ERR/E4.2: truncate integer main's return to u8 for the JIT exit code
A non-failable integer `main :: () -> T` must exit with its return value truncated to u8 (matching C main / the OS exit-status byte), so `sx run` (JIT) and an AOT binary agree. runJITMain clamped instead: any value outside 0..255 returned exit 1, so `return 1105` exited 1 (not 81), `return -1` exited 1 (not 255), and `return 256` exited 1 (not 0). Fix: bit-cast the i32 return to u32 and @truncate to u8 — negatives wrap as their two's-complement low byte rather than being clamped. The AOT path already gets OS truncation, so it was already correct; this makes JIT match. examples/238-main-exit-truncation.sx returns 1105 -> exit 81. Values <=255 (42, 200) still pass through unchanged. Gates: zig build, zig build test, bash tests/run_examples.sh (275 passed; the lone failure is the user's uncommitted 213-canonical-map pack WIP).
This commit is contained in:
1
tests/expected/238-main-exit-truncation.exit
Normal file
1
tests/expected/238-main-exit-truncation.exit
Normal file
@@ -0,0 +1 @@
|
||||
81
|
||||
1
tests/expected/238-main-exit-truncation.txt
Normal file
1
tests/expected/238-main-exit-truncation.txt
Normal file
@@ -0,0 +1 @@
|
||||
returning 1105 -> exit 81
|
||||
Reference in New Issue
Block a user