code wiki / _hdl_build / lmprobe_lm002.nx

lmprobe_lm002.nx source

↩ module page · 35 lines · 1484 B

1// lmprobe_lm002.nx -- LANDMINE PROBE for LM-002 "flat ifs only: 4-deep nested-if miscompiles". 2// CONTRACT (the retirement oracle used for LM-003/LM-007): exit 0 => ROOT-FIXED, the construct now 3// computes correctly; non-zero OR build-failure => STILL LIVE. Deliberately import-light (nx_estr is 4// the shared emit BASE CLASS, nothing else) so a compile failure is attributable to the nested-if 5// construct under test rather than to import weight. 6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_estr.nx" 9 10// 4 levels of nesting with a distinct answer down EVERY path -- a miscompile that collapses a level 11// shows up as the wrong branch value, not merely as a wrong final answer. 12func probe(a: i64, b: i64, c: i64, d: i64) -> i64 { 13 var r: i64 = 0 14 if a == 1 { 15 if b == 2 { 16 if c == 3 { 17 if d == 4 { r = 1234 } else { r = 9 } 18 } else { r = 8 } 19 } else { r = 7 } 20 } else { r = 6 } 21 return r 22} 23 24func main() -> i64 { 25 var bad: i64 = 0 26 if probe(1,2,3,4) != 1234 { bad = 1 } 27 if probe(1,2,3,0) != 9 { bad = 1 } 28 if probe(1,2,0,0) != 8 { bad = 1 } 29 if probe(1,0,0,0) != 7 { bad = 1 } 30 if probe(0,0,0,0) != 6 { bad = 1 } 31 if bad == 1 { es_puts("LM-002 STILL-LIVE (4-deep nested if miscompiles)\n" as *u8); sys_exit(1); return 1 } 32 es_puts("LM-002 ROOT-FIXED (4-deep nested if correct on all 5 paths)\n" as *u8) 33 sys_exit(0) 34 return 0 35}