code wiki / _hdl_build / nx_wasm_vm_gate.nx

nx_wasm_vm_gate.nx source

↩ module page · 54 lines · 3660 B

1// nx_wasm_vm_gate.nx -- R0: the sovereign WASM parser (nx_wasm_vm) parses the REAL shipped nx_vcodec.wasm binary and 2// recovers its structure -- function count, memory, and the named exports the codec.html demo calls. This proves the 3// parser works on the actual artifact before the executor runs it (R1/R2). 4import "nx_syscalls.nx" 5import "nx_gate_emit_lib.nx" 6import "nx_wasm_vm.nx" 7import "nx_gate_verdict.nx" 8 9func main() -> i64 { 10 g_puts("nx_wasm_vm gate R0 (sovereign WASM parser on the REAL nx_vcodec.wasm, MEASURED)\n" as *u8) 11 var pass: i64 = 0; var total: i64 = 0 12 13 let box: *i64 = sys_mmap(16) as *i64 14 let wasm: *u8 = sys_read_file("/mnt/c/Users/elder/nishi-core/nxc2/web_assets/_video_build/nx_vcodec.wasm" as *u8, box) 15 if (wasm as i64) == 0 { g_puts(" FAIL cannot read nx_vcodec.wasm\n" as *u8); g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 } 16 let wlen: i64 = box[0] 17 g_puts(" [measure] wasm bytes=" as *u8); g_pn(wlen); g_puts(" magic ok=" as *u8) 18 var magic_ok: i64 = 0 19 if wasm[0]==(0 as u8) { if wasm[1]==(0x61 as u8) { if wasm[2]==(0x73 as u8) { if wasm[3]==(0x6d as u8) { magic_ok=1 } } } } 20 g_pn(magic_ok); g_puts("\n" as *u8) 21 pass = pass + g_check("valid wasm magic" as *u8, magic_ok); total=total+1 22 23 let mod: *WasmMod = wm_new(wasm, wlen) 24 let rc: i64 = wm_parse(mod) 25 g_puts(" [measure] parse rc=" as *u8); g_pn(rc); g_puts(" types=" as *u8); g_pn(mod.n_types) 26 g_puts(" imports=" as *u8); g_pn(mod.n_imports); g_puts(" funcs=" as *u8); g_pn(mod.n_funcs) 27 g_puts(" exports=" as *u8); g_pn(mod.n_exports); g_puts(" mem=" as *u8); g_pn(mod.mem_bytes); g_puts(" B\n" as *u8) 28 pass = pass + g_check("module parses cleanly (rc=0)" as *u8, rc == 0); total=total+1 29 pass = pass + g_check("recovered a sane function count (> 30)" as *u8, mod.n_funcs > 30); total=total+1 30 pass = pass + g_check("recovered a linear memory" as *u8, mod.mem_bytes > 0); total=total+1 31 32 let e_enc: i64 = wm_find_export(mod, "vc_wasm_encode" as *u8) 33 let e_dec: i64 = wm_find_export(mod, "vc_wasm_decode" as *u8) 34 let e_cur: i64 = wm_find_export(mod, "vc_cur_off" as *u8) 35 let e_str: i64 = wm_find_export(mod, "vc_stream_off" as *u8) 36 let e_bad: i64 = wm_find_export(mod, "does_not_exist" as *u8) 37 g_puts(" [measure] export indices: vc_wasm_encode=" as *u8); g_pn(e_enc); g_puts(" vc_wasm_decode=" as *u8); g_pn(e_dec) 38 g_puts(" vc_cur_off=" as *u8); g_pn(e_cur); g_puts(" vc_stream_off=" as *u8); g_pn(e_str); g_puts(" (missing=" as *u8); g_pn(e_bad); g_puts(")\n" as *u8) 39 pass = pass + g_check("found exported vc_wasm_encode" as *u8, e_enc >= 0); total=total+1 40 pass = pass + g_check("found exported vc_wasm_decode" as *u8, e_dec >= 0); total=total+1 41 pass = pass + g_check("found exported accessors (cur+stream)" as *u8, (e_cur >= 0) & (e_str >= 0)); total=total+1 42 pass = pass + g_check("unknown export correctly not found (-1)" as *u8, e_bad < 0); total=total+1 43 44 g_puts("---- wasm_vm gate R0: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 45 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 46 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 47 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 48 let ctr__dry: *i64 = gv_ctr() 49 ctr__dry[0] = pass 50 ctr__dry[1] = total 51 let rc__dry: i64 = gv_verdict("WASM-VM-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 52 sys_exit(rc__dry) 53 return rc__dry 54}