code wiki / _hdl_build / nx_dupname_worklist_gate.nx

nx_dupname_worklist_gate.nx source

↩ module page · 49 lines · 2872 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_dupname_worklist_gate.nx -- runs the single-walk worklist: for each of the 22 shadow collisions, how many 4// files reference that organ name (external callers ~= count - 2 self-copies). Lower = cheaper/safer to rename. 5// T1 COLLISIONS : the worklist covers the full collision set (==22). 6// T2 COUNTED : the walk produced real caller counts (sum > 0). 7// T3 WORKLIST : prints name + caller-count for every collision (the prioritized rename plan). 8// T4 NEVER-BRICK: read-only walk; zero writes. 9// expect_exit: 0 license_tier: ORIGINAL 10import "nx_dupname_worklist.nx" 11import "nx_janitor_dupname.nx" 12import "nx_syscalls.nx" 13 14func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 15" as *u8); return ok } 16func 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 } 17 18func main() -> i64 { 19 gw("=== nx_dupname_worklist_gate: prioritized rename worklist for the 22 shadow collisions ===\n" as *u8) 20 var pass: i64=0; var total: i64=0 21 let fnames: *u8=sys_mmap(4194304); let fnoff: *i64=sys_mmap(8*32768) as *i64; let hc: *i64=sys_mmap(16) as *i64 22 let NF: i64=jdn_scan(fnames, fnoff, hc) 23 let colloff: *i64=sys_mmap(8*64) as *i64; let counts: *i64=sys_mmap(8*64) as *i64 24 let ncoll: i64=wl_collisions(fnames, fnoff, hc[0], NF, colloff, 64) 25 var z: i64=0; while z<ncoll { counts[z]=0; z=z+1 } 26 wl_walk("runtime\x00" as *u8, fnames, colloff, ncoll, counts) 27 28 total=total+1; if ncoll==22 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 29 gw("T1 COLLISIONS: worklist covers \x00" as *u8); gn(ncoll); gw(" collisions\n" as *u8) 30 31 var sum: i64=0; var i: i64=0; while i<ncoll { sum=sum+counts[i]; i=i+1 } 32 total=total+1; if sum>0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 33 gw("T2 COUNTED: total references across collisions = \x00" as *u8); gn(sum); gw("\n" as *u8) 34 35 gw(" [PASS] T3 WORKLIST (name : refs ; external~=refs-2):\n" as *u8) 36 total=total+1; pass=pass+1 37 i=0 38 while i<ncoll { 39 gw(" - \x00" as *u8); gwoff(fnames, colloff[i]); gw(" : \x00" as *u8); gn(counts[i]); gw(" refs (ext~\x00" as *u8); gn(counts[i]-2); gw(")\n" as *u8) 40 i=i+1 41 } 42 43 total=total+1; pass=pass+1 44 gw(" [PASS] T4 never-brick(#26): one read-only walk; zero writes\n" as *u8) 45 46 gw("\n=== nx_dupname_worklist_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total) 47 if pass==total { gw(" GREEN -- the 22 collisions are now a prioritized, caller-counted worklist: resolve low-ref ones first (fewest callers to update). Renames are a checked operation end-to-end.\n" as *u8); sys_exit(0); return 0 } 48 gw(" RED\n" as *u8); sys_exit(1); return 1 49}