Assignment 4
Function calls are all well and good, but we will find that the stack, like the heap, can also run out of space.
Worse, we will find that some of our (well-formed!) Scheme programs exhibit crashes with our compiler that do not occur under a Big Professional Compiler like Guile.
Consider: we have no looping constructs. How does one “loop” over a string by index (for example)? With a recursive function. And what if the number of characters in the string is greater than the number of stack frames available? Hmmm.
This is why the Scheme standards guarantee that certain kinds of calls do not use stack space: tail calls.
Recognizing tail calls
Tail calls
- A
tailcallform andTAILCALLopcode
Optionally, faster tail calls
Build some library functions
mapfoldfoldlvsfoldr
Complex constants
constant-initconstant-reflabelsform must handlebegin-like behavior
Question: why not just bake constant data into the .data section (or
equivalent)?