Class StringInterpolationAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.StringInterpolationAsmGenerator
- All Implemented Interfaces:
Consumer<StringInterpolationInstr>
final class StringInterpolationAsmGenerator
extends AbstractAsmGenerator
implements Consumer<StringInterpolationInstr>
Generates JVM bytecode for STRING_INTERPOLATION IR instructions.
Uses invokedynamic with StringConcatFactory.makeConcatWithConstants(MethodHandles.Lookup, String, MethodType, String, Object...)
for optimal string concatenation. This approach:
- Creates a single String allocation (no intermediate objects)
- No StringBuilder or temporary String objects
- JVM can inline and optimize the concatenation
- Matches how Java 9+ compiles string concatenation
The recipe string uses as placeholder for dynamic arguments
and literal text is embedded directly in the recipe.
Example:
// EK9: `Hello ${name}, count: ${count}`
// Recipe: "Hello , count: "
// Dynamic args: [name_str, count_str]
-
Field Summary
Fields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple -
Constructor Summary
ConstructorsConstructorDescriptionStringInterpolationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(StringInterpolationInstr instr) Generate JVM bytecode for a string interpolation instruction.Methods 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, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
StringInterpolationAsmGenerator
StringInterpolationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
-
-
Method Details
-
accept
Generate JVM bytecode for a string interpolation instruction.Processing steps:
- Execute setup instructions ($ conversions for non-String expressions)
- Build recipe string from literal parts
- Collect dynamic argument variable names
- Load all dynamic arguments onto stack
- Emit invokedynamic with StringConcatFactory
- Store result
- Specified by:
acceptin interfaceConsumer<StringInterpolationInstr>
-