Class TernaryOperatorAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.TernaryOperatorAsmGenerator
Specialized generator for EK9 ternary operator.
Handles CONTROL_FLOW_CHAIN with chain_type: "TERNARY_OPERATOR".
EK9 Ternary Operator Pattern: condition <- thenValue : elseValue
- If condition is true → returns thenValue
- If condition is false → returns elseValue
IR Structure:
CONTROL_FLOW_CHAIN [chain_type: "TERNARY_OPERATOR"]
condition_chain:
[case 1: case_type: "EXPRESSION"]
condition_evaluation: [LOAD condition, CALL _true()]
condition_result: conditionTemp (EK9 Boolean)
primitive_condition: primitiveBoolean (Java boolean)
body_evaluation: [evaluate thenValue]
body_result: thenTemp
default_body_evaluation: [evaluate elseValue]
default_result: elseTemp
Bytecode Pattern:
// Condition evaluation (produces primitive boolean) ALOAD condition_index INVOKEVIRTUAL _true() ILOAD primitive_index IFEQ else_label // True branch: evaluate thenValue [then_evaluation_instructions] ALOAD then_result_index ASTORE result_index GOTO end_label else_label: // False branch: evaluate elseValue [else_evaluation_instructions] ALOAD else_result_index ASTORE result_index end_label: // result now holds correct value
Stack Frame Invariant: All paths arrive at 'end' label with empty stack. Result is stored in local variable (overall_result).
-
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
ConstructorsConstructorDescriptionTernaryOperatorAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for ternary operator.Methods inherited from class AbstractControlFlowAsmGenerator
branchIfFalse, branchIfTrue, copyResultVariable, createControlFlowLabel, jumpTo, placeLabel, processBodyEvaluation, processConditionCase, processConditionCaseWithoutLabelPlacement, processConditionEvaluation, processInstructionsMethods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
TernaryOperatorAsmGenerator
TernaryOperatorAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for ternary operator.Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty (result in local variable)
- Parameters:
instr- CONTROL_FLOW_CHAIN instruction with TERNARY_OPERATOR type
-