Class StringInterpolationInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.StringInterpolationInstr
All Implemented Interfaces:
INode

public final class StringInterpolationInstr extends IRInstr
IR instruction for string interpolation.

Contains structured data for building an interpolated string from literal text and pre-converted String variables. All expressions have been converted to String by Phase 7 before this instruction is created.

Backends can choose optimal concatenation strategy:

  • JVM: invokedynamic StringConcatFactory or StringBuilder
  • LLVM: single allocation with memcpy
  • Method Details

    • interpolate

      public static StringInterpolationInstr interpolate(String result, List<IRInstr> setupInstructions, List<StringInterpolationPart> parts, String scopeId, DebugInfo debugInfo)
      Create a string interpolation instruction.
      Parameters:
      result - Variable to store the resulting String
      setupInstructions - Instructions to convert expressions to String ($ calls)
      parts - The interpolation parts (literals and String variables)
      scopeId - Scope for memory management
      debugInfo - Source location information
      Returns:
      StringInterpolationInstr
    • getSetupInstructions

      public List<IRInstr> getSetupInstructions()
      Get the setup instructions ($ operator calls for non-String expressions).
      Returns:
      List of setup instructions, may be empty
    • getParts

      public List<StringInterpolationPart> getParts()
      Get the interpolation parts.
      Returns:
      Immutable list of parts
    • getScopeId

      public String getScopeId()
      Get the scope ID for memory management.
      Returns:
      The scope identifier
    • hasVariableParts

      public boolean hasVariableParts()
      Check if this interpolation has any variable parts.
      Returns:
      true if at least one part is a variable reference
    • hasSetupInstructions

      public boolean hasSetupInstructions()
      Check if this interpolation has any setup instructions.
      Returns:
      true if there are setup instructions to execute
    • getLiteralPartCount

      public long getLiteralPartCount()
      Get count of literal parts.
      Returns:
      Number of literal parts
    • getVariablePartCount

      public long getVariablePartCount()
      Get count of variable parts.
      Returns:
      Number of variable parts
    • isLiteralOnly

      public boolean isLiteralOnly()
      Check if this is a simple literal-only interpolation. Can be optimized to a single LOAD_LITERAL.
      Returns:
      true if all parts are literals
    • toString

      public String toString()
      Overrides:
      toString in class IRInstr