code wiki / _hdl_build / nx_doc_mainscan_gate.nx

nx_doc_mainscan_gate.nx source

↩ module page · 56 lines · 3813 B

1import "nx_gate_gn.nx" 2// nx_doc_mainscan_gate.nx -- liar-kill gate for the missing-entry-point (library-built-standalone) diagnosis. 3// MUST: detect `func main` present/absent; classify a no-main source + the real "UNDEFINED label: main" diagnostic 4// as the library-build error; and -- the real-data teeth -- read the ACTUAL runtime/nx_tls13.nx and confirm it has 5// no main (it is the TLS library that triggered rc=102 live). MUST-NOT: classify a source that DOES define main as 6// the library case (that is a different problem), nor classify on an unrelated diagnostic. expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_doc_mainscan.nx" 9import "nx_gate_verdict.nx" 10 11func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13 14func main() -> i64 { 15 gp("=== nx_doc_mainscan_gate: missing-entry-point (library-built-standalone) diagnosis ===\n" as *u8) 16 var pass: i64 = 0; var fail: i64 = 0 17 let diag: *u8 = "nxasm_x86: UNDEFINED label: main" as *u8 18 19 // KAT1 a program (has main) -> ms_has_main == 1 20 let p1: *u8 = "import \"nx_syscalls.nx\"\nfunc main() -> i64 { return 0 }" as *u8 21 if ms_has_main(p1, slen(p1)) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat1-main-not-seen\n" as *u8) } 22 23 // KAT2 a library (no main) -> ms_has_main == 0 24 let l2: *u8 = "import \"nx_syscalls.nx\"\nfunc helper(x: i64) -> i64 { return x + 1 }\nfunc other() -> i64 { return 7 }" as *u8 25 if ms_has_main(l2, slen(l2)) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat2-false-main\n" as *u8) } 26 27 // KAT3 library + the real UNDEF-MAIN diagnostic -> classified as the library-build error 28 if ms_is_library_build_error(diag, slen(diag), l2, slen(l2)) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat3-not-classified\n" as *u8) } 29 30 // KAT4 program (has main) + same diagnostic -> NOT the library case (a genuinely-unresolved entry, different remedy) 31 if ms_is_library_build_error(diag, slen(diag), p1, slen(p1)) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat4-misrouted-program\n" as *u8) } 32 33 // KAT5 library + an UNRELATED diagnostic -> not classified (the diagnostic must actually match) 34 let d5: *u8 = "[nx_sov_build_run] COMPILE-FAIL (empty .s after retries)" as *u8 35 if ms_is_library_build_error(d5, slen(d5), l2, slen(l2)) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat5-wrong-diag-matched\n" as *u8) } 36 37 // KAT6 REAL DATA: read the actual TLS library that triggered rc=102 live; it must have no main + classify. 38 let lp: *i64 = sys_mmap(16) as *i64; lp[0] = 0 39 let tls: *u8 = sys_read_file("runtime/nx_tls13.nx" as *u8, lp) 40 if (tls as i64) != 0 { 41 let tn: i64 = lp[0] 42 if ms_has_main(tls, tn) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat6-tls13-has-main?!\n" as *u8) } 43 if ms_is_library_build_error(diag, slen(diag), tls, tn) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat6-tls13-not-classified\n" as *u8) } 44 } else { fail=fail+1; gp(" FAIL kat6-cannot-read-nx_tls13\n" as *u8) } 45 46 gp("DOC-MAINSCAN-GATE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail) 47 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 48 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 49 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 50 let ctr__dry: *i64 = gv_ctr() 51 ctr__dry[0] = pass 52 ctr__dry[1] = pass + fail 53 let rc__dry: i64 = gv_verdict("DOC-MAINSCAN-GATE" as *u8, ctr__dry, "library-built-standalone diagnosed on synthetic + the REAL nx_tls13; program+unrelated-diag not misrouted)" as *u8) 54 sys_exit(rc__dry) 55 return rc__dry 56}