code wiki / _hdl_build / nx_uigen_l3_gate.nx
nx_uigen_l3_gate.nx source
↩ module page · 157 lines · 7818 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"
11
12func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func litlen(lit: *u8) -> i64 { var n: i64=0; while lit[n]!=(0 as u8){n=n+1} return n }
14func idxof(buf: *u8, len: i64, lit: *u8) -> i64 {
15 let ll: i64=litlen(lit)
16 if ll==0 { return 0-1 }
17 var i: i64=0
18 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 }
19 return 0-1
20}
21func countof(buf: *u8, len: i64, lit: *u8) -> i64 {
22 let ll: i64=litlen(lit)
23 if ll==0 { return 0 }
24 var c: i64=0; var i: i64=0
25 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 } }
26 return c
27}
28func csum(p: i64) -> i64 { return (p/65536) + ((p/256)%256) + (p%256) }
29// marker literal for section id (class=-anchored so CSS text never matches)
30func sec_marker(sec: i64) -> *u8 {
31 if sec==0 { return "class=\"grid3\"" as *u8 }
32 if sec==1 { return "class=\"sec splitband\"" as *u8 }
33 if sec==2 { return "class=\"sec stepsband\"" as *u8 }
34 if sec==3 { return "class=\"sec priceband\"" as *u8 }
35 if sec==4 { return "class=\"sec quoteband\"" as *u8 }
36 if sec==5 { return "class=\"sec faqband\"" as *u8 }
37 return "class=\"trust\"" as *u8
38}
39
40func main() -> i64 {
41 let cap: i64 = 524288
42 let buf: *u8 = sys_mmap(cap)
43 let spec: *i64 = sys_mmap(128) as *i64
44 let sigs: *i64 = sys_mmap(512) as *i64
45 let ords: *i64 = sys_mmap(512) as *i64
46 var allvalid: i64 = 1
47 var allcraft: i64 = 1
48 var alla11y: i64 = 1
49
50 gp("=== NX-UIGEN-L3 GATE -- design-grammar at scale: 32 seeds -> 32 designs, EVERY one structurally valid ===\n" as *u8)
51 gp("Validity is checked by an INDEPENDENT byte-parser against the grammar rules, not by the generator.\n\n" as *u8)
52
53 var i: i64 = 0
54 while i < 32 {
55 let seed: i64 = 1000 + i * 77
56 l3_spec_from_seed(spec, seed)
57 let off: i64 = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
58 // ---- independent structural validity on the BYTES ----
59 var valid: i64 = 1
60 if countof(buf, off, "class=\"hero\"" as *u8) != 1 { valid = 0 }
61 if countof(buf, off, "class=\"final\"" as *u8) != 1 { valid = 0 }
62 let hero_at: i64 = idxof(buf, off, "class=\"hero\"" as *u8)
63 let final_at: i64 = idxof(buf, off, "class=\"final\"" as *u8)
64 var present: i64 = 0
65 var s: i64 = 0
66 while s < 7 {
67 let c: i64 = countof(buf, off, sec_marker(s))
68 if c > 1 { valid = 0 }
69 if c == 1 {
70 present = present + 1
71 let at: i64 = idxof(buf, off, sec_marker(s))
72 if at < hero_at { valid = 0 }
73 if at > final_at { valid = 0 }
74 }
75 s = s + 1
76 }
77 if present < 3 { valid = 0 }
78 if present > 5 { valid = 0 }
79 let p_at: i64 = idxof(buf, off, sec_marker(3))
80 let f_at: i64 = idxof(buf, off, sec_marker(5))
81 if p_at >= 0 { if f_at >= 0 { if f_at < p_at { valid = 0 } } }
82 if valid == 0 { allvalid = 0 }
83 // ---- craft markers ----
84 var craft: i64 = 1
85 if countof(buf, off, "var(--nx-" as *u8) == 0 { craft = 0 }
86 if countof(buf, off, "skip-link" as *u8) == 0 { craft = 0 }
87 if countof(buf, off, "@media" as *u8) == 0 { craft = 0 }
88 if countof(buf, off, "clamp(" as *u8) == 0 { craft = 0 }
89 if countof(buf, off, "focus-visible" as *u8) == 0 { craft = 0 }
90 if countof(buf, off, "prefers-reduced-motion" as *u8) == 0 { craft = 0 }
91 if countof(buf, off, "<svg" as *u8) == 0 { craft = 0 }
92 if craft == 0 { allcraft = 0 }
93 // ---- both-theme palette accessibility by construction ----
94 let hue: i64 = spec[0]
95 var acc: i64 = 0
96 let li: i64 = csum(l1_hsl_pack(hue, 25, 12))
97 let lb: i64 = csum(l1_hsl_pack(hue, 22, 97))
98 let di: i64 = csum(l1_hsl_pack(hue, 15, 92))
99 let db: i64 = csum(l1_hsl_pack(hue, 24, 9))
100 if li < 230 { if lb > 660 { if di > 640 { if db < 190 { acc = 1 } } } }
101 if acc == 0 { alla11y = 0 }
102 // ---- design signature (diversity) ----
103 var orderpack: i64 = 0
104 var k: i64 = 0
105 while k < spec[4] { orderpack = orderpack * 8 + (spec[5 + k] + 1); k = k + 1 }
106 sigs[i] = spec[0] + spec[1] * 512 + spec[2] * 2048 + spec[3] * 8192 + orderpack * 32768
107 ords[i] = orderpack
108 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)
109 i = i + 1
110 }
111
112 // distinct signatures + distinct orderings
113 var dsig: i64 = 0
114 var dord: i64 = 0
115 var a: i64 = 0
116 while a < 32 {
117 var seen: i64 = 0
118 var b: i64 = 0
119 while b < a { if sigs[b] == sigs[a] { seen = 1 } b = b + 1 }
120 if seen == 0 { dsig = dsig + 1 }
121 seen = 0
122 b = 0
123 while b < a { if ords[b] == ords[a] { seen = 1 } b = b + 1 }
124 if seen == 0 { dord = dord + 1 }
125 a = a + 1
126 }
127
128 // write 2 samples for the independent judge
129 l3_spec_from_seed(spec, 4242)
130 var soff: i64 = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
131 var fd: i64 = sys_openat_wr("web_assets/uigen_l3_sample_a.html" as *u8, 420)
132 if fd >= 0 { sys_write(fd, buf, soff); sys_close(fd) }
133 gp("\n-- sample A (seed 4242) " as *u8); gn(soff); gp(" bytes -> web_assets/uigen_l3_sample_a.html\n" as *u8)
134 l3_spec_from_seed(spec, 777)
135 soff = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8)
136 fd = sys_openat_wr("web_assets/uigen_l3_sample_b.html" as *u8, 420)
137 if fd >= 0 { sys_write(fd, buf, soff); sys_close(fd) }
138 gp("-- sample B (seed 777) " as *u8); gn(soff); gp(" bytes -> web_assets/uigen_l3_sample_b.html\n" as *u8)
139
140 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)
141 gp(" distinct_signatures=" as *u8); gn(dsig); gp("/32 distinct_orderings=" as *u8); gn(dord); gp("/32\n" as *u8)
142
143 var ok: i64 = 1
144 if allvalid == 0 { ok = 0 }
145 if allcraft == 0 { ok = 0 }
146 if alla11y == 0 { ok = 0 }
147 if dsig < 24 { ok = 0 }
148 if dord < 10 { ok = 0 }
149 if ok == 1 {
150 gp("=== UIGEN-L3 verdict=GREEN: the grammar produced MANY (" as *u8); gn(dsig); gp(" distinct) designs and EVERY one is\n" as *u8)
151 gp("structurally valid, both-theme accessible, S-class. VALIDITY x DIVERSITY at scale = L3, measured.\n" as *u8)
152 sys_exit(0); return 0
153 }
154 gp("=== UIGEN-L3 verdict=RED (validity/craft/a11y/diversity unmet -- see rows)\n" as *u8)
155 sys_exit(1)
156 return 1
157}