code wiki / _hdl_build / nx_doc_mainscan_gate.nx
nx_doc_mainscan_gate.nx source
↩ module page · 48 lines · 3422 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"
9
10func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12
13func main() -> i64 {
14 gp("=== nx_doc_mainscan_gate: missing-entry-point (library-built-standalone) diagnosis ===\n" as *u8)
15 var pass: i64 = 0; var fail: i64 = 0
16 let diag: *u8 = "nxasm_x86: UNDEFINED label: main" as *u8
17
18 // KAT1 a program (has main) -> ms_has_main == 1
19 let p1: *u8 = "import \"nx_syscalls.nx\"\nfunc main() -> i64 { return 0 }" as *u8
20 if ms_has_main(p1, slen(p1)) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat1-main-not-seen\n" as *u8) }
21
22 // KAT2 a library (no main) -> ms_has_main == 0
23 let l2: *u8 = "import \"nx_syscalls.nx\"\nfunc helper(x: i64) -> i64 { return x + 1 }\nfunc other() -> i64 { return 7 }" as *u8
24 if ms_has_main(l2, slen(l2)) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat2-false-main\n" as *u8) }
25
26 // KAT3 library + the real UNDEF-MAIN diagnostic -> classified as the library-build error
27 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) }
28
29 // KAT4 program (has main) + same diagnostic -> NOT the library case (a genuinely-unresolved entry, different remedy)
30 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) }
31
32 // KAT5 library + an UNRELATED diagnostic -> not classified (the diagnostic must actually match)
33 let d5: *u8 = "[nx_sov_build_run] COMPILE-FAIL (empty .s after retries)" as *u8
34 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) }
35
36 // KAT6 REAL DATA: read the actual TLS library that triggered rc=102 live; it must have no main + classify.
37 let lp: *i64 = sys_mmap(16) as *i64; lp[0] = 0
38 let tls: *u8 = sys_read_file("runtime/nx_tls13.nx" as *u8, lp)
39 if (tls as i64) != 0 {
40 let tn: i64 = lp[0]
41 if ms_has_main(tls, tn) == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kat6-tls13-has-main?!\n" as *u8) }
42 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) }
43 } else { fail=fail+1; gp(" FAIL kat6-cannot-read-nx_tls13\n" as *u8) }
44
45 gp("DOC-MAINSCAN-GATE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail)
46 if fail == 0 { gp(" verdict=GREEN (library-built-standalone diagnosed on synthetic + the REAL nx_tls13; program+unrelated-diag not misrouted)\n" as *u8); sys_exit(0); return 0 }
47 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1
48}