Class InterpolatedStringGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.InterpolatedStringGenerator
- All Implemented Interfaces:
Function<ExprProcessingDetails, List<IRInstr>>
public final class InterpolatedStringGenerator
extends AbstractGenerator
implements Function<ExprProcessingDetails, List<IRInstr>>
Generates IR instructions for interpolated string expressions.
Handles the syntax: "Hello ${name}, you are ${age} years old"
IR Generation Strategy:
String interpolation generates a high-level STRING_INTERPOLATION instruction
that provides structured data to backends for optimal concatenation:
- Evaluate each expression part and convert to String (if not already)
- Collect all parts (literals and converted variables)
- Create STRING_INTERPOLATION instruction with parts list
Backend Optimization:
The bespoke instruction allows backends to choose optimal strategies:
- JVM: invokedynamic StringConcatFactory.makeConcatWithConstants()
- LLVM: Single allocation with pre-calculated length and memcpy
Pre-conversion:
All expressions are converted to String BEFORE the interpolation instruction,
keeping backends purely mechanical and enabling Phase 12 optimization
(reusing previously converted Strings if source hasn't been mutated).
-
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionInterpolatedStringGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for interpolated string IR generator. -
Method Summary
Methods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessage, validateNoPreFlowStatement, validateStatementFormOnly
-
Constructor Details
-
InterpolatedStringGenerator
InterpolatedStringGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for interpolated string 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>>
-