VM implementation on the Hack platform /
Parser Module / CodeWriter Module
(7.2.6, p 135) When a VM function starts running, it assumes that (i) the stack
is empty, (ii) the argument values on which it is supposed to operate are
located in the argument segment, and (iii) the local variables that it is
supposed to use are initialized to 0 and located in the local segment.
Recall that VM commands cannot use symbolic argument and variable names -they are limited to making <segment index> references only. For the program described in Fig. 7.9 this translation is straight forward, just map x, y, sum and j on argument 0, argument 1, local 0, and local 1 respectively.
To sum up, when a VM function starts running, it assumes that it is surrounded by a private world, all its own, consisting of initialized argument and local segments and an empty stack, waiting to be manipulated by its commands. The agent responsible for staging this virtual worldview for every VM function just before it starts running is the VM implementation -see Chapter 8.
Parser Module top
CodeWriter Module top