Issue with Output.printInt

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with Output.printInt

HighSchoolerWhoAsksHowTooMuch
Hi!

I am working on implementing the Jack Compiler. For the first script, Main.jack (which outputs 7), the VME is saying that Output.printInt is causing a null pointer exception.
Here are photos taken before and after the function is run.





I am not certain why I am getting this error.

Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

HighSchoolerWhoAsksHowTooMuch



Sorry, the images in the first post are the same. This photo is of the state of the program before the error.
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

ivant
I looked at the source code of the simulator and this part is a bit messy.

You can send me the directory with the VM files that you're running and I'll try to debug it.
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

HighSchoolerWhoAsksHowTooMuch
Do you mean Output.vm or the vm file I generated?

If you mean the ladder:

push constant 1
push constant 2
push constant 3
call Math.multiply 2
add
call Output.printInt 1
pop temp 0
return

Thank you so much!!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

ivant
By specification the VMEmulator stats Sys.init, which initializes the system and calls the Main.main(), which is the entry point of the user program. I don't remember if there was some .tst file, which could skip the Sys.init() and directy run your program as it is now. If so, that should be described in the task in the book.

In any case, I was able to run your program by adding one line at the start:

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
return 
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

HighSchoolerWhoAsksHowTooMuch
I see. Thank you so much for your time!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Output.printInt

WBahn
Administrator
The VM program specification (Section 7.2.1 of 1st Ed) is pretty explicit:

A VM program is a collection of on or more files with a .vm extension, each consisting of one or more functions.
Since your program had bare code in it, it violated the spec, which invoked undefined behavior. In this case, that manifested itself by the VM emulator through a Null-pointer exception.

A subtle telltale that something along this lines is afoot is that your code has a bare return statement in it. So what is supposed to happen when that return statement is executed? Return from what? Return to where?