ERR/E4.2: failable-main wrapper (report + exit 1 on escaping error)
A pure-failable `main` (`-> !` / `-> !Named`) that lets an error reach the function boundary now exits 1 and prints `error: unhandled error reached main: error.<tag>` + the return trace to stderr, instead of returning the raw tag id truncated as the exit code with no diagnostic. Success exits 0; a `catch`-absorbed error exits 0 (buffer cleared). Codegen wrapper so JIT and AOT behave identically (no host-side special- casing): - emit_llvm.zig: the `.ret` arm detects a failable main and routes to new `emitFailableMainRet` — `icmp ne tag, 0` → success block `ret i32 0` / error block GEPs the tag name out of the always-linked tag-name table, calls `sx_trace_report_unhandled`, `ret i32 1`. main's bare-u32 returns (success `ret(0)` + each raise's `ret(tag)`) all funnel through it. - sx_trace.c: new `sx_trace_report_unhandled(tag, name, name_len)` prints the header + surviving frames to stderr (placeholder frame format mirrors trace.sx until DWARF/E3.0). Lives next to the buffer it reads. - lower.zig validateMainSignature: the pure-failable arm sets needs_trace_runtime so the AOT path auto-links sx_trace.c even when the body emits no other push/clear. Value-carrying `-> (T, !)` main stays gate-rejected (multi-slot wrapper is a separate slice). examples/244-failable-main.sx.
This commit is contained in:
1
tests/expected/244-failable-main.exit
Normal file
1
tests/expected/244-failable-main.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
tests/expected/244-failable-main.txt
Normal file
5
tests/expected/244-failable-main.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
v = 10
|
||||
error: unhandled error reached main: error.Empty
|
||||
error return trace (most recent call last):
|
||||
frame 0: <location pending DWARF> (raw 1)
|
||||
frame 1: <location pending DWARF> (raw 1)
|
||||
Reference in New Issue
Block a user