|
|
Hi,
TLDR: How should the VM translator bootstrap SimpleFunction correctly in Project 8? It seems that any option will fail.
(in general - how should Project 8 handle bootstrapping. One example requires it and two examples require its absence)
More detailed:
I’d like to clarify some confusion I have regarding bootstrapping in Project 8 of the Nand2Tetris course.
As I understand it, four of the six examples in Project 8 appear to work without explicit bootstrap code:
BasicLoop and FibonacciSeries don’t define any functions, so no bootstrap code is needed.
NestedCall and StaticsTest define Sys.init as their first function, which is expected to be at the top of the translated .asm file, and Sys.init ends in an infinite loop. Thus, these also run correctly without bootstrap code.
However, two cases seem problematic:
FibonacciElement includes both Main.vm and Sys.vm, and the spec doesn’t define which file should be loaded first. Without bootstrap code that explicitly calls Sys.init, the behavior could be incorrect if Sys.vm is not translated first.
SimpleFunction is even more confusing. It contains only one function (e.g. SimpleFunction.test), and this function ends with a return. There’s no Sys.init, and no other function calls SimpleFunction.test. As a result:
Without bootstrap code, the .asm will begin with SimpleFunction.test, which is never meant to be executed directly. The return will be invoked without a proper call frame, corrupting the stack.
With bootstrap code, the translator will emit a call to Sys.init, which doesn’t exist in this example, leading to a missing label error.
So, my questions are:
- How should the VM translator handle SimpleFunction correctly in Project 8?
- How should the VM translator handle bootstrapping in Project 8?
Any clarification would be much appreciated.
Thanks!
|
|
The following is copied from the PDF file, that is linked from the website. (I hope it's OK to put this here as it's freely available from that page.)
Bootstrap code: In order for any translated VM program to start running, it must include startup
code that invokes the program on the host platform. In addition, in order for any VM code to
operate properly, the VM implementation must set the base address of the stack to some selected
RAM location (on our platform, 256).
Each one of the first three test programs in this project – BasicLoop, FibonaciiSeries,
SimpleFunction – include no function calls. Also, each one of these three programs is stored in a
single .vm file. When running these three tests, we assume that the VM Translator generates no
bootstrap code. We also assume that in these three programs, the VM translator handles no
function calls. Therefore, the stack and the virtual segments are not initialized in the RAM. To
compensate, the testing of these three programs feature test scripts that affect the necessary
initializations "manually" (as you can see by inspecting their .tst files). The last two test programs –
FibonaciiElement and StaticTest – assume that the VM Translator generates startup code and
handles all the function-call-and-return VM commands.
So, in this project, there is a simple rule: If the VM Translator is called to translate one file only, it
should inform the CodeWriter that it should not write the bootstrap code (that is, ignore the
constructor's API guideline beginning with "Writes the assembly instructions that affect the
bootstrap code..."). If the VM Translator is called to translate more than one .vm file, it should
inform the CodeWriter that it must generate bootstrap code. This requirement (write / don’t write
the bootstrap code) can be handled by the CodeWriter constructor.
|
|