Class ListLiteralGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.ListLiteralGenerator
- All Implemented Interfaces:
Function<ExprProcessingDetails, List<IRInstr>>
public final class ListLiteralGenerator
extends AbstractGenerator
implements Function<ExprProcessingDetails, List<IRInstr>>
Generates IR instructions for list literal expressions.
Handles the syntax: ["element1", "element2", ...]
IR Generation Strategy:
List literals are desugared into:
- List<T> constructor call (default constructor)
- Memory management (RETAIN/SCOPE_REGISTER) for list object
- For each element:
- Evaluate element expression
- Memory management for element
- Call
_addAss(element)mutation operator
Example:
["one", "two"] generates:
_temp1 = CALL List<String>.<init>() RETAIN _temp1 SCOPE_REGISTER _temp1 _temp2 = LOAD_LITERAL "one" RETAIN _temp2 SCOPE_REGISTER _temp2 CALL _temp1._addAss(_temp2) _temp3 = LOAD_LITERAL "two" RETAIN _temp3 SCOPE_REGISTER _temp3 CALL _temp1._addAss(_temp3)
Memory Management:
- List object retained and registered to current scope
- Each element retained and registered before _addAss call
- No LOAD/STORE between elements (direct operation on constructor result)
-
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, stackContext -
Constructor Summary
ConstructorsConstructorDescriptionListLiteralGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for list literal IR generator. -
Method Summary
Methods inherited from class AbstractGenerator
createTempVariable, getRecordedSymbolOrException
-
Constructor Details
-
ListLiteralGenerator
ListLiteralGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for list literal IR generator.- Parameters:
stackContext- IRGenerationContext for scope and symbol accessgenerators- GeneratorSet for accessing other generators (expression processor, etc.)
-
-
Method Details
-
apply
- Specified by:
applyin interfaceFunction<ExprProcessingDetails, List<IRInstr>>
-