Typo in The book?

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

Typo in The book?

virote328
Hello, I don't know if this has been found yet or not.

In chapter 11 in figure 11.6 It shows a vm command version of a jack line of code

let balance = (balance + sum) - commission(sum * 5);

the problem is with the commission method.  The vm commands shown in the book differs from the vm code generated by the jackCompiler.

snippit from book
push argument 0// implicit parameter
push argument 1 //argument sum
push constant 5 //constant
call Math.multiply 2 //
call BankAccount.commission 2
end snippet

however, in the vm code generated by the given jackCompler, the implicit parameter is "push pointer 0"

Are these commands EQUIVALENT within the context?  I think its equivalent, but I want to double check with you guys.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Typo in The book?

cadet1620
Administrator
It's good that you noticed this and that you correctly surmised that the two pushes are equivalent.

Argument 0 is the implicit this argument to method transfer. The first thing all methods do is "push argument 0; pop pointer 0" so argument 0 and pointer 0 have the same value during the method.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Typo in The book?

virote328
thank you
Loading...