Support code for students (Python version).
The runtime.c file needs to be compiled by doing the following
gcc -c -g -std=c99 runtime.c
This will produce a file named runtime.o. The -g flag is to tell the
compiler to produce debug information that you may need to use
the gdb (or lldb) debugger.
On a Mac with an M1 (ARM) processor, use the -arch x86_64 flag to
compile the runtime:
gcc -c -g -std=c99 -arch x86_64 runtime.c
The x86 interpreter interp_x86, defined in the interp_x86
directory, runs the x86 programs produced by every chapter's compiler, both
the final x86 and the x86-like languages produced by the select instructions,
assign homes and patch instructions passes. Add it to your interp_dict for
those passes:
from eval_x86 import interp_x86
interp_dict = {
...
'select_instructions': interp_x86,
'assign_homes': interp_x86,
'patch_instructions': interp_x86,
}
Starting from the chapter on tuples, interp_x86 needs to know how many
variables each program or function spills to the root stack:
- Up to Ltup, set the field
num_root_spillsof theX86Programto the number of tuple variables that have been spilled into the root stack. - Beginning with Lfun, set the field
num_root_spillsof everyFunctionDefin the same way.
The interpreter's collect only enlarges the heap and never copies, so it
won't reveal mistakes in how your compiler uses the root stack. The tests
that run your compiled program with runtime.c will.