SECD Machine
An implementation as seen in Ualberta's CMPUT 325
What is an SECD Machine?
An SECD is a virtual machine designed primarily for running compiled code from functional languages. It consists of four stacks: the
S
tack, holding the 'values' of the executed code,
E
nvironment, containing values of the current scope,
C
ontrol, containing instructions to the machine, and
D
ump stack, used for temporary storage.
The compiled code or instruction set, on the other hand, is relatively simple. For brevity, I won't state them here, nor expand on the SECD definition, but feel free to check the references below:
How does this work?
This implementation has two interactive parts, the "code editor", for a lisp-like language, and the "machine", which executes the compiled code.
To glue those two parts together, I split my program into three sections:
parsing
my code into an AST,
compiling
the AST into the SECD instruction set, then
running
it on the VM.
basics
Arithmetic
Comparison
If Statement
Let Statements
Simulating Let*
lists
complex
Parse + Compile
Source code is on
GitHub