-
Book Overview & Buying
-
Table Of Contents
Building Programming Language Interpreters
By :
The stack machine that we had implemented so far was sufficient for trivial executions, but it could not handle more complex control flow operations.
To implement support for conditionals, I introduced the ability for the stack machine to reference the executable code as a value and for the interpreter to start executing that value. This is important because the branches in the operation tree should not be traversed until the operation selects which path to take.
The interpreter, for its part, needs to be able to recognize when it needs to switch from executing one particular stack to start executing a different one. The direction used here was to represent these different stacks as different continuations, with the state of the continuation allowing the interpreter to manage that transparently.
Beyond conditionals, it’s also necessary to support a sequence of operations as well as the list of arguments to a function. That requires a new type of operation...
Change the font size
Change margin width
Change background colour