code wiki / _hdl_build / nx_fwdconst_scan_gate.nx

nx_fwdconst_scan_gate.nx source

↩ module page · 70 lines · 4123 B

1// nx_fwdconst_scan_gate.nx -- GATE for the forward-const detector (4 teeth incl embedded negatives). 2// PREREQ: stage _offc/nx_fwdconst_scan.elf first. Run from nxc2 root. ONE scanner fork total. 3// T1 exactly one FWDCONST row on the 5-fixture dir | T2 the row names bad.nx + const=BADC | 4// T3 summary files=5 flagged=1 | T4 negatives: good(decl-above), cmt(comment-line mention), 5// str(quoted mention), sub(word-boundary FOOX vs FOO) all UNFLAGGED. 6// Mutation proof (manual): drop the word-boundary check in fw_first_use -> sub.nx flags -> T1+T3 RED. 7// license_tier: ORIGINAL No hw writes (Rule 26). 8import "nx_seat_drive_lib.nx" 9import "nx_seg_store.nx" 10import "nx_deploy_lib.nx" 11import "nx_syscalls.nx" 12import "nx_gate_verdict.nx" 13 14func fg_len(s: *u8) -> i64 { 15 var n: i64 = 0 16 while s[n] != (0 as u8) { n = n + 1 } 17 return n 18} 19 20func main(argc: i64, argv: *i64) -> i64 { 21 sys_mkdir("/tmp/fwdc_fix" as *u8, 0x1ed) 22 let f1: *u8 = "func f() -> i64 { return BADC }\nconst BADC: i64 = -100\n" as *u8 23 ss_writefile("/tmp/fwdc_fix/bad.nx" as *u8, f1, fg_len(f1)) 24 let f2: *u8 = "const GOODC: i64 = 5\nfunc g() -> i64 { return GOODC }\n" as *u8 25 ss_writefile("/tmp/fwdc_fix/good.nx" as *u8, f2, fg_len(f2)) 26 let f3: *u8 = "// CMTC is documented here above its decl\nconst CMTC: i64 = 7\nfunc h() -> i64 { return CMTC }\n" as *u8 27 ss_writefile("/tmp/fwdc_fix/cmt.nx" as *u8, f3, fg_len(f3)) 28 let f4: *u8 = "func s() -> *u8 { return \"STRC inside a string\" as *u8 }\nconst STRC: i64 = 9\n" as *u8 29 ss_writefile("/tmp/fwdc_fix/str.nx" as *u8, f4, fg_len(f4)) 30 let f5: *u8 = "func t() -> i64 { let FOOX: i64 = 1 return FOOX }\nconst FOO: i64 = 3\n" as *u8 31 ss_writefile("/tmp/fwdc_fix/sub.nx" as *u8, f5, fg_len(f5)) 32 33 sys_unlinkat("/tmp/fwdc_gate.out" as *u8) 34 let av: *i64 = sys_mmap(32) as *i64 35 av[0] = "/tmp/fwdc_fix" as *u8 as i64 36 let rc: i64 = dep_run_capture("_offc/nx_fwdconst_scan.elf" as *u8, av, 1, "/tmp/fwdc_gate.out" as *u8) 37 let out: *u8 = sys_mmap(65536) 38 let n: i64 = dp_read("/tmp/fwdc_gate.out" as *u8, out, 65536) 39 40 var pass: i64 = 0 41 let rows: i64 = sd_count(out, n, "FWDCONST " as *u8) 42 if rows == 1 { if rc == 0 { sd_w("T1 exactly-one-row PASS\n" as *u8); pass = pass + 1 } else { sd_w("T1 exactly-one-row FAIL rc\n" as *u8) } } else { sd_w("T1 exactly-one-row FAIL\n" as *u8) } 43 let hb: i64 = sd_count(out, n, "bad.nx" as *u8) 44 let hc: i64 = sd_count(out, n, "const=BADC" as *u8) 45 if hb >= 1 { if hc == 1 { sd_w("T2 names-the-culprit PASS\n" as *u8); pass = pass + 1 } else { sd_w("T2 names-the-culprit FAIL\n" as *u8) } } else { sd_w("T2 names-the-culprit FAIL\n" as *u8) } 46 let s1: i64 = sd_count(out, n, "files=5" as *u8) 47 let s2: i64 = sd_count(out, n, "flagged=1" as *u8) 48 if s1 == 1 { if s2 == 1 { sd_w("T3 summary-exact PASS\n" as *u8); pass = pass + 1 } else { sd_w("T3 summary-exact FAIL\n" as *u8) } } else { sd_w("T3 summary-exact FAIL\n" as *u8) } 49 var negs: i64 = 0 50 negs = negs + sd_count(out, n, "const=GOODC" as *u8) 51 negs = negs + sd_count(out, n, "const=CMTC" as *u8) 52 negs = negs + sd_count(out, n, "const=STRC" as *u8) 53 negs = negs + sd_count(out, n, "const=FOO\n" as *u8) 54 if negs == 0 { sd_w("T4 negatives-unflagged PASS\n" as *u8); pass = pass + 1 } else { sd_w("T4 negatives-unflagged FAIL\n" as *u8) } 55 56 sd_w("NX-FWDCONST-GATE pass=" as *u8) 57 let pb: *u8 = sys_mmap(24) 58 var m: i64 = pass 59 if m == 0 { pb[0] = 48 as u8; pb[1] = 0 as u8 } else { pb[0] = (48 + m) as u8; pb[1] = 0 as u8 } 60 sd_w(pb) 61 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 62 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 63 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 64 let ctr__dry: *i64 = gv_ctr() 65 ctr__dry[0] = pass 66 ctr__dry[1] = 4 67 let rc__dry: i64 = gv_verdict("FWDCONST-SCAN-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 68 sys_exit(rc__dry) 69 return rc__dry 70}