¶Bethel stacks
2024-02-09 (last updated 2024-04-03)
I recently decided to go back to CPS for Swanson. At the same time, I decided to go with three stacks. But I really liked how the four-stack setup used a nice power of 2 for the number of stacks.
Continuation-passing S₀: The return
Porque no los dos?
So, S₀ will go back to being CPS, where an invoke instruction is terminal. One of the stacks is primarily intended to be used for continuation quotations, avoiding the juggling problem of a stack-based CPS language. One of the stacks is typically used for locals / enclosed values; the value enclosed in a quotation (if any) will be pushed onto this stack just before control transfers to the chosen quotation branch. But to go from three stacks to four, we'll have two “working” stacks. Each object/invocation will have a “preferred” stack where it will typically be invoked from, and where it will place itself when passing itself back to its continuation. It will expect any “inputs” (and pass any “outputs” to its continuation) on the other working stack.
- Stack 0: Working stack
- Stack 1: Working stack
- Stack 2: Locals stack
- Stack 3: Continuation stack
Also, I'm definitely spinning my wheels here, making never-ending changes to the stack layout and set of primitive instructions. Maybe if I give this most recent design a snappier name it will stick. So let's call these “Bethel stacks”, since I'm typing this at Sunday River.