code wiki / _hdl_build / _constarg_probe.nx

_constarg_probe.nx source

↩ module page · 55 lines · 2710 B

1// _constarg_probe.nx -- minimal repro lattice for debt 1785866425: a const IDENTIFIER passed as a 2// function-call ARGUMENT arrived as 0 in nx_being_showcase (tm_vcol(i, BS_SKIN) painted black), while 3// the same value built in let-locals passed fine. This probe enumerates the suspect axes -- const 4// initializer shape (literal vs expression), value size, and use position (arg1/arg2/store/compare) -- 5// so the compiler fix targets the REAL failing surface, not a guess. expect_exit: 0 when the bug is fixed. 6import "nx_syscalls.nx" 7 8const CA_SMALL: i64 = 2600 9const CA_BIG_LIT: i64 = 11190506 10const CA_BIG_EXPR: i64 = 234 + 192*256 + 170*65536 11const CA_NEG_EXPR: i64 = 0-150 12 13func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func cn(v: i64) -> i64 { 15 let b: *u8 = sys_mmap(32) 16 var x: i64 = v; var ng: i64 = 0 17 if x < 0 { ng = 1; x = 0-x } 18 var i: i64 = 31 19 if x == 0 { b[i]=48 as u8; i=i-1 } 20 while x > 0 { b[i]=(48+x%10) as u8; x=x/10; i=i-1 } 21 if ng == 1 { b[i]=45 as u8; i=i-1 } 22 sys_write(1,(b as i64+i+1) as *u8,31-i) 23 return 0 24} 25func echo1(v: i64) -> i64 { return v } 26func echo2(a: i64, v: i64) -> i64 { return v } 27func tooth(name: *u8, got: i64, want: i64, fails: *i64) -> i64 { 28 cw(name) 29 cw(" got=" as *u8); cn(got); cw(" want=" as *u8); cn(want) 30 if got == want { cw(" PASS\n" as *u8) } else { fails[0] = fails[0] + 1; cw(" FAIL\n" as *u8) } 31 return 0 32} 33 34func main() -> i64 { 35 cw("=== _constarg_probe -- const-identifier use-position lattice (debt 1785866425) ===\n" as *u8) 36 let fails: *i64 = sys_mmap(16) as *i64 37 fails[0] = 0 38 tooth("T1 small-lit const arg1 " as *u8, echo1(CA_SMALL), 2600, fails) 39 tooth("T2 big-lit const arg1 " as *u8, echo1(CA_BIG_LIT), 11190506, fails) 40 tooth("T3 big-expr const arg1 " as *u8, echo1(CA_BIG_EXPR), 11190506, fails) 41 tooth("T4 big-expr const arg2 " as *u8, echo2(1, CA_BIG_EXPR), 11190506, fails) 42 tooth("T5 neg-expr const arg1 " as *u8, echo1(CA_NEG_EXPR), 0-150, fails) 43 var x: i64 = CA_BIG_EXPR 44 tooth("T6 big-expr const store " as *u8, x, 11190506, fails) 45 var cmpok: i64 = 0 46 if CA_BIG_EXPR > 11190505 { cmpok = 1 } 47 tooth("T7 big-expr const compare " as *u8, cmpok, 1, fails) 48 tooth("T8 inline expr arg1 " as *u8, echo1(234 + 192*256 + 170*65536), 11190506, fails) 49 let lv: i64 = 234 + 192*256 + 170*65536 50 tooth("T9 let-local arg1 (control) " as *u8, echo1(lv), 11190506, fails) 51 if fails[0] == 0 { cw("CONSTARG-PROBE GREEN 9/9\n" as *u8); sys_exit(0); return 0 } 52 cw("CONSTARG-PROBE RED fails=" as *u8); cn(fails[0]); cw("\n" as *u8) 53 sys_exit(1) 54 return 1 55}