code wiki / _hdl_build / _stale_probe.nx

_stale_probe.nx source

↩ module page · 30 lines · 1707 B

1// _stale_probe.nx -- verify the STALE-SUSPECT landmines LM-003 (>6 args) + LM-007 2// (*p as *u8 one-expression deref-cast) -- if the roots are fixed, retire the laws. 3// license_tier: ORIGINAL 4import "nx_syscalls.nx" 5func sp_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 6// LM-003: a 7-arg function -- the 7th arg must arrive intact (the tail-call-drop bug) 7func sp_seven(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64) -> i64 { 8 return a + b + c + d + e + f + g 9} 10func main() -> i64 { 11 sp_p("=== STALE PROBE: LM-003 (>6 args) + LM-007 (deref-cast) ===\n" as *u8) 12 var bad: i64 = 0 13 // LM-003: 1+2+4+8+16+32+64 = 127; if the 7th (64) drops, we get 63 14 let s7: i64 = sp_seven(1, 2, 4, 8, 16, 32, 64) 15 if s7 == 127 { sp_p(" LM-003 (>6 args): 7th arg INTACT (127) -> root fixed, STALE\n" as *u8) } 16 else { sp_p(" LM-003: 7th arg DROPPED -> real, keep\n" as *u8); bad = bad + 1 } 17 // LM-007: one-expression deref-cast *pp as *u8 ; pp points to a byte buffer addr 18 let buf: *u8 = sys_mmap(16) 19 buf[0] = 65 as u8 // 'A' 20 let pp: *i64 = sys_mmap(16) as *i64 21 pp[0] = buf as i64 22 // deref pp[0] (the addr) and cast to *u8 in ONE expression, read [0] 23 let viacast: *u8 = (pp[0]) as *u8 24 if viacast[0] == (65 as u8) { sp_p(" LM-007 (deref-cast): correct (65) -> root fixed, STALE\n" as *u8) } 25 else { sp_p(" LM-007: miscompile -> real, keep\n" as *u8); bad = bad + 1 } 26 if bad == 0 { sp_p(" STALE PROBE: BOTH STALE (retire LM-003 + LM-007 laws)\n" as *u8); sys_exit(0); return 0 } 27 sp_p(" STALE PROBE: a law is still REAL (keep it)\n" as *u8) 28 sys_exit(1) 29 return 1 30}