Open happytomatoe opened 1 month ago
Whole log nand2tetris.github.io-1726296150652.log
@happytomatoe thank you for opening this issue. It will probably be easier to troubleshoot these if you're running in development mode locally. You can do this by installing Node.JS, cloning the repo, running npm install
, and then npm start
to have a local copy running. This will use source maps for the javascript, which include the original line numbers, and we can get a better look at the problem.
@DavidSouther Thanks for the suggestion. Only today I've realised how to debug web IDE using VS code. BTW I am no longer receiving this error. I don't know how it was fixed. Any comment on what this error means or situations that can lead to that?
opPtr
is the Program Counter as far as the VM Emulator is concerned. However, it's not a global program counter, rather, a PC per function. So this error means the VM emulator has gone "off the end" of the function. opPtr
gets incremented in a couple places, but more importantly, during return
and goto
it gets set to a new value. Usually I'd expected this error to have an off-by-one difference between the two values - 40 > 39
, indicating that the 39th function instruction wasn't a return
statement.
Looking at the other two cases, the value in return
is itself the return value from memory.popStack
, which does a very literal memory lookup for the return value. If a function were to overwrite the stack, that would certainly cause an issue. This is a bit harder than traditional stack overruns, as Hack's stack grows up, not down, but the os Memory module certainly gives full access to the entirety of the Hack's address space.
The other place, in goto
, sets the opPtr based on the map in the current function's (Jack) labels. So these are effectively within-function offsets, rather than program global offsets. If that table were computed incorrectly, a jump would go to the wrong place.
Tool
VM Emulator
Interface
None
Contact Details
No response
What happened?
Sometimes when I run my jack program I get
What does this error mean?
Additional Comments
No response
Do you want to try to fix this bug?
Code of Conduct