handouts/ho08.tex
changeset 382 38e368dc9b10
parent 381 47eceea734c5
child 383 a6a6bf32fade
equal deleted inserted replaced
381:47eceea734c5 382:38e368dc9b10
   303 If_end:
   303 If_end:
   304   ireturn
   304   ireturn
   305 .end method
   305 .end method
   306 \end{lstlisting}
   306 \end{lstlisting}
   307 
   307 
   308 \noindent The local limit is because add takes two arguments.
   308 \noindent The locals limit is 2 because add takes two arguments.
   309 The stack limit is a simple calculation using the estimate
   309 The stack limit is a simple calculation using the estimate
   310 function. We first generate code for the boolean expression
   310 function. We first generate code for the boolean expression
   311 \pcode{x == 0}, that is loading local variable 0 and the
   311 \pcode{x == 0}, that is loading the local variable 0 and the
   312 number 0 onto the stack (Lines 4 and 5). If the not-equality
   312 number 0 onto the stack (Lines 4 and 5). If the not-equality
   313 test fails we continue with returning $y$, which is the local
   313 test fails, we continue with returning $y$, which is the local
   314 variable 1 (followed by a jump to the return instruction). If
   314 variable 1 (followed by a jump to the return instruction). If
   315 the not-equality test succeeds then we jump to the label 
   315 the not-equality test succeeds, then we jump to the label 
   316 \pcode{If_else} (Line 9). After that label is the code for
   316 \pcode{If_else} (Line 9). After that label is the code for
   317 \pcode{suc(add(x - 1, y))}. We first have to evaluate the
   317 \pcode{suc(add(x - 1, y))}. We first have to evaluate the
   318 argument of the suc-function. But this means we first have to
   318 argument of the suc-function. But this means we first have to
   319 evaluate the two arguments of the add-function. This means
   319 evaluate the two arguments of the add-function. This means
   320 loading $x$ and $1$ onto the stack and subtracting them.
   320 loading $x$ and $1$ onto the stack and subtracting them.