nx_imported_body_wasm_gate_t44.nx source
↩ module page · 61 lines · 4613 B
1// Actual compiled plain/shared body API and movement execution through the existing sovereign VM.
2import "nx_wasm_vm.nx"
3import "_hdl_build/nx_wasm_craft_imported_body_t42.nx"
4import "nx_gate_verdict.nx"
5func bv_module(bytes:*u8,n:i64,ctr:*i64)->i64{
6 let mod:*WasmMod=wm_new(bytes,n);let parsed:i64=wm_parse(mod)
7 gv_check("actual compiled body module parses",parsed==0,ctr)
8 if parsed!=0{return 3}
9 let stage:i64=wm_run(mod,"body_stage_off",0,0,0,0,0,0)
10 let read_off:i64=wm_run(mod,"body_read_off",0,0,0,0,0,0)
11 let required_pages:i64=wm_run(mod,"wasm_pages_req",0,0,0,0,0,0)
12 gv_check("compiled exports pin source-owned record and arena bounds",stage==O_IMPORTED_STAGE&&read_off==O_IMPORTED_READ&&required_pages==WASM_PAGES_REQ,ctr)
13 if stage!=O_IMPORTED_STAGE||read_off!=O_IMPORTED_READ||required_pages!=WASM_PAGES_REQ{return 3}
14 // Model the existing page's required-memory growth, retaining the module's initialized bytes.
15 if mod.mem_bytes<required_pages*WASM_PAGE_BYTES{
16 let expanded:*u8=sys_mmap(required_pages*WASM_PAGE_BYTES);var i:i64=0
17 while i<mod.mem_bytes{expanded[i]=mod.mem[i];i=i+1}
18 mod.mem=expanded;mod.mem_bytes=required_pages*WASM_PAGE_BYTES
19 }
20 gv_check("compiled init refuses insufficient available memory",wm_run(mod,"body_init",2,CRAFT_EXT_TOTAL-1,0,0,0,2)==IBR_CAPACITY,ctr)
21 gv_check("compiled init accepts bounded explicit capacity",wm_run(mod,"body_init",2,mod.mem_bytes,0,0,0,2)==0,ctr)
22 let record:*i64=(mod.mem+stage) as *i64
23 record[IBR_ID_HI]=7;record[IBR_ID_LO]=111;record[IBR_REV]=1;record[IBR_SHAPE_REV]=1;record[IBR_POSE_REV]=1
24 record[IBR_WORLD_X]=1000;record[IBR_WORLD_Y]=0;record[IBR_WORLD_Z]=1024
25 record[IBR_MIN_X]=0-100;record[IBR_MIN_Y]=0;record[IBR_MIN_Z]=0-100
26 record[IBR_MAX_X]=100;record[IBR_MAX_Y]=500;record[IBR_MAX_Z]=100
27 record[IBR_LAYER]=4;record[IBR_MASK]=BODY_LAYER_PLAYER|BODY_LAYER_NPC;record[IBR_ENABLED]=1;record[IBR_KIND]=1
28 let handle:i64=wm_run(mod,"body_bind",0,0,0,0,0,0)
29 gv_check("compiled bind retains stable physical handle",handle>0&&wm_run(mod,"body_bind",0,0,0,0,0,0)==handle&&wm_run(mod,"body_count",0,0,0,0,0,0)==1,ctr)
30 gv_check("compiled instance lookup and read exposes geometry revisions",wm_run(mod,"body_handle",7,111,0,0,0,2)==handle&&wm_run(mod,"body_read",handle,0,0,0,0,1)==0,ctr)
31 let exposed:*i64=(mod.mem+read_off) as *i64
32 gv_check("compiled body read preserves authored policy and coordinates",exposed[IBR_SHAPE_REV]==1&&exposed[IBR_WORLD_X]==1000&&exposed[IBR_KIND]==IBR_SHAPE_AABB,ctr)
33 record[IBR_REV]=2;record[IBR_MIN_X]=0-101
34 gv_check("compiled unchanged shape revision refuses changed geometry",wm_run(mod,"body_bind",0,0,0,0,0,0)==IBR_CONFLICT,ctr)
35 record[IBR_REV]=1;record[IBR_MIN_X]=0-100
36 let state:*i64=(mod.mem+O_ST) as *i64;state[S_CX]=0;state[S_CY]=EYE;state[S_CZ]=1024
37 let moved:i64=wm_run(mod,"wc_player_axis_apply",0,0,2000,0,0,4)
38 gv_check("actual compiled player movement stops before imported body",moved==900&&state[S_CX]==900,ctr)
39 let collision:*i64=(mod.mem+O_CONTACT+(2*CONTACT_BOX_WORDS+CONTACT_RESULT_WORDS)*8) as *i64
40 gv_check("compiled player collision audit records blocked axis",collision[1]==1,ctr)
41 let arguments:*i64=sys_mmap(48) as *i64
42 arguments[0]=0;arguments[1]=0;arguments[2]=0;arguments[3]=1024;arguments[4]=0;arguments[5]=2000
43 let fidx:i64=wm_find_export(mod,"wc_body_mob_axis")
44 gv_check("compiled NPC movement helper is callable",fidx>=0,ctr)
45 if fidx>=0{gv_check("actual compiled NPC shape stops before imported body",wm_call(mod,fidx,arguments,6)==900-MOB_R_Q8,ctr)}
46 state[S_CX]=0-4096;state[S_WOX]=16
47 gv_check("compiled origin-relative movement keeps physical body fixed",wm_run(mod,"wc_player_axis_apply",0,0,2000,0,0,4)==900&&state[S_CX]==900-4096,ctr)
48 gv_check("compiled identity survives origin transition",wm_run(mod,"body_handle",7,111,0,0,0,2)==handle,ctr)
49 state[S_CX]=1000-4096
50 gv_check("compiled overlap refuses arbitrary displacement",wm_run(mod,"wc_player_axis_apply",0,0,100,0,0,4)==0&&state[S_CX]==1000-4096,ctr)
51 return 0
52}
53func main()->i64{
54 let ctr:*i64=gv_ctr();gv_head("IMPORTED-BODY-ACTUAL-WASM")
55 let length:*i64=sys_mmap(8) as *i64
56 let plain:*u8=sys_read_file("/tmp/nx_imported_body_t43.wasm",length);let pn:i64=length[0]
57 let shared:*u8=sys_read_file("/tmp/nx_imported_body_shared_t43.wasm",length);let sn:i64=length[0]
58 if (plain as i64)<=0||(shared as i64)<=0{return 3}
59 bv_module(plain,pn,ctr);bv_module(shared,sn,ctr)
60 return gv_verdict("IMPORTED-BODY-ACTUAL-WASM",ctr,"Actual bytecode interpreted; required host memory growth modeled; threaded execution, page wiring, shape/visual coverage and serialization remain unqualified.")
61}