nx_mesh_christus_probe.nx source
↩ module page · 43 lines · 2023 B
1// nx_mesh_christus_probe.nx -- minimal repro for the christus exit=11 (mesh.n_tris != 4).
2// Allocs a 4-tri mesh exactly as build_christus_cone does, then exits with n_tris so the exit
3// code IS the value under test: exit 4 = mesh field read is correct (bug is elsewhere in the
4// integration test); exit != 4 = nx_mesh_alloc / struct-field codegen is the culprit. NO sh, NO gcc.
5import "nx_tier.nx" // defines `type nx_int = i64` -- without it nx_int may resolve to TY_VOID size 0
6import "nx_syscalls.nx"
7import "nx_mesh.nx"
8
9func pw(label: *u8, v: i64) -> i64 {
10 sys_write(1, label, 6)
11 let t: *u8 = sys_mmap(28); var m: i64=v; var neg: i64=0; if m<0{neg=1;m=0-m}
12 let bb: *u8 = sys_mmap(28); var k: i64=0; if m==0{bb[0]=48;k=1}; while m>0{bb[k]=(48+(m%10)) as u8;m=m/10;k=k+1}
13 if neg==1{sys_write(1,"-" as *u8,1)}
14 var i: i64=0; while i<k{t[i]=bb[k-1-i];i=i+1}; sys_write(1,t,k); sys_write(1,"\n" as *u8,1); return 0
15}
16func main() -> i64 {
17 let m: *NxMesh = nx_mesh_alloc(4, 4, 0)
18 if (m as i64) == 0 { return 99 }
19 // dump raw struct words 0..5 to see WHERE alloc's 4s landed (true field offsets nx_cc used)
20 let p: *i64 = m as *i64
21 pw("raw[0]" as *u8, p[0])
22 pw("raw[1]" as *u8, p[1])
23 pw("raw[2]" as *u8, p[2])
24 pw("raw[5]" as *u8, p[5])
25 pw("fld.nv" as *u8, m.n_verts)
26 pw("fld.nt" as *u8, m.n_tris)
27 nx_mesh_set_vertex(m, 0, 0, 0, 0, 0)
28 nx_mesh_set_vertex(m, 1, 10, 0, 0, 0)
29 nx_mesh_set_vertex(m, 2, 5, 9, 0, 0)
30 nx_mesh_set_vertex(m, 3, 5, 3, 40, 0)
31 nx_mesh_set_triangle(m, 0, 0, 2, 1)
32 nx_mesh_set_triangle(m, 1, 0, 1, 3)
33 nx_mesh_set_triangle(m, 2, 1, 2, 3)
34 nx_mesh_set_triangle(m, 3, 2, 0, 3)
35 let nt: i64 = m.n_tris
36 let nv: i64 = m.n_verts
37 sys_write(1, "probe n_verts=" as *u8, 14);
38 let a: *u8 = sys_mmap(8); a[0] = (48 + nv) as u8; sys_write(1, a, 1)
39 sys_write(1, " n_tris=" as *u8, 8)
40 let b: *u8 = sys_mmap(8); b[0] = (48 + nt) as u8; sys_write(1, b, 1)
41 sys_write(1, "\n" as *u8, 1)
42 return nt
43}