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 emit a single LIST_LITERAL instruction containing:
- Setup instructions: element expression evaluation + RETAIN/SCOPE_REGISTER
- List literal details: collection type FQN, element temps, element count
The backend uses element count for pre-sized allocation (JVM: new ArrayList(N))
and element temps for bulk population via _addAss() calls.
Example:
["one", "two"] generates:
_temp1 = LIST_LITERAL org.ek9.lang::_List_HASH [size=2] [_temp2, _temp3]
Where setup instructions contain:
_temp2 = LOAD_LITERAL one, org.ek9.lang::String RETAIN _temp2 SCOPE_REGISTER _temp2, _scope_1 _temp3 = LOAD_LITERAL two, org.ek9.lang::String RETAIN _temp3 SCOPE_REGISTER _temp3, _scope_1
-
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionListLiteralGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for list literal IR generator. -
Method Summary
Methods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessage, validateNoPreFlowStatement, validateStatementFormOnly
-
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>>
-