Class NullCoalescingOperatorAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.NullCoalescingOperatorAsmGenerator
Specialized generator for EK9 null coalescing operator (??).
Handles CONTROL_FLOW_CHAIN with chain_type: "NULL_COALESCING_OPERATOR".
EK9 Null Coalescing Operator Pattern: lhs ?? rhs
- If LHS is null → returns RHS
- If LHS is not null → returns LHS (regardless of set/unset state)
Key Difference from Elvis Operator (:?):
- ?? checks ONLY null (IS_NULL instruction)
- :? checks BOTH null AND set (IS_NULL + IS_SET instructions)
IR Structure:
CONTROL_FLOW_CHAIN [chain_type: "NULL_COALESCING_OPERATOR"]
condition_chain:
[case_type: "NULL_CHECK"]
condition_evaluation: [LOAD lhs, IS_NULL lhs]
primitive_condition: temp_is_null
body_evaluation: [LOAD rhs] // Returns RHS if null
body_result: rhs
default_body_evaluation: [LOAD lhs] // Returns LHS if not null
default_result: lhs
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
ConstructorsConstructorDescriptionNullCoalescingOperatorAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for null coalescing operator (??).Methods inherited from class AbstractControlFlowAsmGenerator
branchIfFalse, branchIfTrue, copyResultVariable, createControlFlowLabel, generateCoalescingPattern, 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, isVariableFieldAccess, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
NullCoalescingOperatorAsmGenerator
NullCoalescingOperatorAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for null coalescing operator (??).Uses the common coalescing pattern from AbstractControlFlowAsmGenerator.
Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty (result in local variable)
- Parameters:
instr- CONTROL_FLOW_CHAIN instruction with NULL_COALESCING_OPERATOR type
-