Class ThrowStatementGenerator

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.ThrowStatementGenerator
All Implemented Interfaces:
Function<EK9Parser.ThrowStatementContext, List<IRInstr>>

public final class ThrowStatementGenerator extends AbstractGenerator implements Function<EK9Parser.ThrowStatementContext, List<IRInstr>>
Generates IR for throw statements.

Grammar support: throwStatement: THROW (call | identifierReference)

Two forms: 1. throw Exception("message") - constructor call expression (TODO: not yet implemented) 2. throw exceptionVariable - variable reference (implemented)

Key behaviors: - For identifier: Applies RETAIN (ownership transfer) then THROW - THROW is a terminating instruction (transfers control to exception mechanism) - SCOPE_EXIT after throw is unreachable in normal flow (backend executes during unwinding)

ARC Ownership Transfer Semantics: Following the Producer/Consumer pattern from EK9_ARC_OWNERSHIP_TRANSFER_PATTERN.md:

Declaration (normal variable management):
  RETAIN + SCOPE_REGISTER    // Variable managed in declaration scope

Throw (Producer - transfers ownership):
  RETAIN (no SCOPE_REGISTER) // Increment for transfer
  THROW                      // Transfer control

Stack Unwinding (backend responsibility):
  SCOPE_EXIT                 // Backend releases declaration scope reference

Catch (Consumer - receives ownership):
  REFERENCE (no RETAIN)      // Receive exception
  SCOPE_REGISTER             // Take ownership for catch scope

Result: Exception has refcount = 1 in catch handler, gets released on catch scope exit.