code wiki / _hdl_build / nx_video_client_wasm_vm_gate.nx

nx_video_client_wasm_vm_gate.nx source

↩ module page · 101 lines · 6061 B

1// nx_video_client_wasm_vm_gate.nx -- SOVEREIGN deploy gate for the rebuilt 2// nx_video_client.wasm (the family-room browser core). The ecosystem's OWN 3// wasm VM (nx_wasm_vm) EXECUTES the freshly-rebuilt wasm and DIFFs it against 4// the native source (nx_video_client_wasm) -- no cmp/xxd/grep, all in-organ. 5// 6// Why this exists: the rebuilt wasm came out ~3KB smaller than the 2-week-old 7// deployed one. Before pushing to the LIVE family room we PROVE the rebuild is 8// (a) parseable, (b) functionally COMPLETE (every export app.js calls is 9// present), and (c) FAITHFUL -- the VM-executed functions match native byte 10// for byte, including vc_ladder_floor (the exported pure neighbor of the 11// governor fix vc_ladder_step, same file + same compile pass) and the 12// byte-memory path vc_wr_u32/vc_rd_u32 (the exact thing a bad wat->wasm 13// lowering would corrupt). If this is GREEN, the smaller size is just a more 14// compact compiler, not missing/!broken logic. expect_exit: 0 license_tier: ORIGINAL 15import "nx_syscalls.nx" 16import "nx_gate_emit_lib.nx" 17import "nx_wasm_vm.nx" 18import "nx_video_client_wasm.nx" 19 20const VCW_PATH: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/web_assets/nx_video_client.staged.wasm" 21const VCW_LOG: *u8 = "knowledge/status/vc_wasm_vm.log" 22 23func fw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 24func main() -> i64 { 25 g_puts("nx_video_client wasm-VM gate (sovereign VM runs the REBUILT wasm, DIFF vs native)\n" as *u8) 26 var pass: i64 = 0; var total: i64 = 0 27 28 let box: *i64 = sys_mmap(16) as *i64 29 let wasm: *u8 = sys_read_file(VCW_PATH, box) 30 if (wasm as i64) == 0 { g_puts(" FAIL cannot read rebuilt wasm\n" as *u8); g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 } 31 g_puts(" rebuilt wasm bytes=" as *u8); g_pn(box[0]); g_puts("\n" as *u8) 32 let mod: *WasmMod = wm_new(wasm, box[0]) 33 var parse_ok: i64 = 0 34 if wm_parse(mod) == 0 { parse_ok = 1 } 35 pass = pass + g_check("rebuilt wasm PARSES under the sovereign VM" as *u8, parse_ok); total = total + 1 36 if parse_ok == 0 { g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 } 37 mod.mem = sys_mmap(mod.mem_bytes) as *u8 38 39 // ---- CHECK: every export app.js calls is PRESENT (functional completeness) ---- 40 var miss: i64 = 0 41 if wm_find_export(mod, "vc_wire_pack" as *u8) < 0 { miss = miss + 1 } 42 if wm_find_export(mod, "vc_wire_parse" as *u8) < 0 { miss = miss + 1 } 43 if wm_find_export(mod, "vc_ladder_floor" as *u8) < 0 { miss = miss + 1 } 44 if wm_find_export(mod, "vc_ladder_step" as *u8) < 0 { miss = miss + 1 } 45 if wm_find_export(mod, "vc_wr_u32" as *u8) < 0 { miss = miss + 1 } 46 if wm_find_export(mod, "vc_rd_u32" as *u8) < 0 { miss = miss + 1 } 47 if wm_find_export(mod, "vc_f32_to_i16" as *u8) < 0 { miss = miss + 1 } 48 if wm_find_export(mod, "vc_i16_to_f32" as *u8) < 0 { miss = miss + 1 } 49 if wm_find_export(mod, "vc_lpc_encode" as *u8) < 0 { miss = miss + 1 } 50 if wm_find_export(mod, "vc_lpc_decode" as *u8) < 0 { miss = miss + 1 } 51 if wm_find_export(mod, "vc_nv1_validate" as *u8) < 0 { miss = miss + 1 } 52 if wm_find_export(mod, "vc_nv1_next" as *u8) < 0 { miss = miss + 1 } 53 if wm_find_export(mod, "vc_nv1_header" as *u8) < 0 { miss = miss + 1 } 54 if wm_find_export(mod, "vc_nv1_chunk" as *u8) < 0 { miss = miss + 1 } 55 if wm_find_export(mod, "vc_nv1_end" as *u8) < 0 { miss = miss + 1 } 56 g_puts(" missing-of-15 app.js exports=" as *u8); g_pn(miss); g_puts("\n" as *u8) 57 pass = pass + g_check("all 15 exports app.js depends on are PRESENT (rebuild is complete)" as *u8, miss == 0); total = total + 1 58 59 // ---- CHECK: vc_ladder_floor VM==native (the governor's exported pure neighbor) ---- 60 var lf_ok: i64 = 1 61 var n: i64 = 1 62 while n <= 8 { 63 let vm: i64 = wm_run(mod, "vc_ladder_floor" as *u8, n, 0,0,0,0, 1) 64 let nat: i64 = vc_ladder_floor(n) 65 if vm != nat { lf_ok = 0 } 66 n = n + 1 67 } 68 pass = pass + g_check("vc_ladder_floor VM==native for n_peers 1..8 (compiler faithful on this file)" as *u8, lf_ok); total = total + 1 69 70 // ---- CHECK: byte-memory path vc_wr_u32/vc_rd_u32 VM==native (what a bad lowering corrupts) ---- 71 let V: i64 = 305419896 // 0x12345678 72 let OFF: i64 = 256 // free scratch in the module's linear memory 73 wm_run(mod, "vc_wr_u32" as *u8, OFF, 0, V, 0,0, 3) // write V at mem[OFF] via the VM 74 let rd: i64 = wm_run(mod, "vc_rd_u32" as *u8, OFF, 0, 0,0,0, 2) 75 // independent native LE bytes for the same value 76 let natbuf: *u8 = sys_mmap(16) 77 vc_wr_u32(natbuf, 0, V) 78 var bytes_ok: i64 = 1 79 var bi: i64 = 0 80 while bi < 4 { if mod.mem[OFF + bi] != natbuf[bi] { bytes_ok = 0 } bi = bi + 1 } 81 var mem_ok: i64 = 0 82 if rd == V { if bytes_ok == 1 { mem_ok = 1 } } 83 g_puts(" vc_rd_u32 via VM=" as *u8); g_pn(rd); g_puts(" (expect 305419896) LE-bytes-match-native=" as *u8); g_pn(bytes_ok); g_puts("\n" as *u8) 84 pass = pass + g_check("vc_wr_u32/vc_rd_u32 byte-memory round-trips VM==native (LE bytes exact)" as *u8, mem_ok); total = total + 1 85 86 g_puts("---- vc wasm-VM gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 87 if pass == total { 88 let lfd: i64 = sys_openat_append(VCW_LOG, 0x1a4) 89 if lfd >= 0 { 90 fw(lfd, "VC-WASM-VM organ=nx_video_client_wasm checks=" as *u8); fw(lfd, "4/4 wasm-bytes=" as *u8) 91 // (numeric byte-count omitted from log line keep it simple) 92 fw(lfd, "parse+exports15+ladder_floor+wr/rd_u32 VM==native verdict=GREEN\n" as *u8) 93 sys_close(lfd) 94 } 95 g_puts("verdict=GREEN -- rebuilt wasm is complete + faithful (safe to deploy)\n" as *u8) 96 sys_exit(0); return 0 97 } 98 let rfd: i64 = sys_openat_append(VCW_LOG, 0x1a4) 99 if rfd >= 0 { fw(rfd, "VC-WASM-VM verdict=RED\n" as *u8); sys_close(rfd) } 100 g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 101}