code wiki / _hdl_build / nx_fwdconst_scan_gate.nx

nx_fwdconst_scan_gate.nx source

↩ module page · 68 lines · 3710 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" 12 13func fg_len(s: *u8) -> i64 { 14 var n: i64 = 0 15 while s[n] != (0 as u8) { n = n + 1 } 16 return n 17} 18 19func main(argc: i64, argv: *i64) -> i64 { 20 sys_mkdir("/tmp/fwdc_fix" as *u8, 0x1ed) 21 let f1: *u8 = "func f() -> i64 { return BADC }\nconst BADC: i64 = -100\n" as *u8 22 ss_writefile("/tmp/fwdc_fix/bad.nx" as *u8, f1, fg_len(f1)) 23 let f2: *u8 = "const GOODC: i64 = 5\nfunc g() -> i64 { return GOODC }\n" as *u8 24 ss_writefile("/tmp/fwdc_fix/good.nx" as *u8, f2, fg_len(f2)) 25 let f3: *u8 = "// CMTC is documented here above its decl\nconst CMTC: i64 = 7\nfunc h() -> i64 { return CMTC }\n" as *u8 26 ss_writefile("/tmp/fwdc_fix/cmt.nx" as *u8, f3, fg_len(f3)) 27 let f4: *u8 = "func s() -> *u8 { return \"STRC inside a string\" as *u8 }\nconst STRC: i64 = 9\n" as *u8 28 ss_writefile("/tmp/fwdc_fix/str.nx" as *u8, f4, fg_len(f4)) 29 let f5: *u8 = "func t() -> i64 { let FOOX: i64 = 1 return FOOX }\nconst FOO: i64 = 3\n" as *u8 30 ss_writefile("/tmp/fwdc_fix/sub.nx" as *u8, f5, fg_len(f5)) 31 32 sys_unlinkat("/tmp/fwdc_gate.out" as *u8) 33 let av: *i64 = sys_mmap(32) as *i64 34 av[0] = "/tmp/fwdc_fix" as *u8 as i64 35 let rc: i64 = dep_run_capture("_offc/nx_fwdconst_scan.elf" as *u8, av, 1, "/tmp/fwdc_gate.out" as *u8) 36 let out: *u8 = sys_mmap(65536) 37 let n: i64 = dp_read("/tmp/fwdc_gate.out" as *u8, out, 65536) 38 39 var pass: i64 = 0 40 let rows: i64 = sd_count(out, n, "FWDCONST " as *u8) 41 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) } 42 let hb: i64 = sd_count(out, n, "bad.nx" as *u8) 43 let hc: i64 = sd_count(out, n, "const=BADC" as *u8) 44 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) } 45 let s1: i64 = sd_count(out, n, "files=5" as *u8) 46 let s2: i64 = sd_count(out, n, "flagged=1" as *u8) 47 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) } 48 var negs: i64 = 0 49 negs = negs + sd_count(out, n, "const=GOODC" as *u8) 50 negs = negs + sd_count(out, n, "const=CMTC" as *u8) 51 negs = negs + sd_count(out, n, "const=STRC" as *u8) 52 negs = negs + sd_count(out, n, "const=FOO\n" as *u8) 53 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) } 54 55 sd_w("NX-FWDCONST-GATE pass=" as *u8) 56 let pb: *u8 = sys_mmap(24) 57 var m: i64 = pass 58 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 } 59 sd_w(pb) 60 if pass == 4 { 61 sd_w("/4 verdict=GREEN\n" as *u8) 62 sys_exit(0) 63 return 0 64 } 65 sd_w("/4 verdict=RED\n" as *u8) 66 sys_exit(1) 67 return 1 68}