code wiki / _hdl_build / nx_gatedry_lib.nx
nx_gatedry_lib.nx source
↩ module page · 61 lines · 3133 B
1// nx_gatedry_lib.nx -- the gate-DRY classifier as a MODULE. NO main() ON PURPOSE.
2//
3// WHY A MODULE AND NOT ONE ORGAN: nx_gatedry.nx owns a main(), so its functions cannot be imported by a
4// second entry point -- the exact structural trap nx_gate_verdict_lib.nx documents ("that is why it kept
5// being copied rather than shared -- a structural reason, not an oversight"). The CLI and its GATE both
6// need the classifier, so the classifier lives here and neither copies it.
7//
8// WHAT IT DECIDES: does a gate source inherit the nx_gate_verdict base class (ADOPTER), hand-roll its own
9// verdict (CUSTOM-VERDICT = the L009 breach), or emit no judgeable anchor at all (NO-VERDICT = the seq585
10// unjudgeable class, which nx_gate_green reads as NOT-GREEN even when the gate passes)?
11//
12// u26a0DECLARED ENVELOPE (L011): SUBSTRING PRESENCE over source text. A `gv_verdict(` inside a comment counts
13// as adoption; a gate emitting its verdict through an imported helper reads CUSTOM. A REVIEW SIGNAL at a
14// submission chokepoint, never an auto-verdict over a corpus.
15// license_tier: ORIGINAL No hw writes (Rule 26).
16import "nx_syscalls.nx"
17
18const GD_ADOPTER: i64 = 0
19const GD_CUSTOM: i64 = 1
20const GD_NOVERDICT: i64 = 2
21const GD_UNREADABLE: i64 = 3
22
23func gd_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
24
25func gd_has(hay: *u8, hn: i64, ndl: *u8) -> i64 {
26 let nn: i64 = gd_len(ndl)
27 if nn == 0 { return 0 }
28 if nn > hn { return 0 }
29 var i: i64 = 0
30 while i + nn <= hn {
31 var k: i64 = 0
32 var hit: i64 = 1
33 while k < nn { if hay[i+k] != ndl[k] { hit = 0; k = nn } else { k = k + 1 } }
34 if hit == 1 { return 1 }
35 i = i + 1
36 }
37 return 0
38}
39
40// ORDER MATTERS AND IS THE WHOLE SUBTLETY: adoption is tested FIRST, because a base-class adopter ALSO
41// contains the anchor `verdict=` (gv_verdict emits it). An anchor-first classifier misfiles EVERY adopter
42// as CUSTOM -- i.e. it would report the migration target as the breach. T3 in the gate pins this.
43func gd_classify(buf: *u8, n: i64) -> i64 {
44 if gd_has(buf, n, "gv_verdict(" as *u8) == 1 { return GD_ADOPTER }
45 if gd_has(buf, n, "verdict=" as *u8) == 1 { return GD_CUSTOM }
46 return GD_NOVERDICT
47}
48
49func gd_name(v: i64) -> *u8 {
50 if v == GD_ADOPTER { return "ADOPTER" as *u8 }
51 if v == GD_CUSTOM { return "CUSTOM-VERDICT" as *u8 }
52 if v == GD_NOVERDICT { return "NO-VERDICT" as *u8 }
53 return "UNREADABLE" as *u8
54}
55
56func gd_advice(v: i64) -> *u8 {
57 if v == GD_ADOPTER { return " (inherits nx_gate_verdict -- the D001 target shape)" as *u8 }
58 if v == GD_CUSTOM { return " (L009 BREACH: hand-rolls its verdict. Migrate onto gv_ctr/gv_head/gv_check/gv_verdict; nx_gate_migrate verify PROVES it by judge-equivalence, so the edit is safe to make)" as *u8 }
59 if v == GD_NOVERDICT { return " (seq585 UNJUDGEABLE: no `verdict=` anchor, so nx_gate_green reads a PASSING run as NOT-GREEN. Anchor FIRST via nx_gate_migrate anchor, THEN migrate -- judge-equivalence is vacuous while neither side has an anchor)" as *u8 }
60 return " (could not read the file)" as *u8
61}