v4 Bytecode: lowering control flow
Lesson, slides, and applied problem sets.
View SlidesLesson
v4 Bytecode: lowering control flow
for loops
Lower:
for (init; cond; post) { body }
into:
ENTER_SCOPE
init
loopStart:
cond
JUMP_IF_FALSE end
body
post
JUMP loopStart
end:
EXIT_SCOPE
break / continue
breakemits a jump patched to loop end.continueemits a jump patched to loop continue target.
Use a loop stack with patch lists.
&& / ||
Emit short-circuit jumps that produce boolean results. Example a && b:
- evaluate
a - if false: jump to
falseLabel - otherwise evaluate
band check - produce
trueorfalse
This keeps runtime semantics correct without new opcodes.