Class DoWhileLoopAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.DoWhileLoopAsmGenerator
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAsmGenerator
AbstractAsmGenerator.LocalVariableInfo, AbstractAsmGenerator.MethodContext, AbstractAsmGenerator.ScopeInfo, AbstractAsmGenerator.TempVariableSource -
Field Summary
Fields inherited from class AbstractControlFlowAsmGenerator
contextFields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionDoWhileLoopAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for do-while loop.Methods inherited from class AbstractControlFlowAsmGenerator
branchIfFalse, branchIfTrue, copyResultVariable, createControlFlowLabel, jumpTo, placeLabel, processBodyEvaluation, processConditionCase, processConditionCaseWithoutLabelPlacement, processConditionEvaluation, processInstructionsMethods inherited from class AbstractAsmGenerator
convertBooleanToInt, convertToJvmDescriptor, convertToJvmName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStringLiteral, getCurrentMethodVisitor, getMethodContext, getOrCreateLabel, getVariableIndex, isVariableAllocated, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
DoWhileLoopAsmGenerator
DoWhileLoopAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for do-while loop.Control Flow:
- Place loop start label
- Execute body (leaves stack empty)
- Evaluate condition (leaves stack empty)
- Branch BACK to loop start if condition is TRUE
- 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
-