Administrator
|
The important point is that the VM translator ensures that label/if/if-goto labels are decorated so that they will be unique across functions.
If you want to try to match the supplied Jack compiler's output you need to generate the labels using serial numbers that restart with every function. If you want to match my compiler's output, you need to be lazy like I was and never reinitialize the serial number 8-)
Nested control structures imply nested calls to compileIf() and compileWhile() so those routines need to generate all the labels that they might need to use before they call anything that might recursively call themselves.
General note on recursive object-oriented programming:
Some things need to be stored in the object and others on the stack—I've written some wonderfully hard to find bugs over the years by mixing them up!
--Mark
|