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]
  • Constructor Details

    • StringInterpolationAsmGenerator

      StringInterpolationAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
  • Method Details

    • accept

      public void accept(StringInterpolationInstr instr)
      Generate JVM bytecode for a string interpolation instruction.

      Processing steps:

      1. Execute setup instructions ($ conversions for non-String expressions)
      2. Build recipe string from literal parts
      3. Collect dynamic argument variable names
      4. Load all dynamic arguments onto stack
      5. Emit invokedynamic with StringConcatFactory
      6. Store result
      Specified by:
      accept in interface Consumer<StringInterpolationInstr>