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
Current Status: NOT YET IMPLEMENTED (throws CompilerException).
Implementation Plan (after IR generator is finalized):
- Evaluate condition (variable? returns false if null/unset)
- If condition false: execute assignment
- If condition true: skip assignment
- Follow pattern similar to QuestionOperatorAsmGenerator
Blocked By: IR generation for GUARDED_ASSIGNMENT must be finalized and tested first. The IR generator (ControlFlowChainGenerator.generateGuardedAssignment) exists but bytecode generation is deferred pending complete testing of question operator foundation.
-
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
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, 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, setCurrentMethodVisitor, setSharedMethodContext, 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
-