Class DoWhileLoopAsmGenerator


final class DoWhileLoopAsmGenerator extends AbstractControlFlowAsmGenerator
Specialized generator for EK9 do-while loops. Handles CONTROL_FLOW_CHAIN with chain_type: "DO_WHILE_LOOP".

JVM Bytecode Pattern (different from while loop):

loop_start:
  [body instructions]         ; Execute body FIRST
  [condition evaluation]      ; Then evaluate condition
  iload primitive_condition
  ifne loop_start             ; If TRUE (non-zero), jump BACK
loop_end:                     ; Fall through if false

Key Differences from While Loop:

  • Body executes BEFORE condition (guaranteed at least once)
  • Uses IFNE (jump if NON-ZERO/true) instead of IFEQ
  • No need for forward branch before body
  • Loop always executes at least once

Stack Frame Invariant: Stack is empty before loop, after body, after condition, and after loop exit.

  • Constructor Details

  • Method Details

    • generate

      public void generate(ControlFlowChainInstr instr)
      Generate bytecode for do-while loop.

      Control Flow:

      1. Place loop start label
      2. Execute body (leaves stack empty)
      3. Evaluate condition (leaves stack empty)
      4. Branch BACK to loop start if condition is TRUE
      5. Fall through to loop end if condition is FALSE

      Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty

      Parameters:
      instr - CONTROL_FLOW_CHAIN instruction with DO_WHILE_LOOP type