Class PanicThrowInstrs
org.ek9.lang::Panic"
IR sequence - EK9's one representation of an uncatchable fatal invariant breach.
A Panic is a SIBLING of Exception (not a subtype), so it cannot be caught by user
try/catch; it propagates to the generated program _main, which reports it
and exits with the Panic's exit code. Every fatal-invariant site lowers to the identical sequence:
msg = LOAD_LITERAL <message>, org.ek9.lang::String ; RETAIN ; SCOPE_REGISTER code = LOAD_LITERAL <exitCode>, org.ek9.lang::Integer ; RETAIN ; SCOPE_REGISTER p = CALL org.ek9.lang::Panic.<init>(String, Integer) ; RETAIN THROW p
This helper emits ONLY that msg/code/construct/throw body - no labels. The caller owns the
surrounding guard: evaluate the invariant, BRANCH_TRUE past this sequence to an ok-label
when it holds, emit this, then place the ok-label (exactly the shape the three call sites use).
Do NOT re-derive this sequence inline - call emit(IRGenerationContext, List, String, String, String, DebugInfo). It was consolidated (SPEC-assertPanic
§6) from ConstrainedTypeDfnGenerator (constrained-type breach = 1st site) once user
require and the for-range set-check became the 2nd/3rd sites. Omitting the
RETAIN/SCOPE_REGISTER on the msg/code temps orphans them on the ARC/LLVM backend - a leak on every
breach.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe exit code every Panic site uses when it reaches the generated program_mainhandler. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidemit(IRGenerationContext stackContext, List<IRInstr> instructions, String message, String exitCode, String scopeId, DebugInfo debugInfo) Append the construct-and-throw-Panic sequence toinstructions.static StringlocationSuffix(DebugInfo debugInfo) Format the "at file:line:col" suffix appended to a Panic message, or""when the location is unknown.
-
Field Details
-
DEFAULT_EXIT_CODE
The exit code every Panic site uses when it reaches the generated program_mainhandler. Shared across constrained-type breaches, userrequire, and the compiler-injected for-range set-check so all fatal-invariant sites agree (SPEC-assertPanic §9.1). The exit code travels inside the Panic, so distinct sites could diverge in future - but they share this until there is a reason not to.- See Also:
-
-
Method Details
-
locationSuffix
Format the "at file:line:col" suffix appended to a Panic message, or""when the location is unknown. Matches the exact form the oldREQUIREbackend produced, so that moving require/for-range message formatting phase-ward leaves runtime message text byte-identical. -
emit
public static void emit(IRGenerationContext stackContext, List<IRInstr> instructions, String message, String exitCode, String scopeId, DebugInfo debugInfo) Append the construct-and-throw-Panic sequence toinstructions.- Parameters:
stackContext- for temp-name generationinstructions- the instruction list to append tomessage- the fully-formed human-readable Panic message (becomes a String literal)exitCode- the exit-code literal (typicallyDEFAULT_EXIT_CODE)scopeId- the scope the msg/code temps register into for ARC cleanupdebugInfo- source location attached to every emitted instruction
-