code wiki / _hdl_build / nx_css_vars_engine_gate.nx

nx_css_vars_engine_gate.nx source

↩ module page · 116 lines · 6174 B

1// nx_css_vars_engine_gate.nx -- proves the NATIVE render engine (the exact rh_filter_media + _rh_to_fb the 2// Nishi Browser / reader / NishiOS-docview call) resolves fleet var(--token) custom properties, DETERMINISTICALLY 3// (no browser binary, no fixture server, no network -- unlike the flaky shot A/B). A var-less engine leaves 4// "var(--acc)" (color decode fails -> ZERO accent pixels); this gate shows the RESOLVED rgb(41,84,164) reaching 5// both the CSS pipeline AND the framebuffer -> that non-zero IS the measured before/after delta. license_tier: 6// ORIGINAL expect_exit: 0 7import "nx_render_html.nx" 8 9func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func eg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 11func eg_has(buf: *u8, blen: i64, needle: *u8) -> i64 { 12 let nl: i64 = eg_slen(needle) 13 if nl == 0 { return 0 } 14 var i: i64 = 0 15 while i + nl <= blen { 16 var k: i64 = 0 17 var hit: i64 = 1 18 while k < nl { if buf[i + k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } } 19 if hit == 1 { return 1 } 20 i = i + 1 21 } 22 return 0 23} 24func eg_ck(name: *u8, cond: i64, pass: *i64, fail: *i64) -> i64 { 25 if cond == 1 { p(" PASS " as *u8); p(name); p("\n" as *u8); pass[0] = pass[0] + 1; return 1 } 26 p(" FAIL " as *u8); p(name); p("\n" as *u8); fail[0] = fail[0] + 1 27 return 0 28} 29func main() -> i64 { 30 p("=== NX-CSS-VARS ENGINE GATE (native var() through the REAL render pipeline; deterministic delta) ===\n" as *u8) 31 let pass: *i64 = sys_mmap(16) as *i64 32 let fail: *i64 = sys_mmap(16) as *i64 33 pass[0] = 0 34 fail[0] = 0 35 36 // (1) WIRING: rh_filter_media is what nx_browser.nx:282 + nx_browser_render.nx:225 + reader _rh_to_fb:502 37 // all call. Feed it the office-shape token CSS at the browser's 1000px width; assert it RESOLVES. 38 let css: *u8 = ":root{--nx-color-accent:rgb(41,84,164);--acc:var(--nx-color-accent)}h1{background-color:var(--acc)}a{color:var(--acc)}" as *u8 39 let cl: i64 = eg_slen(css) 40 let outc: *u8 = sys_mmap(262144) 41 let m: i64 = rh_filter_media(css, 0, cl, outc, 262144, 1000) 42 var w1: i64 = 0 43 if eg_has(outc, m, "background-color:rgb(41,84,164)" as *u8) == 1 { if eg_has(outc, m, "color:rgb(41,84,164)" as *u8) == 1 { if eg_has(outc, m, "var(" as *u8) == 0 { w1 = 1 } } } 44 eg_ck("ENGINE rh_filter_media resolves office tokens (no var( left) -- the browser's own CSS path" as *u8, w1, pass, fail) 45 46 // (1b) WIRING: clamp() fluid type resolves through the SAME rh_filter_media at the render viewport (1000px). 47 let ccss: *u8 = "body{font-size:clamp(15px,1vw + 12px,17px)}h1{font-size:clamp(20px,2.6vw,26px)}" as *u8 48 let ccl: i64 = eg_slen(ccss) 49 let cout: *u8 = sys_mmap(262144) 50 let cm2: i64 = rh_filter_media(ccss, 0, ccl, cout, 262144, 1000) 51 var w1b: i64 = 0 52 if eg_has(cout, cm2, "font-size:17px" as *u8) == 1 { if eg_has(cout, cm2, "font-size:26px" as *u8) == 1 { if eg_has(cout, cm2, "clamp(" as *u8) == 0 { w1b = 1 } } } 53 eg_ck("ENGINE rh_filter_media resolves clamp() fluid type @1000px (no clamp( left)" as *u8, w1b, pass, fail) 54 55 // (2) RENDER: push a token page through the REAL render core to a framebuffer -> the resolved accent must 56 // reach real pixels. Use a `p` BACKGROUND (a property/element the reader UA sheet does NOT set, so the 57 // author's var() wins cleanly here too -- h1 bg is UA-masked in the reader path, a separate cascade quirk). 58 // A var-less engine leaves "var(--acc)" -> the color decoder fails -> the p box has NO accent fill (0 px). 59 let html: *u8 = "<html><head><style>:root{--acc:rgb(41,84,164)}p{background-color:var(--acc);color:rgb(255,255,255)}</style></head><body><p>accent fill paragraph accent fill paragraph accent fill paragraph accent fill paragraph accent fill</p></body></html>" as *u8 60 let hl: i64 = eg_slen(html) 61 let o3: *i64 = sys_mmap(64) as *i64 62 let fb: *Framebuffer = _rh_to_fb(html, hl, o3) 63 let vw: i64 = o3[0] 64 let boxes: i64 = o3[2] 65 var acc: i64 = 0 66 let px: *CssColor = (sys_mmap(NX_CSS_COLOR_BYTES as nx_size)) as *CssColor 67 var y: i64 = 0 68 while y < 300 { 69 var x: i64 = 0 70 while x < vw { 71 nx_framebuffer_get_pixel(fb, x, y, px) 72 let r: i64 = px.r as i64 73 let g: i64 = px.g as i64 74 let b: i64 = px.b as i64 75 var dr: i64 = r - 41 76 if dr < 0 { dr = 0 - dr } 77 var dg: i64 = g - 84 78 if dg < 0 { dg = 0 - dg } 79 var db: i64 = b - 164 80 if db < 0 { db = 0 - db } 81 if dr <= 12 { if dg <= 12 { if db <= 12 { acc = acc + 1 } } } 82 x = x + 4 83 } 84 y = y + 2 85 } 86 p(" [render] boxes=" as *u8) 87 var bb: i64 = boxes 88 let tb: *u8 = sys_mmap(16) 89 var bk: i64 = 0 90 if bb == 0 { tb[0] = 48 as u8; bk = 1 } 91 while bb > 0 { tb[bk] = (48 + (bb % 10)) as u8; bb = bb / 10; bk = bk + 1 } 92 var bz: i64 = 0 93 while bz < bk { let c1: *u8 = sys_mmap(2); c1[0] = tb[bk - 1 - bz]; sys_write(1, c1, 1); bz = bz + 1 } 94 p(" resolved-accent-pixels=" as *u8) 95 var aa: i64 = acc 96 let ta: *u8 = sys_mmap(16) 97 var ak: i64 = 0 98 if aa == 0 { ta[0] = 48 as u8; ak = 1 } 99 while aa > 0 { ta[ak] = (48 + (aa % 10)) as u8; aa = aa / 10; ak = ak + 1 } 100 var az: i64 = 0 101 while az < ak { let c2: *u8 = sys_mmap(2); c2[0] = ta[ak - 1 - az]; sys_write(1, c2, 1); az = az + 1 } 102 p("\n" as *u8) 103 eg_ck("ENGINE render: resolved rgb(41,84,164) reaches the FRAMEBUFFER (var-less engine = 0)" as *u8, (acc > 0) as i64, pass, fail) 104 105 p("NX-CSS-VARS-ENGINE-GATE pass=" as *u8) 106 var pv: i64 = pass[0] 107 let tp: *u8 = sys_mmap(16) 108 var pk: i64 = 0 109 if pv == 0 { tp[0] = 48 as u8; pk = 1 } 110 while pv > 0 { tp[pk] = (48 + (pv % 10)) as u8; pv = pv / 10; pk = pk + 1 } 111 var pz: i64 = 0 112 while pz < pk { let c3: *u8 = sys_mmap(2); c3[0] = tp[pk - 1 - pz]; sys_write(1, c3, 1); pz = pz + 1 } 113 if fail[0] == 0 { p(" fail=0 verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 114 p(" fail>0 verdict=RED\n" as *u8); sys_exit(1) 115 return 1 116}