Class VariableOnlyDeclInstrGenerator

All Implemented Interfaces:
Function<EK9Parser.VariableOnlyDeclarationContext, List<IRInstr>>

public final class VariableOnlyDeclInstrGenerator extends AbstractVariableDeclGenerator implements Function<EK9Parser.VariableOnlyDeclarationContext, List<IRInstr>>
Creates IR instructions for variable only declarations. Uses REFERENCE instructions for all variables - backend handles storage allocation. Also handles injection-marked variables (the ! suffix) by generating LOAD_STATIC_FIELD from the global _Application static struct (root-level singleton).

STACK-BASED: Now uses IRGenerationContext for scope management instead of parameter threading.

  • Constructor Details

    • VariableOnlyDeclInstrGenerator

      public VariableOnlyDeclInstrGenerator(IRGenerationContext stackContext)
  • Method Details

    • apply

      Generate IR instructions for variable only declaration. Example: someVar as String? — Generates: REFERENCE only (no assignment) Example: logger as AbstractLogger! — Generates: REFERENCE + LOAD_STATIC_FIELD from _Application STACK-BASED: Gets scope ID from stack context instead of parameter threading.
      Specified by:
      apply in interface Function<EK9Parser.VariableOnlyDeclarationContext, List<IRInstr>>
    • parts

      The declaration as its two halves (DeclarationParts): the variable's slot, then the coverage probe and an injection's load.
    • localDeclaration

      public List<IRInstr> localDeclaration(EK9Parser.VariableOnlyDeclarationContext ctx)
      A LOCAL declared without a value (x as T? as a block statement): the declaration, then its owner - the declaring scope owns the slot's CURRENT value, so whatever a later := / :=? leaves in it is released when that scope exits, normally and on unwind (A10, EK9_IR_OWNERSHIP_MODEL.md §6 and §12). Each reassignment releases the value it replaces; a slot never assigned is still null, which the release skips. The owner is part of the declaration (SLOT_DECLARE x, T, s).

      Only a block statement is a local: a parameter is borrowed, the returning variable belongs to the caller and a property to its object, so those declarations go through apply(EK9Parser.VariableOnlyDeclarationContext) alone. An injected local (!) already has its owner from generateInjectionLoad(ISymbol, List).