code wiki / _hdl_build / nx_capsweep_gate.nx

nx_capsweep_gate.nx source

↩ module page · 185 lines · 9074 B

1// nx_capsweep_gate.nx -- teeth over nx_capsweep_lib. IN-PROCESS, with every fixture assembled IN MEMORY. 2// 3// WHY IN-PROCESS AND WHY NO FIXTURE FILES: a gate that forks the deployed elf measures whatever artifact 4// happens to be installed, and a gate that writes scratch under knowledge/store shares its fixture with a 5// production beat -- the estate has measured both defects. Every function under test here is PURE over a 6// caller-supplied buffer, so the fixtures are built in RAM, nothing is written anywhere, and a mutation 7// reaches every rule instead of stopping at a fork boundary. 8// 9// THE TOOTH THAT MATTERS IS T14 and it was named by a sibling seat reviewing this organ: hide a unit that IS 10// on the surface and assert the on-surface count FALLS. Every other tooth here proves the arithmetic is 11// self-consistent, and a partition can reconcile perfectly while the classifier reads the wrong column. 12// ★A RECONCILING PARTITION IS EVIDENCE THE ARITHMETIC IS CONSISTENT, NEVER THAT THE CLASSIFIER IS RIGHT. 13 14import "nx_syscalls.nx" 15import "nx_gate_verdict.nx" 16import "nx_capsweep_lib.nx" 17 18const CG_BUF: i64 = 65536 19const CG_SMALLCAP: i64 = 2 // a deliberately tiny table, so the truncation tooth can actually fill it 20 21func cg_put(b: *u8, at: i64, s: *u8) -> i64 { 22 var p: i64 = at 23 var i: i64 = 0 24 while s[i] != (0 as u8) { b[p] = s[i]; p = p + 1; i = i + 1 } 25 return p 26} 27 28// One execsurface.tsv row: name, six middle fields, first_surface. SEVEN tabs, which is what puts 29// first_surface at column index 7 -- the same arithmetic cs_field_start walks. 30func cg_row(b: *u8, at: i64, name: *u8, surf: *u8) -> i64 { 31 var p: i64 = cg_put(b, at, name) 32 var f: i64 = 0 33 while f < 6 { 34 b[p] = 9 as u8; p = p + 1 35 b[p] = 48 as u8; p = p + 1 36 f = f + 1 37 } 38 b[p] = 9 as u8; p = p + 1 39 p = cg_put(b, p, surf) 40 b[p] = 10 as u8; p = p + 1 41 return p 42} 43 44// Count units whose parsed surface is anything other than NONE. 45func cg_count_on_surface(surf: *i64, n: i64) -> i64 { 46 var c: i64 = 0 47 var i: i64 = 0 48 while i < n { 49 if surf[i] != CS_S_NONE { c = c + 1 } 50 i = i + 1 51 } 52 return c 53} 54 55func main() -> i64 { 56 let ctr: *i64 = gv_ctr() 57 gv_head("NX-CAPSWEEP-GATE -- does the join actually READ the surface, or is it decorative?" as *u8) 58 59 let b: *u8 = sys_mmap(CG_BUF) 60 let names: *u8 = sys_mmap(CS_MAXU * WC_NAMEMAX) 61 let lens: *i64 = sys_mmap(CS_MAXU * 8) as *i64 62 let surf: *i64 = sys_mmap(CS_MAXU * 8) as *i64 63 let tr: *i64 = sys_mmap(16) as *i64 64 65 // ---- field arithmetic ---- 66 var n1: i64 = cg_row(b, 0, "nx_alpha" as *u8, "clock" as *u8) 67 var t1: i64 = 0 68 if cs_field_end(b, 0, n1) == 8 { t1 = 1 } 69 gv_check("T1 FIELD END: the first tab of a row is found at the name boundary, so column 0 is delimited by the separator and not by a hand-counted length" as *u8, t1, ctr) 70 71 var t2: i64 = 0 72 let fs1: i64 = cs_field_start(b, 0, n1, CS_SURF_FIELD) 73 if fs1 < n1 { 74 if b[fs1] == (99 as u8) { t2 = 1 } 75 } 76 gv_check("T2 FIELD START: walking seven separators lands on first_surface, which is the column the whole join depends on -- an off-by-one here would read a boolean as a surface name and still parse" as *u8, t2, ctr) 77 78 // ---- surface classification ---- 79 var t3: i64 = 0 80 let cclock: i64 = cs_surf_code("clock" as *u8, 0, 5) 81 let ccron: i64 = cs_surf_code("cron" as *u8, 0, 4) 82 if cclock == CS_S_CLOCK { 83 if ccron == CS_S_CRON { t3 = 1 } 84 } 85 gv_check("T3 DISCRIMINATION: clock and cron are told APART, and they share a first byte -- a one-byte classifier would map both to the same surface and the census would silently move rows between two live execution planes" as *u8, t3, ctr) 86 87 var t4: i64 = 0 88 if cs_surf_code("-" as *u8, 0, 1) == CS_S_NONE { t4 = 1 } 89 gv_check("T4 DASH IS NONE: the census's own no-surface token maps to NONE" as *u8, t4, ctr) 90 91 var t5: i64 = 0 92 if cs_surf_code("zz" as *u8, 0, 2) == CS_S_UNKNOWN { t5 = 1 } 93 gv_check("T5 THIRD STATE: an unrecognised surface token reads UNKNOWN, never NONE -- folding an unknown into no-surface would report a dark unit the census never claimed was dark" as *u8, t5, ctr) 94 95 // ---- table behaviour ---- 96 tr[0] = 0 97 var c: i64 = 0 98 c = cs_add(names, lens, c, CS_MAXU, "nx_dup" as *u8, 6, tr) 99 c = cs_add(names, lens, c, CS_MAXU, "nx_dup" as *u8, 6, tr) 100 var t6: i64 = 0 101 if c == 1 { t6 = 1 } 102 gv_check("T6 DEDUPE: the same unit added twice is carried once, so a name appearing on two surfaces cannot inflate the population" as *u8, t6, ctr) 103 104 tr[0] = 0 105 var c2: i64 = 0 106 c2 = cs_add(names, lens, c2, CG_SMALLCAP, "nx_a" as *u8, 4, tr) 107 c2 = cs_add(names, lens, c2, CG_SMALLCAP, "nx_b" as *u8, 4, tr) 108 c2 = cs_add(names, lens, c2, CG_SMALLCAP, "nx_c" as *u8, 4, tr) 109 var t7: i64 = 0 110 if c2 == CG_SMALLCAP { 111 if tr[0] == 1 { t7 = 1 } 112 } 113 gv_check("T7 NEG-CONTROL CAP ANNOUNCES: a full table REFUSES the row AND increments trunc, so overflow is announced rather than absorbed -- a cap that fills in silence turns a FLOOR into a published total, which is the defect this whole board exists to expose" as *u8, t7, ctr) 114 115 // ---- parsing a whole fixture ---- 116 tr[0] = 0 117 var p: i64 = 0 118 p = cg_row(b, p, "nx_one" as *u8, "clock" as *u8) 119 p = cg_row(b, p, "nx_two" as *u8, "daemon" as *u8) 120 p = cg_row(b, p, "nx_three" as *u8, "-" as *u8) 121 p = cg_put(b, p, "# asof=1 organs=3 dark=1" as *u8) 122 b[p] = 10 as u8; p = p + 1 123 let parsed: i64 = cs_parse_surface(b, p, names, lens, surf, CS_MAXU, tr) 124 var t8: i64 = 0 125 if parsed == 3 { t8 = 1 } 126 gv_check("T8 PARSE COUNT: three data rows parse to three units" as *u8, t8, ctr) 127 128 var t9: i64 = 0 129 if parsed == 3 { 130 if tr[0] == 0 { t9 = 1 } 131 } 132 gv_check("T9 FOOTER SKIPPED: the comment footer is NOT counted as a unit -- counting it would make the population disagree with the census by exactly one and look like an off-by-one in the census instead of in the reader" as *u8, t9, ctr) 133 134 var t10: i64 = 0 135 if cs_footer_num(b, p, "organs=" as *u8) == 3 { t10 = 1 } 136 gv_check("T10 FOOTER READ: the census's own published total is recovered, which is what makes units-equals-organs a claim by TWO instruments rather than one" as *u8, t10, ctr) 137 138 var t11: i64 = 0 139 if cs_footer_num(b, p, "nosuchkey=" as *u8) == 0 - 1 { t11 = 1 } 140 gv_check("T11 NEG-CONTROL ABSENT FOOTER IS MINUS ONE, NOT ZERO: a missing total must read UNKNOWN, because a zero here would make the cross-check appear to balance against a number nobody published" as *u8, t11, ctr) 141 142 // ---- THE DECORATIVE-JOIN TOOTH ---- 143 let base_on: i64 = cg_count_on_surface(surf, parsed) 144 var t12: i64 = 0 145 if base_on == 2 { t12 = 1 } 146 gv_check("T12 SURFACE COUNTED: of three units, exactly the two carrying a real surface token are counted on-surface" as *u8, t12, ctr) 147 148 tr[0] = 0 149 var q: i64 = 0 150 q = cg_row(b, q, "nx_one" as *u8, "clock" as *u8) 151 q = cg_row(b, q, "nx_two" as *u8, "-" as *u8) 152 q = cg_row(b, q, "nx_three" as *u8, "-" as *u8) 153 q = cg_put(b, q, "# asof=1 organs=3 dark=2" as *u8) 154 b[q] = 10 as u8; q = q + 1 155 let parsed2: i64 = cs_parse_surface(b, q, names, lens, surf, CS_MAXU, tr) 156 let hidden_on: i64 = cg_count_on_surface(surf, parsed2) 157 var t13: i64 = 0 158 if parsed2 == 3 { 159 if hidden_on == 1 { t13 = 1 } 160 } 161 gv_check("T13 NEG-CONTROL DECORATIVE JOIN: hide the surface of a unit that HAD one, keep the population identical at three, and the on-surface count MUST fall from two to one. If it does not fall, the join is not reading the surface column at all and every green partition above it is decoration -- a reconciling partition proves the arithmetic is consistent, never that the classifier is right" as *u8, t13, ctr) 162 163 // ---- the partition predicate ---- 164 var t14: i64 = 0 165 if cs_partition_ok(10, 7, 3) == 1 { t14 = 1 } 166 gv_check("T14 PARTITION SUMS: joined plus residual equal to the population is accepted" as *u8, t14, ctr) 167 168 var t15: i64 = 0 169 if cs_partition_ok(10, 7, 2) == 0 { 170 if cs_partition_ok(10, 0 - 1, 11) == 0 { t15 = 1 } 171 } 172 gv_check("T15 NEG-CONTROL PARTITION REFUSES: parts that do not sum are REJECTED, and so is a negative part -- this is the predicate that stops a unit count being published over a leak, so a version that returned 1 unconditionally would make every count above it unfalsifiable" as *u8, t15, ctr) 173 174 var t16: i64 = 0 175 if cs_stage_bits(1, 1, 1, 1) == 15 { 176 if cs_stage_bits(0, 0, 0, 0) == 0 { 177 if cs_stage_bits(1, 0, 0, 0) == CS_B_SURFACE { t16 = 1 } 178 } 179 } 180 gv_check("T16 STAGE BITS: the lifecycle mask composes and decomposes, so one row carries the whole chain instead of four booleans a reader must recombine" as *u8, t16, ctr) 181 182 let rc: i64 = gv_verdict("CAPSWEEP-GATE" as *u8, ctr, "every conjunct is a NAMED tooth above and this note restates none of them" as *u8) 183 sys_exit(rc) 184 return rc 185}