markcornwell / pilar

incremental development of scheme compiler
1 stars 0 forks source link

Modify runtime.c to allocate heap #6

Closed markcornwell closed 9 years ago

markcornwell commented 9 years ago

Task: Modify runtime.c according to the tutorial on Heap Allocation and verify that system compiler still passes tests. Save the registers on entry to Scheme, allocate the heap and stack, then call the scheme entry point. When scheme returns, restore the registers and print the value returned.

markcornwell commented 9 years ago

Heap allocation is a little different that stack allocation. The stack grows from Hi addresses to Low addresses. The heap grows in the opposite direction. Thus when initializing registers the stack register is initialized to point to the high end of block allocated for the stack, but the heap register is initialize to point to the low end of the block allocated for the heap. They are not the same!

markcornwell commented 9 years ago

To run the tests, you also have to modify the print_ptr() routine to account for lists. This can a little tricky. Key observation is that you convert a ptr value tagged as a pair to an actual pointer by adding 1. Handy to add a typedef to access car and cdr fields simply.

typedef struct { ptr car; ptr cdr } *pair;