Java Reference
In-Depth Information
The generation of code for conditional execution follows the code layout shown
in the box above. To accommodate the jumps necessary for the code, two labels
are generated at Marker 45 . Code is generated at Marker 46 to evaluate the
predicate. Based on the evaluation of the predicate at runtime, a branch is
generated at Marker 47 that skips around the true-branch code if the predicate
evaluates to false . Generally, a value of 0 represents false and some non-zero
value (typically 1) represents true. If the predicate evaluates to false, then the
branch is not taken and the code generated at Marker 48 executes, followed
by an unconditional branch to the end of the CondTestingcode.
If control reaches f alseLabel , then the code generated by Marker 49 exe-
cutes. The end of the Ifishcode is then reached.
11.3.10 Loops
/
Visitor code for Marker 13
/
procedure
visit
(WhileTesting n )
doneLabel ← gen
L
abel
()
50
loopLabel ← gen
L
abel
()
call
emit
L
abel
D
ef
( loopLabel )
n . getPredicate() . accept( this )
predicateResult n . getPredicate() . getResultLocal()
call emit
51
B
ranch
I
f
F
alse
( predicateResult , doneLabel )
n . getLoopBody() . accept( this )
call
52
emit
B
ranch
( loopLabel )
call
emit
L
abel
D
ef
( doneLabel )
end
The code generated for a WhileTestingloop is similar to code generated for an
CondTestingnode. Two labels are obtained at Marker 50 .Oneservesasthe
exit for the loop, and the other serves to repeat the loop at its predicate test.
AST
JVM Instructions
WhileIsh
loopLabel:
; Predicate code (Marker 51 )
; Predicate false? → exit the loop
; ifeq doneLabel
; Loop body code(Marker 52 )
goto loopLabel
endLabel:
Done with loop
while
n
predicate
body
 
 
Search WWH ::




Custom Search