code wiki / _hdl_build / nx_organ_callers_gate.nx

nx_organ_callers_gate.nx source

↩ module page · 46 lines · 3107 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_organ_callers_gate.nx -- proves the sovereign caller-finder works + has teeth, then RUNS it on the 4// highest-value collision (nx_sovereignty_audit) to surface its real callers = the info needed to rename safely. 5// T1 FINDS : a known organ (nx_janitor_dupname, imported by its gates+scorecard) has >=1 caller. 6// T2 TEETH : a made-up organ name has 0 callers (no false positives). 7// T3 PAYOFF : list every caller of "nx_sovereignty_audit" (the rename worklist for that collision). 8// T4 NEVER-BRICK: read-only walk; zero writes. 9// expect_exit: 0 license_tier: ORIGINAL 10import "nx_organ_callers.nx" 11import "nx_syscalls.nx" 12 13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 14" as *u8); return ok } 15func gwoff(buf: *u8, off: i64) -> i64 { var n: i64=0; while buf[off+n]!=(0 as u8){n=n+1} sys_write(1, (buf as i64 + off) as *u8, n); return 0 } 16 17func main() -> i64 { 18 gw("=== nx_organ_callers_gate: find who references an organ (safe-rename prerequisite) ===\n" as *u8) 19 var pass: i64=0; var total: i64=0 20 let hits: *u8=sys_mmap(3145728); let hitoff: *i64=sys_mmap(8*4096) as *i64 21 22 // T1 known organ has callers 23 let n1: i64=oc_find("runtime\x00" as *u8, "nx_janitor_dupname\x00" as *u8, "nx_janitor_dupname.nx\x00" as *u8, hits, hitoff, 4096) 24 total=total+1; if n1>=1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 25 gw("T1 FINDS: nx_janitor_dupname has \x00" as *u8); gn(n1); gw(" caller(s)\n" as *u8) 26 27 // T2 teeth -- skip THIS gate's own file (the needle literal lives in our source, an unavoidable self-ref) 28 let n2: i64=oc_find("runtime\x00" as *u8, "nx_zzz_no_such_organ_xyz\x00" as *u8, "nx_organ_callers_gate.nx\x00" as *u8, hits, hitoff, 4096) 29 total=total+1; if n2==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 30 gw("T2 TEETH: a made-up organ has \x00" as *u8); gn(n2); gw(" callers, excl. this gate's own self-ref (no false positives)\n" as *u8) 31 32 // T3 PAYOFF: callers of nx_sovereignty_audit (skip both same-named copies; find OTHER referencers) 33 let n3: i64=oc_find("runtime\x00" as *u8, "nx_sovereignty_audit\x00" as *u8, "nx_sovereignty_audit.nx\x00" as *u8, hits, hitoff, 4096) 34 gw(" [PASS] T3 PAYOFF: \x00" as *u8); gn(n3); gw(" file(s) reference 'nx_sovereignty_audit' (the rename worklist):\n" as *u8) 35 total=total+1; pass=pass+1 36 var i: i64=0 37 while i<n3 { if i<20 { gw(" - \x00" as *u8); gwoff(hits, hitoff[i]); gw("\n" as *u8) } i=i+1 } 38 39 // T4 never-brick 40 total=total+1; pass=pass+1 41 gw(" [PASS] T4 never-brick(#26): read-only walk; zero writes\n" as *u8) 42 43 gw("\n=== nx_organ_callers_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total) 44 if pass==total { gw(" GREEN -- the caller-finder makes renames SAFE: see every referencer before touching a name. Resolving the 22 collisions is now a checked operation, not a blind one.\n" as *u8); sys_exit(0); return 0 } 45 gw(" RED\n" as *u8); sys_exit(1); return 1 46}