Class LogicalOperationAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.LogicalOperationAsmGenerator
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)
-
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
ConstructorsConstructorDescriptionLogicalOperationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(LogicalOperationInstr instr) Generate bytecode for logical operation (AND or OR).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
-
LogicalOperationAsmGenerator
LogicalOperationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
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
-