Re: how to print vm commands in correct order
Posted by kraftwerk1611 on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/how-to-print-vm-commands-in-correct-order-tp4030962p4030964.html
Thank you.
The problem was solved changing locations of writeVM() functions. The method to write 'function x nLocals' was a tricky one. And (1+(2*3) was compiled correctly using code of Project 10 without any extra look ahead.
It turns out that I have to rely on Python global variables to keep track of values of different variables across function calls. Otherwise I will have to change method signatures of compileXXX() functions, which does not look right when producing only xml code, which does not need information about locals and arguments.
In my CompilationEngine the same functions produce both xml and vm outputs.
Anyway for now I am happy to see the compiler generate correct output.
function Main.main 0
push constant 1
push constant 2
push constant 3
call Math.multiply 2
add
call Output.printInt 1
pop temp 0
push constant 0
return