nx_imported_body_wasm_gate_t49.nx source
↩ module page · 77 lines · 6881 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_t49.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_kv("actual_stage",stage);gv_kv("expected_stage",O_IMPORTED_STAGE);gv_kv("actual_read",read_off);gv_kv("expected_read",O_IMPORTED_READ);gv_kv("actual_required_pages",required_pages);gv_kv("expected_required_pages",WASM_PAGES_REQ)
13 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)
14 if stage!=O_IMPORTED_STAGE||read_off!=O_IMPORTED_READ||required_pages!=WASM_PAGES_REQ{return 3}
15 // Model the existing page's required-memory growth, retaining the module's initialized bytes.
16 if mod.mem_bytes<required_pages*WASM_PAGE_BYTES{
17 let expanded:*u8=sys_mmap(required_pages*WASM_PAGE_BYTES);var i:i64=0
18 while i<mod.mem_bytes{expanded[i]=mod.mem[i];i=i+1}
19 mod.mem=expanded;mod.mem_bytes=required_pages*WASM_PAGE_BYTES
20 }
21 let affine_at:i64=wm_run(mod,"body_affine_input_off",0,0,0,0,0,0)
22 let affine_out:i64=wm_run(mod,"body_affine_bounds_off",0,0,0,0,0,0)
23 gv_check("compiled static affine ABI owns fixed scratch",affine_at==O_BODY_AFFINE_INPUT&&affine_out==O_BODY_AFFINE_BOUNDS&&wm_run(mod,"body_affine_input_words",0,0,0,0,0,0)==13,ctr)
24 if affine_at!=O_BODY_AFFINE_INPUT||affine_out!=O_BODY_AFFINE_BOUNDS{return 3}
25 let affine_input:*i64=(mod.mem+affine_at) as *i64
26 affine_input[0]=3368583808; affine_input[1]=3369967584; affine_input[2]=3284336640; affine_input[3]=1221100160; affine_input[4]=1197423872; affine_input[5]=1231684256; affine_input[6]=0; affine_input[7]=1065353216; affine_input[8]=925768117; affine_input[9]=1043803405; affine_input[10]=1056964608; affine_input[11]=1111229202; affine_input[12]=1123876864
27 let bounds_rc:i64=wm_run(mod,"body_static_bounds",1,0,0,0,0,1)
28 let actual_bounds:*i64=(mod.mem+affine_out) as *i64
29 gv_check("compiled static transform encloses actual VERT reference",bounds_rc==0&&actual_bounds[0]<=0-68&&actual_bounds[1]<=12032&&actual_bounds[2]<=32356&&actual_bounds[3]>=324&&actual_bounds[4]>=12489&&actual_bounds[5]>=32600,ctr)
30 let unchanged_bound:i64=actual_bounds[0]
31 gv_check("compiled unsupported deformation contract refuses without output mutation",wm_run(mod,"body_static_bounds",2,0,0,0,0,1)==IBR_BAD&&actual_bounds[0]==unchanged_bound,ctr)
32 gv_check("compiled fresh capacity reports zero",wm_run(mod,"body_capacity_current",0,0,0,0,0,0)==0,ctr)
33 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)
34 gv_check("compiled init accepts bounded explicit capacity",wm_run(mod,"body_init",2,mod.mem_bytes,0,0,0,2)==0,ctr)
35 gv_check("compiled existing nondefault capacity is observable",wm_run(mod,"body_capacity_current",0,0,0,0,0,0)==2,ctr)
36 gv_check("compiled explicit incompatible reinit refuses without changing capacity",wm_run(mod,"body_init",3,mod.mem_bytes,0,0,0,2)==IBR_CONFLICT&&wm_run(mod,"body_capacity_current",0,0,0,0,0,0)==2,ctr)
37 let record:*i64=(mod.mem+stage) as *i64
38 record[IBR_ID_HI]=7;record[IBR_ID_LO]=111;record[IBR_REV]=1;record[IBR_SHAPE_REV]=1;record[IBR_POSE_REV]=1
39 record[IBR_WORLD_X]=1000;record[IBR_WORLD_Y]=0;record[IBR_WORLD_Z]=1024
40 record[IBR_MIN_X]=0-100;record[IBR_MIN_Y]=0;record[IBR_MIN_Z]=0-100
41 record[IBR_MAX_X]=100;record[IBR_MAX_Y]=500;record[IBR_MAX_Z]=100
42 record[IBR_LAYER]=4;record[IBR_MASK]=BODY_LAYER_PLAYER|BODY_LAYER_NPC;record[IBR_ENABLED]=1;record[IBR_KIND]=1
43 let handle:i64=wm_run(mod,"body_bind",0,0,0,0,0,0)
44 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)
45 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)
46 let exposed:*i64=(mod.mem+read_off) as *i64
47 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)
48 record[IBR_REV]=2;record[IBR_MIN_X]=0-101
49 gv_check("compiled unchanged shape revision refuses changed geometry",wm_run(mod,"body_bind",0,0,0,0,0,0)==IBR_CONFLICT,ctr)
50 record[IBR_REV]=1;record[IBR_MIN_X]=0-100
51 let state:*i64=(mod.mem+O_ST) as *i64;state[S_CX]=0;state[S_CY]=EYE;state[S_CZ]=1024
52 let moved:i64=wm_run(mod,"wc_player_axis_apply",0,0,2000,0,0,4)
53 gv_check("actual compiled player movement stops before imported body",moved==900&&state[S_CX]==900,ctr)
54 let collision:*i64=(mod.mem+O_CONTACT+(2*CONTACT_BOX_WORDS+CONTACT_RESULT_WORDS)*8) as *i64
55 gv_check("compiled player collision audit records blocked axis",collision[1]==1,ctr)
56 let arguments:*i64=sys_mmap(48) as *i64
57 arguments[0]=0;arguments[1]=0;arguments[2]=0;arguments[3]=1024;arguments[4]=0;arguments[5]=2000
58 let fidx:i64=wm_find_export(mod,"wc_body_mob_axis")
59 gv_check("compiled NPC movement helper is callable",fidx>=0,ctr)
60 if fidx>=0{gv_check("actual compiled NPC shape stops before imported body",wm_call(mod,fidx,arguments,6)==900-MOB_R_Q8,ctr)}
61 if fidx>=0{arguments[1]=1000;arguments[2]=600;arguments[3]=1024;arguments[4]=1;arguments[5]=0-2000;gv_check("compiled NPC downward sweep stops on imported top",wm_call(mod,fidx,arguments,6)==0-100,ctr)}
62 state[S_CX]=0-4096;state[S_WOX]=16
63 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)
64 gv_check("compiled identity survives origin transition",wm_run(mod,"body_handle",7,111,0,0,0,2)==handle,ctr)
65 state[S_CX]=1000-4096
66 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)
67 return 0
68}
69func main()->i64{
70 let ctr:*i64=gv_ctr();gv_head("IMPORTED-BODY-ACTUAL-WASM")
71 let length:*i64=sys_mmap(8) as *i64
72 let plain:*u8=sys_read_file("/tmp/nx_imported_body_static_20260910.wasm",length);let pn:i64=length[0]
73 let shared:*u8=sys_read_file("/tmp/nx_imported_body_static_shared_20260910.wasm",length);let sn:i64=length[0]
74 if (plain as i64)<=0||(shared as i64)<=0{return 3}
75 bv_module(plain,pn,ctr);bv_module(shared,sn,ctr)
76 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.")
77}