code wiki / _hdl_build / nx_editor_loop_gate.nx

nx_editor_loop_gate.nx source

↩ module page · 63 lines · 3264 B

1// nx_editor_loop_gate.nx -- the no-JS edit loop end-to-end: emit a native form (0 JS), POST an op, the engine applies 2// it, the re-render REFLECTS the change. Unknown ops rejected. Proves the ecosystem can MANAGE a layout with no JS. 3// 100% sovereign. expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_sitegate_emit_lib.nx" 6import "nx_editor_loop.nx" 7import "nx_brand_tokens.nx" 8 9 10func g_has(s: *u8, n: i64, lit: *u8) -> i64 { if bt_find(s, n, lit, bt_len(lit)) >= 0 { return 1 } return 0 } 11func put(c: *i64, i: i64, k: i64, x: i64, y: i64, w: i64, h: i64) -> i64 { c[i*5+0]=k; c[i*5+1]=x; c[i*5+2]=y; c[i*5+3]=w; c[i*5+4]=h; return 0 } 12func render_to(c: *i64, n: i64, path: *u8, out: *u8, cap: i64) -> i64 { 13 let fd: i64 = sys_openat_wr(path, 0x1a4); el_emit_form(c, n, fd); sys_close(fd) 14 let lp: *i64 = sys_mmap(16) as *i64; let pg: *u8 = sys_read_file(path, lp); let pn: i64 = lp[0] 15 var i: i64 = 0; while i < pn { if i < cap { out[i] = pg[i] } i = i + 1 } 16 return pn 17} 18 19func main() -> i64 { 20 let tot: *i64 = sys_mmap(32) as *i64 21 tot[0]=0; tot[1]=0 22 let c: *i64 = sys_mmap(512) as *i64 23 let out: *u8 = sys_mmap(8192) 24 gw("=== nx_editor_loop_gate -- NO-JS edit loop (emit form -> POST op -> apply -> re-render) ===\n" as *u8) 25 26 // L1: emit the native ops form (no JS) 27 put(c, 0, 1, 10, 0, 50, 20); put(c, 1, 3, 40, 0, 50, 20); put(c, 2, 2, 70, 0, 50, 20) 28 var pn: i64 = render_to(c, 3, "/tmp/nx_editor_loop.html" as *u8, out, 8192) 29 var l1: i64 = 0 30 if g_has(out, pn, "<form method=\"post\"" as *u8) == 1 { if g_has(out, pn, "value=\"snap\"" as *u8) == 1 { if g_has(out, pn, "<script" as *u8) == 0 { l1 = 1 } } } 31 t_row("L1 native HTML ops form emitted, ZERO JavaScript" as *u8, l1, tot) 32 33 // L2: POST 'align-left' -> engine applies -> all x equal 34 let r2: i64 = el_apply(c, 3, "align-left" as *u8) 35 var l2: i64 = 0 36 if r2==1 { if c[1]==10 { if c[6]==10 { if c[11]==10 { l2 = 1 } } } } 37 t_row("L2 POST op 'align-left' applied by the engine (x -> all 10)" as *u8, l2, tot) 38 39 // L3: the re-render REFLECTS the applied op (left:40px gone, left:10px present) 40 pn = render_to(c, 3, "/tmp/nx_editor_loop2.html" as *u8, out, 8192) 41 var l3: i64 = 0 42 if g_has(out, pn, "left:10px" as *u8) == 1 { if g_has(out, pn, "left:40px" as *u8) == 0 { l3 = 1 } } 43 t_row("L3 re-render reflects the edit (the loop closes, no JS)" as *u8, l3, tot) 44 45 // L4: 'snap' op 46 put(c, 0, 1, 37, 11, 63, 20) 47 let r4: i64 = el_apply(c, 1, "snap" as *u8) 48 var l4: i64 = 0 49 if r4==1 { if c[1]==40 { if c[2]==8 { l4 = 1 } } } 50 t_row("L4 POST op 'snap' applied (37,11)->(40,8)" as *u8, l4, tot) 51 52 // L5: unknown op rejected (governed -- only known ops apply) 53 put(c, 0, 1, 99, 99, 10, 10) 54 let r5: i64 = el_apply(c, 1, "rm -rf; drop table" as *u8) 55 var l5: i64 = 0 56 if r5==0 { if c[1]==99 { l5 = 1 } } 57 t_row("L5 unknown op REJECTED (no-op; only governed ops apply)" as *u8, l5, tot) 58 59 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8) 60 if tot[1] == 0 { gw("VERDICT=GREEN -- the Nishi ecosystem MANAGES a layout with NO JavaScript (form->op->apply->re-render, governed).\n" as *u8); return 0 } 61 gw("VERDICT=RED\n" as *u8) 62 return 1 63}