code wiki / _hdl_build / nx_modelfacts_gate.nx

nx_modelfacts_gate.nx source

↩ module page · 126 lines · 6197 B

1// nx_modelfacts_gate.nx -- PROVE THE MODEL FACT EXTRACTOR: measured where real, -1 where absent, 2// a binary blob can never wear a triangle count, truncation refuses to undercount. 3// Fixtures are hand-built from the PUBLISHED grammars (GLB header+chunks, STL 84+50n equation, 4// OBJ/PLY line grammar) -- not from our exporters, so a shared misreading cannot self-validate. 5// license_tier: ORIGINAL No hw writes (Rule 26). 6import "nx_syscalls.nx" 7import "nx_gate_verdict.nx" 8import "nx_modelfacts_lib.nx" 9 10func gg_copy(dst: *u8, at: i64, s: *u8) -> i64 { 11 var i: i64 = 0 12 var p: i64 = at 13 while s[i] != (0 as u8) { dst[p] = s[i]; p = p + 1; i = i + 1 } 14 return p 15} 16func gg_u32(dst: *u8, at: i64, v: i64) -> i64 { 17 dst[at] = (v & 0xff) as u8 18 dst[at+1] = ((v >> 8) & 0xff) as u8 19 dst[at+2] = ((v >> 16) & 0xff) as u8 20 dst[at+3] = ((v >> 24) & 0xff) as u8 21 return at + 4 22} 23 24// minimal valid GLB: header + padded JSON chunk + BIN chunk. Returns total length. 25func gg_glb(b: *u8, json: *u8, binlen: i64) -> i64 { 26 var jl: i64 = 0 27 while json[jl] != (0 as u8) { jl = jl + 1 } 28 var jpad: i64 = (jl + 3) / 4 * 4 29 gg_copy(b, 0, "glTF" as *u8) 30 gg_u32(b, 4, 2) 31 gg_u32(b, 12, jpad) 32 gg_copy(b, 16, "JSON" as *u8) 33 var p: i64 = gg_copy(b, 20, json) 34 while p < 20 + jpad { b[p] = 32 as u8; p = p + 1 } 35 gg_u32(b, p, binlen) 36 p = gg_copy(b, p + 4, "BIN" as *u8) 37 b[p] = 0 as u8; p = p + 1 38 var i: i64 = 0 39 while i < binlen { b[p] = 0xaa as u8; p = p + 1; i = i + 1 } 40 gg_u32(b, 8, p) 41 return p 42} 43 44func main(argc: i64, argv: *i64) -> i64 { 45 let ctr: *i64 = gv_ctr() 46 gv_head("nx_modelfacts_gate -- model facts measured from published grammars, never fabricated" as *u8) 47 48 let b: *u8 = sys_mmap(8192) 49 let facts: *i64 = sys_mmap(MDL_N_SLOTS * 8) as *i64 50 51 // T1 plain GLB: 2 accessors, UVs, no skin, no VRM; json/bin byte counts from the chunk headers 52 let j1: *u8 = "{\"accessors\":[{\"componentType\":5126},{\"componentType\":5123}],\"meshes\":[{\"primitives\":[{\"attributes\":{\"POSITION\":0,\"TEXCOORD_0\":1}}]}]}" as *u8 53 let n1: i64 = gg_glb(b, j1, 40) 54 mdl_probe(b, n1, n1, facts) 55 var t1: i64 = 0 56 if facts[0] == MDL_FMT_GLB { if facts[7] == 2 { if facts[4] == 1 { if facts[8] == 0 { if facts[9] == 0 { if facts[6] == 40 { t1 = 1 } } } } } } 57 gv_check("T1 GLB MEASURED: 2 accessors + UV present + skinned=0 + vrm=0 + bin=40B all read from the real chunk structure" as *u8, t1, ctr) 58 59 // T2 the flags' other polarity: a skinned VRM avatar fires both 60 let j2: *u8 = "{\"extensions\":{\"VRMC_vrm\":{}},\"meshes\":[{\"primitives\":[{\"attributes\":{\"POSITION\":0,\"JOINTS_0\":1}}]}]}" as *u8 61 let n2: i64 = gg_glb(b, j2, 4) 62 mdl_probe(b, n2, n2, facts) 63 var t2: i64 = 0 64 if facts[0] == MDL_FMT_GLB { if facts[8] == 1 { if facts[9] == 1 { t2 = 1 } } } 65 gv_check("T2 VRM + SKINNED FLAGS FIRE: VRMC_ extension and JOINTS_0 detected -- and T1 proved they stay silent when absent" as *u8, t2, ctr) 66 67 // T3 binary STL through a TRUNCATED window: 84-byte buffer, declared 12 tris, true size 684 68 var i3: i64 = 0 69 while i3 < 84 { b[i3] = 0 as u8; i3 = i3 + 1 } 70 gg_u32(b, 80, 12) 71 mdl_probe(b, 84, 684, facts) 72 var t3: i64 = 0 73 if facts[0] == MDL_FMT_STL { if facts[1] == 12 { t3 = 1 } } 74 gv_check("T3 BINARY STL WINDOW-SAFE: tris=12 from the header while only 84 of 684 bytes are in the window -- the 84+50n size equation carries the proof" as *u8, t3, ctr) 75 76 // T4 the equation is the wall: same bytes, size off by one -> NOT stl, no count 77 mdl_probe(b, 84, 683, facts) 78 var t4: i64 = 0 79 if facts[0] == MDL_FMT_UNKNOWN { if facts[1] == 0 - 1 { t4 = 1 } } 80 gv_check("T4 A BLOB CANNOT WEAR A TRIANGLE COUNT: size 683 fails 84+50n so the same bytes are refused as STL and no count is fabricated" as *u8, t4, ctr) 81 82 // T5 ascii STL counted by endfacet 83 let s5: *u8 = "solid t\nfacet normal 0 0 1\nendfacet\nfacet normal 0 0 1\nendfacet\nendsolid t\n" as *u8 84 var l5: i64 = 0 85 while s5[l5] != (0 as u8) { l5 = l5 + 1 } 86 mdl_probe(s5, l5, l5, facts) 87 var t5: i64 = 0 88 if facts[0] == MDL_FMT_STL { if facts[1] == 2 { t5 = 1 } } 89 gv_check("T5 ASCII STL: 2 facets counted from the complete text" as *u8, t5, ctr) 90 91 // T6 OBJ line grammar: 3 verts, 1 face, UVs present 92 let s6: *u8 = "# fixture\nv 0 0 0\nv 1 0 0\nv 0 1 0\nvt 0 0\nf 1 2 3\n" as *u8 93 var l6: i64 = 0 94 while s6[l6] != (0 as u8) { l6 = l6 + 1 } 95 mdl_probe(s6, l6, l6, facts) 96 var t6: i64 = 0 97 if facts[0] == MDL_FMT_OBJ { if facts[2] == 3 { if facts[3] == 1 { if facts[4] == 1 { t6 = 1 } } } } 98 gv_check("T6 OBJ MEASURED: v=3 f=1 vt-present from the line grammar" as *u8, t6, ctr) 99 100 // T7 truncation honesty: the SAME obj bytes with a larger true size refuse to count 101 mdl_probe(s6, l6, l6 + 1000, facts) 102 var t7: i64 = 0 103 if facts[0] == MDL_FMT_OBJ { if facts[2] == 0 - 1 { if facts[3] == 0 - 1 { t7 = 1 } } } 104 gv_check("T7 TRUNCATION REFUSES TO UNDERCOUNT: a window smaller than the file keeps text counts at -1 -- a plausible undercount is worse than absence" as *u8, t7, ctr) 105 106 // T8 PLY header declares its counts 107 let s8: *u8 = "ply\nformat ascii 1.0\nelement vertex 8\nproperty float x\nelement face 12\nend_header\n" as *u8 108 var l8: i64 = 0 109 while s8[l8] != (0 as u8) { l8 = l8 + 1 } 110 mdl_probe(s8, l8, l8, facts) 111 var t8: i64 = 0 112 if facts[0] == MDL_FMT_PLY { if facts[2] == 8 { if facts[3] == 12 { t8 = 1 } } } 113 gv_check("T8 PLY MEASURED: element vertex 8 / element face 12 from the header" as *u8, t8, ctr) 114 115 // T9 garbage fabricates nothing 116 var i9: i64 = 0 117 while i9 < 200 { b[i9] = 0x41 as u8; i9 = i9 + 1 } 118 mdl_probe(b, 200, 200, facts) 119 var t9: i64 = 0 120 if facts[0] == MDL_FMT_UNKNOWN { if facts[1] == 0 - 1 { if facts[2] == 0 - 1 { if facts[7] == 0 - 1 { t9 = 1 } } } } 121 gv_check("T9 UNKNOWN FABRICATES NOTHING: garbage yields format=unknown and every slot -1" as *u8, t9, ctr) 122 123 let rc: i64 = gv_verdict("MODELFACTS-GATE", ctr, "published-grammar fixtures, both polarities, size-equation wall, truncation honesty" as *u8) 124 sys_exit(rc) 125 return rc 126}