Class AssignIfUnsetAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.AssignIfUnsetAsmGenerator
Specialized generator for EK9 assign-if-unset (:=?).
Handles CONTROL_FLOW_CHAIN with chain_type: "ASSIGN_IF_UNSET".
EK9 Assign-If-Unset Pattern: variable :=? value
- Assigns value to variable only if variable is null or not set
- Prevents overwriting already-initialized variables
- Useful for default value initialization
Generates bytecode that checks if the target variable is unset (null or _isSet() false),
and only performs the assignment if so. Follows the condition/branch/body pattern
from AbstractControlFlowAsmGenerator.
-
Field Summary
Fields inherited from class AbstractControlFlowAsmGenerator
contextFields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionAssignIfUnsetAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for assign-if-unset.Methods inherited from class AbstractControlFlowAsmGenerator
branchIfFalse, branchIfTrue, copyResultVariable, createControlFlowLabel, generateCoalescingPattern, jumpTo, placeLabel, processBodyEvaluation, processConditionCase, processConditionCaseWithoutLabelPlacement, processConditionEvaluation, processInstructions, processSequentialCaseChainMethods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStoreVariableAsInt, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, isVariableFieldAccess, setCurrentMethodVisitor, setSharedMethodContext, toJvmFieldName, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
AssignIfUnsetAsmGenerator
AssignIfUnsetAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for assign-if-unset.EK9 Pattern:
variable :=? valueSemantic Flow:
- Check if target variable is unset (null or _isSet() returns false)
- If UNSET: evaluate RHS expression and assign to target
- If SET: skip assignment (fall through to end)
Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty (assignment stored in variable)
- Parameters:
instr- CONTROL_FLOW_CHAIN instruction with ASSIGN_IF_UNSET type
-