code wiki / _hdl_build / nx_capability_census_gate.nx

nx_capability_census_gate.nx source

↩ module page · 123 lines · 8793 B

1// nx_capability_census_gate.nx -- GATE for the GENERAL capability-comparison engine (nx_capability_census). 2// Proves the reusable "study any tool -> compare to our census" muscle WITHOUT needing the network: 3// T1 VERDICT LOGIC -- cc_verdict truth-table (GAP/PARITY/AHEAD/BOTH-ABSENT) correct over all cases. 4// T2 DISK-FACT GRADE -- cc_our_grade==PRESENT for a REAL organ on disk, ==ABSENT for a fake path (liar-kill: 5// our side can never grade PRESENT without the organ actually opening). 6// T3 CORPUS DETECT -- cc_comp_attest finds a term that IS in a written fixture corpus, and returns 0 for a 7// term that is NOT (competitor evidence is never fabricated). 8// T4 NEVER-BRICK -- read-only (one idempotent fixture write), bounded, deterministic (re-run identical). 9// Then it PRINTS the honest LibrePCB-vs-us capability matrix over REAL organ paths + the sovereign-fetched 10// corpus (knowledge/fetched/eda_*.raw if banked; 0 = run nx_eda_tooling_research_fetch). GREEN iff T1-T4 pass. 11// Sovereign nx_cc->nxasm (no gcc, no 3rd-party). expect_exit: 0 license_tier: ORIGINAL 12import "nx_capability_census.nx" 13import "nx_syscalls.nx" 14 15func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 17 18func ccg_streq(a: *u8, b: *u8) -> i64 { 19 var i: i64 = 0 20 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 21 if b[i] != (0 as u8) { return 0 } 22 return 1 23} 24 25func demo_row(label: *u8, term: *u8, organ: *u8, exceed: *u8, paths: *i64, npaths: i64, buf: *u8, cap: i64) -> i64 { 26 let comp: i64 = cc_comp_attest(paths, npaths, term, buf, cap) 27 let our: i64 = cc_our_grade(organ, exceed) 28 let v: i64 = cc_verdict(comp, our) 29 w(" "); w(cc_verdict_str(v)); w(" us="); w(cc_grade_str(our)); w(" them(src="); wn(comp); w(") "); w(label); w("\n") 30 return 0 31} 32 33func main() -> i64 { 34 w("=== nx_capability_census_gate: GENERAL tool-vs-census comparison engine (sovereign, data-driven) ===\n" as *u8) 35 var pass: i64 = 0; var total: i64 = 0 36 let cap: i64 = 2097152 37 let buf: *u8 = sys_mmap(cap) 38 39 // ---------- T1: VERDICT LOGIC truth-table ---------- 40 var t1ok: i64 = 1 41 if cc_verdict(1, 0) != 1 { t1ok = 0 } // they have, we ABSENT -> GAP 42 if cc_verdict(2, 3) != 2 { t1ok = 0 } // both have -> PARITY 43 if cc_verdict(1, 4) != 3 { t1ok = 0 } // we EXCEEDS -> AHEAD 44 if cc_verdict(0, 3) != 3 { t1ok = 0 } // we have, they unattested -> AHEAD 45 if cc_verdict(0, 0) != 0 { t1ok = 0 } // neither -> BOTH-ABSENT 46 total=total+1; if t1ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 47 w("T1 verdict logic: GAP/PARITY/AHEAD/BOTH-ABSENT all correct\n" as *u8) 48 49 // ---------- T2: DISK-FACT GRADE + liar-kill ---------- 50 let real_organ: *u8 = "runtime/nx_pcb_gerber.nx" as *u8 51 let fake_organ: *u8 = "runtime/nx_DOES_NOT_EXIST_zzqq.nx" as *u8 52 let none: *u8 = "runtime/nx_DOES_NOT_EXIST_zzqq.nx" as *u8 53 let g_real: i64 = cc_our_grade(real_organ, none) 54 let g_fake: i64 = cc_our_grade(fake_organ, none) 55 var t2ok: i64 = 1 56 if g_real != 3 { t2ok = 0 } // real organ on disk -> PRESENT 57 if g_fake != 0 { t2ok = 0 } // fake path -> ABSENT (cannot fabricate PRESENT) 58 total=total+1; if t2ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 59 w("T2 disk-fact grade: real organ=" as *u8); wn(g_real); w(" (PRESENT) fake=" as *u8); wn(g_fake); w(" (ABSENT, liar-killed)\n" as *u8) 60 61 // ---------- T3: CORPUS DETECT + non-fabrication ---------- 62 let fxpath: *u8 = "knowledge/fetched/cc_selftest.raw" as *u8 63 let fxfd: i64 = sys_openat_wr(fxpath, 420) 64 if fxfd >= 0 { 65 let s: *u8 = "sovereign self-test corpus: this tool supports schematic capture and gerber export and drill files\x00" as *u8 66 var sl: i64 = 0; while s[sl] != (0 as u8) { sl = sl + 1 } 67 sys_write(fxfd, s, sl); sys_close(fxfd) 68 } 69 let fx: *i64 = sys_mmap(8 * 2) as *i64 70 fx[0] = fxpath as i64 71 let hit_present: i64 = cc_comp_attest(fx, 1, "schematic" as *u8, buf, cap) 72 let hit_absent: i64 = cc_comp_attest(fx, 1, "zzbogus_capability" as *u8, buf, cap) 73 var t3ok: i64 = 1 74 if hit_present < 1 { t3ok = 0 } // a term that IS present is detected 75 if hit_absent != 0 { t3ok = 0 } // a term that is ABSENT is never fabricated 76 total=total+1; if t3ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 77 w("T3 corpus detect: present-term src=" as *u8); wn(hit_present); w(" absent-term src=" as *u8); wn(hit_absent); w(" (no fabrication)\n" as *u8) 78 79 // ---------- T4: NEVER-BRICK (deterministic) ---------- 80 let d1: i64 = cc_comp_attest(fx, 1, "gerber" as *u8, buf, cap) 81 let d2: i64 = cc_comp_attest(fx, 1, "gerber" as *u8, buf, cap) 82 var t4ok: i64 = 1 83 if d1 != d2 { t4ok = 0 } 84 total=total+1; if t4ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 85 w("T4 never-brick: deterministic (" as *u8); wn(d1); w("==" as *u8); wn(d2); w("), read-only, bounded\n" as *u8) 86 87 // ---------- T5: LABEL INTEGRITY (liar-killer from mutation probe, 2026-07-14) ---------- 88 // The generic mutation probe found a SURVIVOR here: flipping `g == 3` in cc_grade_str swapped the 89 // PRESENT/ABSENT labels while every NUMERIC check stayed green -- i.e. the census MATRIX (what the 90 // operator reads on /compare) could LIE with a GREEN gate. The renderers are now truth-tabled. 91 var t5ok: i64 = 1 92 if ccg_streq(cc_grade_str(4), "EXCEEDS" as *u8) != 1 { t5ok = 0 } 93 if ccg_streq(cc_grade_str(3), "PRESENT" as *u8) != 1 { t5ok = 0 } 94 if ccg_streq(cc_grade_str(0), "ABSENT " as *u8) != 1 { t5ok = 0 } 95 if ccg_streq(cc_verdict_str(3), "AHEAD " as *u8) != 1 { t5ok = 0 } 96 if ccg_streq(cc_verdict_str(2), "PARITY" as *u8) != 1 { t5ok = 0 } 97 if ccg_streq(cc_verdict_str(1), "GAP " as *u8) != 1 { t5ok = 0 } 98 if ccg_streq(cc_verdict_str(0), "------" as *u8) != 1 { t5ok = 0 } 99 total=total+1; if t5ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 100 w("T5 label integrity: grade/verdict strings match their codes (a swapped label = lying matrix, killed)\n" as *u8) 101 102 // ---------- DEMO: the honest LibrePCB-vs-us matrix (the operator's actual question) ---------- 103 w("\n --- LibrePCB / EDA-suite vs Nishi (verdict | us-grade | their-source-count) ---\n" as *u8) 104 w(" (them-src from sovereign-fetched knowledge/fetched/eda_*.raw; 0 = run nx_eda_tooling_research_fetch)\n" as *u8) 105 let subj: *i64 = sys_mmap(8 * 4) as *i64 106 subj[0] = "knowledge/fetched/eda_librepcb.raw" as *u8 as i64 107 subj[1] = "knowledge/fetched/eda_kicad.raw" as *u8 as i64 108 subj[2] = "knowledge/fetched/eda_comparison.raw" as *u8 as i64 109 let ns: i64 = 3 110 demo_row("schematic capture -> netlist" as *u8, "schematic" as *u8, "runtime/_hdl_build/nx_schematic.nx" as *u8, none, subj, ns, buf, cap) 111 demo_row("board copper geometry + editor" as *u8, "board" as *u8, "runtime/nx_pcb_gerber.nx" as *u8, none, subj, ns, buf, cap) 112 demo_row("Gerber RS-274X export" as *u8, "Gerber" as *u8, "runtime/nx_pcb_gerber.nx" as *u8, none, subj, ns, buf, cap) 113 demo_row("Excellon drill export" as *u8, "drill" as *u8, "runtime/nx_pcb_drill.nx" as *u8, none, subj, ns, buf, cap) 114 demo_row("design rule check (DRC)" as *u8, "design rule" as *u8,"runtime/_hdl_build/nx_pcb_drc.nx" as *u8, none, subj, ns, buf, cap) 115 demo_row("interactive autorouter" as *u8, "autorout" as *u8, "runtime/_hdl_build/nx_pcb_autoroute.nx" as *u8, none, subj, ns, buf, cap) 116 demo_row("isolation-milling CAM (etch-free)" as *u8,"milling" as *u8, "runtime/nx_pcb_cam.nx" as *u8, none, subj, ns, buf, cap) 117 demo_row("component library / supply-chain BOM" as *u8,"supplier" as *u8,"runtime/_hdl_build/nx_bom.nx" as *u8, none, subj, ns, buf, cap) 118 demo_row("FPGA place-and-route (sovereign)" as *u8,"place" as *u8, "runtime/_hdl_build/nx_fpga_pnr.nx" as *u8,none, subj, ns, buf, cap) 119 120 w("\n=== nx_capability_census_gate " as *u8); wn(pass); w("/" as *u8); wn(total) 121 if pass == total { w(" GREEN (general data-driven tool-vs-census comparison engine; verdict logic + disk-fact grade + corpus detect + never-brick; adding a tool = data rows)\n" as *u8); sys_exit(0); return 0 } 122 w(" RED\n" as *u8); sys_exit(1); return 1 123}