Project>Square- Where do the number of arguments come from in these methods calls?

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

Project>Square- Where do the number of arguments come from in these methods calls?

kraftwerk1611
Hi,

I have a question about the number of methods arguments pushed on stack.

When I was working with test 'Seven' in Project 11, I used number of expressions compiled by methods for vm output like

do Output.printInt(1 + (2 * 3));

generating

call Output.printInt 1

In Square.jack in Square test, following command inside the constructor

do draw()

generates the following output

call Square.draw 1

Where does this one come from, when there is no expression inside draw() ? Is it due to 'this' ?



Reply | Threaded
Open this post in threaded view
|

Re: Project>Square- Where do the number of arguments come from in these methods calls?

cadet1620
Administrator
kraftwerk1611 wrote
do draw()

generates the following output

call Square.draw 1

Where does this one come from, when there is no expression inside draw() ? Is it due to 'this' ?
You are correct. Methods always get 'this' as argument 0.

The syntax of the function call determines what type of subroutine is being called, and what is passed as 'this':

do fun()
    method call -- only valid from within a method or constructor; passes current 'this' as 'this' argument.
do object.fun()
    method call -- passes object as 'this' argument.
do Class.fun()
    function or constructor call -- there is no 'this' argument.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Project>Square- Where do the number of arguments come from in these methods calls?

kraftwerk1611
thanks