Class SwitchAsmGenerator
EK9 Switch Semantics: - Sequential condition evaluation (if/else-if pattern) - Supports rich operators: equality, contains, matches, comparison - Works with Integer, String, Float, Character types - Multiple case literals per case - Optional default clause
Bytecode Pattern (Sequential Evaluation):
; Evaluation variable setup (switch expression) [evaluation variable instructions] ; Case 1 [condition evaluation] iload primitive_condition ifeq case_2 ; Branch if false [case 1 body] goto end ; Exit switch case_2: [condition evaluation] iload primitive_condition ifeq default_label ; Branch if false [case 2 body] goto end default_label: [default body] ; Fall through to end end: ; All paths converge here
Stack Frame Invariant: All paths arrive at 'end' label with empty stack. Statement form has no result variable (unlike expression form which would).
Design Note: EK9 switch uses sequential evaluation rather than JVM tableswitch/lookupswitch because it supports rich operator semantics (contains, matches) and multiple types (String, Float) that don't map to JVM switch instructions. This provides maximum flexibility while maintaining correct semantics.
-
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
ConstructorsConstructorDescriptionSwitchAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for switch statement.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
-
SwitchAsmGenerator
SwitchAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for switch statement.Control Flow:
- Process evaluation variable setup (switch expression)
- For each case: evaluate condition, branch if false, execute body, jump to end
- Process default case (if present)
- Place end label where all paths converge
Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty
- Parameters:
instr- CONTROL_FLOW_CHAIN instruction with SWITCH type
-