v4 Bytecode: lowering control flow

Lesson, slides, and applied problem sets.

View Slides

Lesson

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

  • break emits a jump patched to loop end.
  • continue emits 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 b and check
  • produce true or false

This keeps runtime semantics correct without new opcodes.


Module Items