code wiki / _hdl_build / nx_uigen_l3_gate.nx
nx_uigen_l3_gate.nx source
↩ module page · 159 lines · 7917 B
1import "nx_gate_gn.nx"
2// nx_uigen_l3_gate.nx -- MEASURES roadmap rung L3 (procedural design-grammar) at SCALE. 32 seeds -> 32 designs;
3// an INDEPENDENT structural checker parses the emitted BYTES (not the generator's intent) and enforces the
4// grammar's validity rules: exactly one hero (first), exactly one CTA band (last), 3..5 middle bands, no
5// duplicates, FAQ never before pricing. Plus: both-theme palette accessibility (integer HSL sums), S-class
6// craft markers, and DIVERSITY (distinct design signatures + distinct section orderings). VALIDITY x DIVERSITY
7// is the L3 metric pair: many designs, every one correct. Writes 2 samples for the independent nx_ui_judge.
8// expect_exit: 0 license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_uigen_l3.nx"
11import "nx_gate_verdict.nx"
12
13func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func litlen(lit: *u8) -> i64 { var n: i64=0; while lit[n]!=(0 as u8){n=n+1} return n }
15func idxof(buf: *u8, len: i64, lit: *u8) -> i64 {
16 let ll: i64=litlen(lit)
17 if ll==0 { return 0-1 }
18 var i: i64=0
19 while i+ll<=len { var j: i64=0; var ok: i64=1; while j<ll { if buf[i+j]!=lit[j] { ok=0; j=ll } else { j=j+1 } } if ok==1 { return i } i=i+1 }
20 return 0-1
21}
22func countof(buf: *u8, len: i64, lit: *u8) -> i64 {
23 let ll: i64=litlen(lit)
24 if ll==0 { return 0 }
25 var c: i64=0; var i: i64=0
26 while i+ll<=len { var j: i64=0; var ok: i64=1; while j<ll { if buf[i+j]!=lit[j] { ok=0; j=ll } else { j=j+1 } } if ok==1 { c=c+1; i=i+ll } else { i=i+1 } }
27 return c
28}
29func csum(p: i64) -> i64 { return (p/65536) + ((p/256)%256) + (p%256) }
30// marker literal for section id (class=-anchored so CSS text never matches)
31func sec_marker(sec: i64) -> *u8 {
32 if sec==0 { return "class=\"grid3\"" as *u8 }
33 if sec==1 { return "class=\"sec splitband\"" as *u8 }
34 if sec==2 { return "class=\"sec stepsband\"" as *u8 }
35 if sec==3 { return "class=\"sec priceband\"" as *u8 }
36 if sec==4 { return "class=\"sec quoteband\"" as *u8 }
37 if sec==5 { return "class=\"sec faqband\"" as *u8 }
38 return "class=\"trust\"" as *u8
39}
40
41func main() -> i64 {
42 let cap: i64 = 524288
43 let buf: *u8 = sys_mmap(cap)
44 let spec: *i64 = sys_mmap(128) as *i64
45 let sigs: *i64 = sys_mmap(512) as *i64
46 let ords: *i64 = sys_mmap(512) as *i64
47 var allvalid: i64 = 1
48 var allcraft: i64 = 1
49 var alla11y: i64 = 1
50
51 gp("=== NX-UIGEN-L3 GATE -- design-grammar at scale: 32 seeds -> 32 designs, EVERY one structurally valid ===\n" as *u8)
52 gp("Validity is checked by an INDEPENDENT byte-parser against the grammar rules, not by the generator.\n\n" as *u8)
53
54 var i: i64 = 0
55 while i < 32 {
56 let seed: i64 = 1000 + i * 77
57 l3_spec_from_seed(spec, seed)
58 let off: i64 = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
59 // ---- independent structural validity on the BYTES ----
60 var valid: i64 = 1
61 if countof(buf, off, "class=\"hero\"" as *u8) != 1 { valid = 0 }
62 if countof(buf, off, "class=\"final\"" as *u8) != 1 { valid = 0 }
63 let hero_at: i64 = idxof(buf, off, "class=\"hero\"" as *u8)
64 let final_at: i64 = idxof(buf, off, "class=\"final\"" as *u8)
65 var present: i64 = 0
66 var s: i64 = 0
67 while s < 7 {
68 let c: i64 = countof(buf, off, sec_marker(s))
69 if c > 1 { valid = 0 }
70 if c == 1 {
71 present = present + 1
72 let at: i64 = idxof(buf, off, sec_marker(s))
73 if at < hero_at { valid = 0 }
74 if at > final_at { valid = 0 }
75 }
76 s = s + 1
77 }
78 if present < 3 { valid = 0 }
79 if present > 5 { valid = 0 }
80 let p_at: i64 = idxof(buf, off, sec_marker(3))
81 let f_at: i64 = idxof(buf, off, sec_marker(5))
82 if p_at >= 0 { if f_at >= 0 { if f_at < p_at { valid = 0 } } }
83 if valid == 0 { allvalid = 0 }
84 // ---- craft markers ----
85 var craft: i64 = 1
86 if countof(buf, off, "var(--nx-" as *u8) == 0 { craft = 0 }
87 if countof(buf, off, "skip-link" as *u8) == 0 { craft = 0 }
88 if countof(buf, off, "@media" as *u8) == 0 { craft = 0 }
89 if countof(buf, off, "clamp(" as *u8) == 0 { craft = 0 }
90 if countof(buf, off, "focus-visible" as *u8) == 0 { craft = 0 }
91 if countof(buf, off, "prefers-reduced-motion" as *u8) == 0 { craft = 0 }
92 if countof(buf, off, "<svg" as *u8) == 0 { craft = 0 }
93 if craft == 0 { allcraft = 0 }
94 // ---- both-theme palette accessibility by construction ----
95 let hue: i64 = spec[0]
96 var acc: i64 = 0
97 let li: i64 = csum(l1_hsl_pack(hue, 25, 12))
98 let lb: i64 = csum(l1_hsl_pack(hue, 22, 97))
99 let di: i64 = csum(l1_hsl_pack(hue, 15, 92))
100 let db: i64 = csum(l1_hsl_pack(hue, 24, 9))
101 if li < 230 { if lb > 660 { if di > 640 { if db < 190 { acc = 1 } } } }
102 if acc == 0 { alla11y = 0 }
103 // ---- design signature (diversity) ----
104 var orderpack: i64 = 0
105 var k: i64 = 0
106 while k < spec[4] { orderpack = orderpack * 8 + (spec[5 + k] + 1); k = k + 1 }
107 sigs[i] = spec[0] + spec[1] * 512 + spec[2] * 2048 + spec[3] * 8192 + orderpack * 32768
108 ords[i] = orderpack
109 gp(" seed=" as *u8); gn(seed); gp(" hue=" as *u8); gn(spec[0]); gp(" rel=" as *u8); gn(spec[1]); gp(" rad=" as *u8); gn(spec[2]); gp(" den=" as *u8); gn(spec[3]); gp(" nmid=" as *u8); gn(spec[4]); gp(" order=" as *u8); gn(orderpack); gp(" bytes=" as *u8); gn(off); gp(" valid=" as *u8); gn(valid); gp(" craft=" as *u8); gn(craft); gp(" a11y=" as *u8); gn(acc); gp("\n" as *u8)
110 i = i + 1
111 }
112
113 // distinct signatures + distinct orderings
114 var dsig: i64 = 0
115 var dord: i64 = 0
116 var a: i64 = 0
117 while a < 32 {
118 var seen: i64 = 0
119 var b: i64 = 0
120 while b < a { if sigs[b] == sigs[a] { seen = 1 } b = b + 1 }
121 if seen == 0 { dsig = dsig + 1 }
122 seen = 0
123 b = 0
124 while b < a { if ords[b] == ords[a] { seen = 1 } b = b + 1 }
125 if seen == 0 { dord = dord + 1 }
126 a = a + 1
127 }
128
129 // write 2 samples for the independent judge
130 l3_spec_from_seed(spec, 4242)
131 var soff: i64 = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
132 var fd: i64 = sys_openat_wr("web_assets/uigen_l3_sample_a.html" as *u8, 420)
133 if fd >= 0 { sys_write(fd, buf, soff); sys_close(fd) }
134 gp("\n-- sample A (seed 4242) " as *u8); gn(soff); gp(" bytes -> web_assets/uigen_l3_sample_a.html\n" as *u8)
135 l3_spec_from_seed(spec, 777)
136 soff = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
137 fd = sys_openat_wr("web_assets/uigen_l3_sample_b.html" as *u8, 420)
138 if fd >= 0 { sys_write(fd, buf, soff); sys_close(fd) }
139 gp("-- sample B (seed 777) " as *u8); gn(soff); gp(" bytes -> web_assets/uigen_l3_sample_b.html\n" as *u8)
140
141 gp("\n-- L3 MEASUREMENT: designs=32 all_valid=" as *u8); gn(allvalid); gp(" all_craft=" as *u8); gn(allcraft); gp(" all_a11y=" as *u8); gn(alla11y)
142 gp(" distinct_signatures=" as *u8); gn(dsig); gp("/32 distinct_orderings=" as *u8); gn(dord); gp("/32\n" as *u8)
143
144 var ok: i64 = 1
145 if allvalid == 0 { ok = 0 }
146 if allcraft == 0 { ok = 0 }
147 if alla11y == 0 { ok = 0 }
148 if dsig < 24 { ok = 0 }
149 if dord < 10 { ok = 0 }
150 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
151 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
152 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
153 let ctr__dry: *i64 = gv_ctr()
154 ctr__dry[0] = ok
155 ctr__dry[1] = 1
156 let rc__dry: i64 = gv_verdict("UIGEN-L3-GATE" as *u8, ctr__dry, ": the grammar produced MANY (" as *u8)
157 sys_exit(rc__dry)
158 return rc__dry
159}