Administrator
|
Remember that the values of LCL, ARG, THIS, and THAT that are stored in the stack frame are used to restore those pointers when the function called returns. However, the Sys.init() function should never return. Once Main.main() returns control back to Sys.init(), it should call Sys.halt() -- or just go into an infinite loop directly. Therefore it doesn't matter what values exist in its stack frame because they will never get used.
I'm not sure what you mean by what your VM translator program should do with a 1-file program. Unless your file is names Sys.vm, there will not be a Sys.init() to call!
The project allows you to build your translator incrementally so that you can test it before you implement the bootstrap code. This is possible because the test scripts were written specifically under the assumption that your translator isn't yet doing the initialization, so the necessary actions are taken care of by the script itself.
The only time that being the first function matters is when there is no bootstrap code. At that point, the first thing in the .asm file is the definition for the first function. But the hack doesn't know a function from anything else, it just starts executing the code it sees. This is really akin to invoking undefined behavior, but we know it's going to do it, so we leverage that knowledge to make our implementation and testing strategy easier.
|