Starting with a representation of a item of computation as an object which includes a method says how to perform the next step of its computation.
// a statement, expression etc. class ExecutableThing { executeStep(C:Context ); } Where context here is the execution environment including all the variables in scope.
Now consider a block which is an ordered collection of things to execute following the composite pattern, pseudo code below:
// a statement, expression etc. class ExecutableThing { X executeStep(C:Context ); } class Block implements ExecutableThing { vector<ExecutableThing> statements; X executeStep(C:Context); }; Where X represents an output that indicates what to execute next.
Is that definition sufficient to make it correct to call X a continuation?
There are different ways to think of this. Taking a very low-level view the vector of statements could be like machine code instructions. The block could be a linear representation of the entire program. X could be a token meaning increment the program counter. It could be the program counter itself (for implementing a jump instruction)
For a low-level model where X literally is the program counter would it still be correct to call that program counter a continuation?
Taking a higher level view where X exists in code (rather than being something happening inside a CPU) its a pointer to the next thing to step into. For the 'block' that pointer is (or includes) an iterator into the vector of statements. But is still essentially acting as a program counter.
In my mind a continuation normally includes a reference to the execution context. For example, at the very least, a pointer to an activation record in a stack. So calling X a continuation feels wrong.
Depending on your implementation the 'program counter' could literally be a variable in the context. Such that X means:
context.PC += 1 // for a normal 'statement' context.PC = address // for a jump statement. Does that make the context its own continuation?
Are there rigorous definitions of the following terms that distinguish them from and relate them to each other?
- Program Counter
- Continuation
- Context
- Environment
- Scope
- Activation Record
I think its fair to start by saying that a program counter and an activation record are low level implementation details of one or more of the higher level concepts.
I've added environment and scope there as alternative words for context, though I personally think of scope as "set set of variables visible from a given execution context".
Here's what I have so far please fill in holes as appropriate
Program Counter
- a low-level variable points to the next instruction to be executed.
- typically a control flow register in a CPU
Continuation
- an object which can be passed to something to indicate where control flow should proceed once its execution has completed.
Context
- the environment in which something executes
- includes variables in scope
- may also includes some structures relating to control flow (for example pointers to parent contexts)
Environment
- an alternative word for context
Scope
- the set of variables visible from a given execution context This is more a logical concept than something you implement. For example in some implementations the variables in scope might be those from the
current context and any of its parents
- the set of variables visible from a given execution context This is more a logical concept than something you implement. For example in some implementations the variables in scope might be those from the
Activation Record
- The implementation of a context as a stack frame
- composing activation records produces a call stack