Reference to the object calling (this 0 or pointer 0)?

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

Reference to the object calling (this 0 or pointer 0)?

pier
Hi,
I am struck compileSubroutineCall since a while for the following problem:
Calling a method means pushing as a first argument a reference to the object on which we will operate.
What I don't understand is that the JackCompiler sometimes pushes this 0 and sometimes pointer 0.
I can't figure out why  and I am getting crazy!

Can you explain me this? Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Reference to the object calling (this 0 or pointer 0)?

WBahn
Administrator
push pointer 0

This takes the value of THIS (which is stored at pointer[0]) and places it on the stack. So this is placing the address of the object currently pointed to by THIS onto the stack.

push this 0

This takes the value of the first field variable in the object currently pointed to by THIS (which is stored at THIS[0]) and places it on the stack.

To do any better than that, we need more information about exactly where in the JackCompiler output you are referring to.