Class GuardedAssignmentAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.GuardedAssignmentAsmGenerator
Specialized generator for EK9 guarded assignment (:=?).
Handles CONTROL_FLOW_CHAIN with chain_type: "GUARDED_ASSIGNMENT".
EK9 Guarded Assignment 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
ConstructorsConstructorDescriptionGuardedAssignmentAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for guarded assignment.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
-
GuardedAssignmentAsmGenerator
GuardedAssignmentAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for guarded assignment.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 GUARDED_ASSIGNMENT type
-