cyboman wrote
I understand why we need to push this and that on the stack when one function calls the other but I can't figure out where thier values are set? A small picture on the right side of page 160 says that this, that, pointer and temp are undefined upon entry, so what sets those values and how do we make sure that when we go from one function to another we don't overwrite the heaps of each function?
The VM translator does not need to do anything special to initialize
this or
that. The Jack compiler generates code that handles them.
When a function is called that manipulates an object, the compiler generates vm code that passes a pointer to the object as an extra parameter. The generated code for the called function uses this extra parameter to set THIS. When the compiler needs to dereference a pointer to something other than the current object, it uses
that.
--Mark