Class TernaryOperatorAsmGenerator


final class TernaryOperatorAsmGenerator extends AbstractControlFlowAsmGenerator
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).

  • Constructor Details

  • Method Details

    • generate

      public void generate(ControlFlowChainInstr instr)
      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