Class LogicalOperationAsmGenerator


final class LogicalOperationAsmGenerator extends AbstractControlFlowAsmGenerator
Specialized generator for EK9 logical operations (AND, OR) with short-circuit evaluation. Handles LOGICAL_AND_BLOCK and LOGICAL_OR_BLOCK IR instructions.

EK9 Logical AND Pattern: left and right

  • If left is false → short-circuit: return left (false) without evaluating right
  • If left is true → full evaluation: evaluate right and return left._and(right)

EK9 Logical OR Pattern: left or right

  • If left is true → short-circuit: return left (true) without evaluating right
  • If left is false → full evaluation: evaluate right and return left._or(right)

Stack Frame Invariant: All paths arrive at end label with empty stack. Result is stored in local variable (instruction result variable).

IR Structure:

_tempN = LOGICAL_AND_BLOCK / LOGICAL_OR_BLOCK
  left_evaluation → produces left_operand (Boolean) and left_condition (primitive int from _true())
  right_evaluation → produces right_operand (Boolean)
  result_computation → produces logical_result (Boolean from _and() or _or())

Bytecode generator populates instruction result (_tempN) with either: - left_operand (short-circuit case) - logical_result (full evaluation case)

  • Constructor Details

    • LogicalOperationAsmGenerator

      LogicalOperationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
  • Method Details

    • generate

      public void generate(LogicalOperationInstr instr)
      Generate bytecode for logical operation (AND or OR).

      Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty (result in local variable)

      Parameters:
      instr - LOGICAL_AND_BLOCK or LOGICAL_OR_BLOCK instruction