code wiki / _hdl_build / nx_brand_typescale_gate.nx
nx_brand_typescale_gate.nx source
↩ module page · 65 lines · 3209 B
1// nx_brand_typescale_gate.nx -- R9 gate: the modular type-scale generator. A base+ratio yields a monotonic-
2// descending heading scale (no-float) that lands in the R2 type-scale band BY CONSTRUCTION and feeds the token
3// SSOT. 100% sovereign. expect_exit: 0
4import "nx_syscalls.nx"
5import "nx_sitegate_emit_lib.nx"
6import "nx_brand_typescale.nx"
7import "nx_brand_guard.nx"
8import "nx_brand_tokens.nx"
9
10
11func g_has(s: *u8, n: i64, lit: *u8) -> i64 { if bt_find(s, n, lit, bt_len(lit)) >= 0 { return 1 } return 0 }
12func inband9(v: i64, lo: i64, hi: i64) -> i64 { if v < lo { return 0 } if v > hi { return 0 } return 1 }
13
14func main() -> i64 {
15 let tot: *i64 = sys_mmap(32) as *i64
16 tot[0]=0; tot[1]=0
17 let cap: i64 = 4096
18 let a: *u8 = sys_mmap(cap)
19 gw("=== nx_brand_typescale_gate -- R9 modular type-scale generator (base + ratio -> font tokens) ===\n" as *u8)
20
21 // T1: base 1rem, ratio 5/4 (major third) -> h1=2.441 h2=1.562 h3=1.250 rem
22 let w1: i64 = ts_emit_scale(1000, 5, 4, a, cap)
23 gw(" scale(1rem, 5/4): " as *u8); sys_write(1, a, w1)
24 var t1: i64 = 0
25 if g_has(a, w1, "token|font|h1|2.441rem" as *u8) == 1 { if g_has(a, w1, "token|font|h2|1.562rem" as *u8) == 1 { if g_has(a, w1, "token|font|h3|1.250rem" as *u8) == 1 { t1 = 1 } } }
26 t_row("T1 ratio 5/4 -> h1=2.441 h2=1.562 h3=1.250 rem (correct modular steps)" as *u8, t1, tot)
27
28 // T2: monotonic descending
29 let s1: i64 = ts_size_milli(1000, 5, 4, 4)
30 let s2: i64 = ts_size_milli(1000, 5, 4, 2)
31 let s3: i64 = ts_size_milli(1000, 5, 4, 1)
32 var t2: i64 = 0
33 if s1 > s2 { if s2 > s3 { if s3 > 1000 { t2 = 1 } } }
34 t_row("T2 scale is monotonic descending (h1 > h2 > h3 > base)" as *u8, t2, tot)
35
36 // T3: the generated scale satisfies the R2 type-scale check BY CONSTRUCTION
37 let ok3: i64 = bg_type_scale_ok(a, w1)
38 t_row("T3 generated scale passes the R2 type-scale guard (h1>h2 in band)" as *u8, inband9(ok3, 1, 1), tot)
39
40 // T4: a louder ratio 3/2 (perfect fifth) -> a bigger h1
41 let b: *u8 = sys_mmap(cap)
42 let w4: i64 = ts_emit_scale(1000, 3, 2, b, cap)
43 var t4: i64 = 0
44 if g_has(b, w4, "token|font|h1|5.062rem" as *u8) == 1 { t4 = 1 }
45 t_row("T4 ratio 3/2 -> a different, louder scale (h1=5.062rem)" as *u8, t4, tot)
46
47 // T5: determinism
48 let c: *u8 = sys_mmap(cap)
49 let w5: i64 = ts_emit_scale(1000, 5, 4, c, cap)
50 var t5: i64 = 0
51 if w5 == w1 { var eq: i64 = 1; var i: i64 = 0; while i < w1 { if a[i] != c[i] { eq = 0 } i = i + 1 } t5 = eq }
52 t_row("T5 determinism: same base+ratio -> byte-identical scale" as *u8, t5, tot)
53
54 // T6: the scale feeds the token SSOT -> :root --nx-font-h1
55 let root: *u8 = sys_mmap(cap)
56 let wr: i64 = bt_emit_root_buf(a, w1, root, cap)
57 var t6: i64 = 0
58 if wr > 0 { if g_has(root, wr, "--nx-font-h1: 2.441rem" as *u8) == 1 { t6 = 1 } }
59 t_row("T6 scale feeds the token SSOT (:root --nx-font-h1: 2.441rem)" as *u8, t6, tot)
60
61 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8)
62 if tot[1] == 0 { gw("VERDICT=GREEN -- modular type-scale generated no-float, in-band, feeds the SSOT\n" as *u8); return 0 }
63 gw("VERDICT=RED\n" as *u8)
64 return 1
65}