Class ThrowInstr

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

public final class ThrowInstr extends IRInstr
Specialized IR instruction for throwing exceptions (THROW).

Handles both forms of throw statement: - throw Exception("message") - constructor call expression - throw exceptionVariable - variable reference

Key Design: - Terminating instruction (like RETURN) - no code follows in same basic block - Exception object MUST be on stack/in variable before throw - Interacts with CONTROL_FLOW_CHAIN exception handlers for try/catch - Backend generates ATHROW (JVM) or resume (LLVM) instruction - Stack unwinding handled by backend exception mechanism

ARC Semantics: - Exception object should be RETAINED and SCOPE_REGISTERED before throw - THROW transfers ownership to exception mechanism (refcount maintained during unwinding) - CATCH receives ownership without additional RETAIN (clean ownership transfer) - SCOPE_EXIT after THROW is unreachable (backend handles cleanup during unwinding)

  • Method Details

    • throwException

      public static ThrowInstr throwException(String exceptionVariable, DebugInfo debugInfo)
      Create throw instruction with exception object variable and debug info. The exception variable must contain a valid Exception or subtype object.
      Parameters:
      exceptionVariable - The variable containing the exception object to throw
      debugInfo - Debug information for source location (used in stack traces)
      Returns:
      ThrowInstr instance
    • getExceptionVariable

      public String getExceptionVariable()
      Get the exception object variable to throw.
      Returns:
      Exception variable name, or null if not set
    • addOperand

      public ThrowInstr addOperand(String operand)
      Description copied from class: IRInstr
      Add operand to this instruction.
      Overrides:
      addOperand in class IRInstr
    • addOperands

      public ThrowInstr addOperands(String... operands)
      Description copied from class: IRInstr
      Add multiple operands to this instruction.
      Overrides:
      addOperands in class IRInstr