💾 Archived View for dcreager.net › swanson › continuation-passing-again.gmi captured on 2024-02-05 at 09:31:21. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2024-03-21)

-=-=-=-=-=-=-

Continuation-passing S₀: The return

2024-01-24

Lately I've been noodling on a four-stack variant of S₀. Unrelated to its four-stackness, it is also no longer a CPS language — when you invoke a quotation, control returns back to the next instruction once the quotation's body is complete.

Four stacks

I now think I want to go back to CPS. One of the reasons for abandoning it was that it made it harder to juggle the inputs, continuation, and receiver of each invocation. But we can handle that with multiple stacks.

So my current thinking is three stacks: a working stack, a continuation stack, and a locals stack. All quotations would close over a stack of values. Invoking a quotation would _replace_ the locals stack with those values before executing the chosen branch. (That means that the locals stack must be empty at the start of an invocation, so that we don't leak values.) The continuation stack exists mostly to solve the juggling problem. The receiver and inputs of an invocation will be on the working stack.