Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/ng/gate-ir.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / ng / gate-ir.om` 3610 lines · 70680 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/ng/gate-ir.om: the M0 gate of the ΩIR spec and its tools (seed/ng/IR.md). Owner: ng-ir lane. 3 note Build: cat seed/ng/sha256.om seed/ng/gate-ir.om | seed/out/omc > gate-ir 4 note Run from the repository root: gate-ir OMC SCRATCH (SCRATCH is created if absent) 5 note or one part: gate-ir OMC SCRATCH N/K, or the partition proof: gate-ir OMC SCRATCH parts K N1 N2 ... 6 note (PART; see the PART notes before main) 7 note 1. builds ngbuild, ngcheck, ngas, ngdis, ngrun and ngrand with OMC, then ng through `ngbuild build` 8 note (pins of ng.units) 9 note 2. `ngcheck --table` must equal seed/ng/hostwords.tsv byte for byte 10 note 3. ngbuild refuses a units file with a wrong pin (exit 3, the exact mismatch line) before compiling 11 note 4. every line of seed/ng/tests/ir/cases (format in that file): text round trip ngdis(ngas(t)) == t, 12 note ngcheck's whole witness line (ACCEPT, sha256 of the binary by sha256.om, fns/blocks/ops counted 13 note from the fixture text) or whole refusal line with empty stdout, ng ir-copy on every unit (IR.md 14 note s14), ngas syntax and limit refusals, byte mutants judged by ngcheck, ngdis and ng, an unreadable 15 note stdin, generated inputs at the capacities (`16777216` bytes and one more, 65537 table entries), and 16 note run pairs (D9 differential): NAME.oir, which ngcheck must accept, run by ngrun, against NAME.om 17 note compiled by OMC; exit status, stdout and stderr must be equal; random programs of ngrand (seeds 18 note 1..N): ngcheck's whole ACCEPT line, ngas(ngdis(b)) == b, ngrand deterministic, ngrun ends cleanly 19 note (exit 0..63 with 0 or 8 stdout bytes, 64..95 by exit or 101..114 by a trap, stderr empty); and the 20 note shrink step (ngrand shrink with ngrun as the predicate: accepted, still interesting, smaller, its 21 note tape replays it); ngrun alone on units with no omc counterpart (N: exit, empty stdout, the 22 note step-limit or outside-storage line); and the optimizer (O and L cases, and every Q seed): `@ng opt` exits 0 with 23 note empty stderr, ngcheck's whole ACCEPT line on its output, ngas(ngdis(out)) == out, ngrun before 24 note and after equal (exit status, stdout, and stderr; for L kernels only, one decimal line on each side 25 note is the elapsed-time clock and counts as equal), and `@ng opt-count` of the output reports nothing left 26 note to move (a fixed point); each O or L case prints the row "ok O NAME fns=.. loops=.. inloop=A->B 27 note ..." of `@ng opt-count` on its input (A, B: ops in loop blocks before and after), which must equal 28 note the row written on its case line when there is one ("opt counts differ" otherwise) 29 note 5. negative controls of the gate itself: a wrong exit, a wrong offset and a wrong round-trip text 30 note must each trip their named check ("FAIL negative control N" otherwise). 31 note 6. three tool mutants of ngcheck (gt_msel: load/store typing away, witness prefix, class name), one 32 note of ngrun (chk.fuel one pass late), eight more of ngrun (q_np: rem MIN/-1, u64 chk.add and chk.mul, 33 note chk.shl negative side, signed conv lower bound, chk.bounds e = 0, narrow neg, depth cap), one more of 34 note ngrun (step limit one op late, bay 8 review of `39f04efc`) and one of ngrand (a random check's token edge dropped) must 35 note each fail their named check at least once ("ok mutant ...: killed by=K" counts those failures; 36 note "FAIL mutant ...: named failure never fired" otherwise). Five mutants of opt.om: a load hoisted 37 note past the loop's stores, checks (and other effects) hoisted past their guards, preheader merging 38 note that ignores imm, BCE one past its proof, and LICM moving shfl; the first two must be refused by 39 note ngcheck on the output, the next two must change a run, the last must change o-shfl's pinned row. Under a mutant, Q runs at most 100 seeds and L cases are skipped. A mutant whose 40 note pattern does not occur exactly once fails "pattern not unique". 41 note Seven float mutants of ngrun (20..26, see q_fp/q_fr) must each make the float or intcv oracle or a case 42 note fail its run check. 43 note Output: one line per failure, then "NGIRGATE PASS cases=N" (exit 0) or "NGIRGATE FAIL failed=K 44 note cases=N" (exit 1); usage or scratch failure exit 2, a tool that does not build exit 3. 45 note Globals q_*, functions gt_*; sha256.om supplies sh_dat, sh_all, sh_dig. 46 text q_w "seed/ng/ ngbuild ngcheck ngas ngdis ng sha256.om ngbuild.om ngcheck.om ngtxt.om ngas.om ngdis.om ng.units hostwords.tsv tests/ir/ cases .oir build --table src.om out err in bin txt tests/ir unit bad.units nope must src/ir.om ngrun ngrun.om .om ref rout rerr ngrand ngrand.om rbin rtxt rbin2 kbin shrink kbin.tape tape tests/opt/ obin otxt obin2 ocnt src/opt.om src/main.om oin tests/ir/float-oracle.om foracle foracle.ir tests/ir/intcv-oracle.om intcv intcv.ir tests/ir/host-audit.om host-audit tests/ir/host-oracle.om host-oracle host.ir tests/ir/host-refusals.om host-refusals policy.ir host-root- child ../omc/omc.om " 47 text q_m "FAIL |build|table|case|: ngas exit|: ngdis exit|: round trip text differs|: ngcheck exit|: offset|: ACCEPT digest|: ir-copy exit|: ir-copy bytes differ|: ngas syntax line|: malformed case|negative control |NGIRGATE PASS cases=|NGIRGATE FAIL failed=| cases=|usage: gate-ir OMC SCRATCH|scratch unusable|: ngdis exit|: unreadable fixture|mutant ngcheck: |survived every case|not built|killed by=|ok |ngcheck: |ngdis: refused class |ng: refused class |ngas: syntax error at line |ngas: limit at line | at |ACCEPT | fns=| blocks=| ops=|: witness line differs|: refusal line differs|: refusal wrote stdout|: ng exit|bad pin: |not refused before compiling, exit|mutant ngcheck ACCEPT prefix: |mutant ngcheck class name: |: unknown generator|ngbuild: sha256 mismatch seed/ng/src/ir.om have |named failure never fired, other failures=|fn |export |kernel |block |end|omegair 1\n|type %t| = array u8 |type %t32 = array u8 1\n|global @g| %t32 zero\n|fn @f| flags 0 -> void\nblock ^0\nret %0\nend\n|fn @f0 flags 0 -> void\nblock ^0\n|ret %0\n|block ^| %|:tok\nret %|fn @f0 flags 0|:u32| -> void\nblock ^0\nret %0\nend\n|br ^1 %0\nblock ^1 %1:tok|\nret %1\nend\n|end\n|full|over|types|ty65536|ty65537|gl65537|fn65537|bl65537|fp65537|bp65537|: generated input differs|OSC1IR|omega.ng.ir.v1|: named check never fired|mutant ngrun: |: run exits differ, ngrun |, reference |: run stdout differs|: run stderr differs|: reference build|ngrun: refused class |: ngrand failed at seed|: random unit refused at seed|: random unit refused TOKEN at seed|: random round trip differs at seed|: random run did not end cleanly at seed|: ngrand not deterministic|: shrink exit|: shrunk unit not smaller|: shrunk run exit|mutant ngrand token edge: |ok random seeds=| normal=| exit=| trap=|: shrunk tape does not replay|pattern not unique, matches=|: opt exit|: opt output refused|: opt round trip differs|: opt run differs|: opt not at a fixed point| at seed |mutant opt load hoisted: |mutant opt check hoisted: |mutant opt merge ignores imm: |: ngrun exit|: ngrun stdout not empty|: ngrun stderr line differs|ngrun: step limit at |ngrun: access outside storage at |mutant ngrun rem MIN/-1: |mutant ngrun u64 chk.add: |mutant ngrun u64 chk.mul: |mutant ngrun chk.shl low side: |mutant ngrun conv low bound: |mutant ngrun chk.bounds e=0: |mutant ngrun narrow neg: |mutant ngrun depth cap: |mutant opt bce bound: |: opt counts differ, got |mutant ngrun step budget: |mutant opt convergent: |mutant ngrun float bitcast: |mutant ngrun float RTZ: |mutant ngrun f32 FMA: |mutant ngrun f64 FMA: |mutant ngrun unsigned signed conv: |mutant ngrun f32 widened FMA: |mutant ngrun f32 RTZ predecessor: |mutant ngrun path refusal class: |mutant ngrun min/max one quiet NaN: |mutant ngrun min/max signaling NaN: |mutant ngrun min/max two NaNs: |mutant ngrun min signed zero: |mutant ngrun pool stored byte: |mutant ngrun pool zero tail: |mutant ngrun pool moved base: |" 48 note the ngrun float mutants 20..26 (main's 15..21, numbered after the opt mutants since ham/ng-opt-phi-2 merged 49 note main `82e536e1`; q_fp/q_fr patterns, lengths may differ; each also runs the native float or intcv oracle): 50 note 20 float bitcast sign erased, 21 RTZ refused, 22 f32 FMA unfused, 23 f64 FMA unfused, 24 unsigned-to-signed 51 note check only at 64 bits, 25 f32 FMA widened to f64 then narrowed (double rounding; bay 7 review of `26f67fbb`, 52 note killed by the float oracle's Wolfram-checked witness); 26 removes the f64-to-f32 RTZ predecessor correction, 53 note judged against an independent integer decoder. Their messages are q_m 135..141 (gt_mlab). 54 text q_fp4 "if rn_sg t\nret ge v shl ulong 1 sub w 1\n" 55 text q_fr4 "if and rn_sg t eq w 64\nret ge v shl ulong 1 sub w 1\n" 56 text q_fp0 "if rn_isf t\nrn_r o rn_cn t a\n" 57 text q_fr0 "if rn_isf t\nrn_r o and a sub shl ulong 1 sub rn_w t 1 1\n" 58 text q_fp1 "im = get i_oim o\nif and rn_isi t rn_isi s\n" 59 text q_fr1 "im = get i_oim o\nif and rn_isf t eq and im 3 1\nrn_uns o\nend\nif and rn_isi t rn_isi s\n" 60 text q_fp2 "ret ulong bitcast uint fma x y z\n" 61 text q_fr2 "ret ulong bitcast uint add mul x y z\n" 62 text q_fp3 "ret bitcast ulong fma x y z\n" 63 text q_fr3 "ret bitcast ulong add mul x y z\n" 64 text q_fr5 "ret ulong bitcast uint f32 fma f64 x f64 y f64 z\n" 65 text q_fp6 "bits = sub ulong bitcast uint y 1\n" 66 text q_fr6 "bits = add ulong bitcast uint y 0\n" 67 note host and min/max mutants 27..31 (22..26 on `b203fc8c`; renumbered after main's float mutants 20..26): 27 an absolute path refused with the wrong class (host policy 68 note controls), 28..31 the min/max rules of IR.md s7.3 (one quiet NaN, signaling NaN, two NaNs, 69 note signed zero), judged by the native float oracle 70 text q_fp7 "if or eq c 0 eq c 47\nrn_href o 119\n" 71 text q_fr7 "if or eq c 0 eq c 47\nrn_href o 120\n" 72 text q_fp8 "if na\nret b\n" 73 text q_fr8 "if na\nret a\n" 74 text q_fp9 "if sa\nret or a q\n" 75 text q_fr9 "if sa\nret b\n" 76 text q_fp10 "if and na nb\nret or a q\n" 77 text q_fr10 "if and na nb\nret xor a q\n" 78 text q_fp11 "ret b\nend\nret or a b\nend\nif gt x y\n" 79 text q_fr11 "ret b\nend\nret and a b\nend\nif gt x y\n" 80 text q_fp12 "put r_pm add p j uchar and shr v mul j 8 255\n" 81 text q_fr12 "put r_pm add p j uchar and shr v mul j 8 254\n" 82 text q_fp13 "put r_pm add cut j 0\n" 83 text q_fr13 "put r_pm add cut j 1\n" 84 text q_fp14 "put r_pb h add get r_pb h delta\n" 85 text q_fr14 "put r_pb h sub get r_pb h delta\n" 86 87 global q_hs ulong 4 88 global q_hroot uchar 16384 89 global q_hrlen ulong 2 90 global q_hmade uchar 2 91 global q_henv uchar 64 92 text q_hent "NG_ORACLE=present" 93 text q_hopt "--scratch" 94 text q_hdash "--" 95 text q_hatab "HOSTTABLE rows=99 differences=0\n" 96 text q_hstat "HC_NATIVE operations=" 97 text q_hmsg "ngrun: refused host class " 98 text q_hword " word " 99 text q_hat " at " 100 text q_hpol "ok host policy controls=" 101 note the tool mutants of ngcheck (each pattern occurs once; the replacement has its length): 102 note 1 load and store typing dispatched away, 2 the witness prints " ops=" for "ACCEPT ", 103 note 3 a refusal names the class after the right one 104 text q_mu0 "\nif or eq op 42 eq op 43\n" 105 text q_mu1 "\nif or eq op 99 eq op 99\n" 106 text q_mp0 "\nck_txt 3 1\n" 107 text q_mp1 "\nck_txt 6 1\n" 108 text q_mc0 "\nck_cname sub c 9\n" 109 text q_mc1 "\nck_cname sub c 8\n" 110 note the ngrun mutant (id 4): chk.fuel fails one pass late 111 text q_mu2 "\nif eq op 81\nret ge a b\n" 112 text q_mu3 "\nif eq op 81\nret gt a b\n" 113 note the ngrand mutant (id 5): the new token of a random statement's check is not made current, so the 114 note next effect or terminator consumes a used token (ngcheck must refuse TOKEN) 115 text q_mr0 "\nput y_h 1 ir_otok q\n" 116 text q_mr1 "\nput y_h 9 ir_otok q\n" 117 note the opt.om mutants: 6 loads (class R) may leave a loop, so a load moves above the loop's stores with 118 note its in-loop token; 7 every op but a terminator may leave, results or not, so a check moves above 119 note the guard of its loop with its in-loop token; 8 two preheader ops of different imm count as equal 120 text q_mx0 "\nif ne get i_rtk op 0\nret false\n" 121 text q_mx1 "\nif eq get i_rtk op 1\nret false\n" 122 text q_mk0 "\nif ne get i_rtk op 0\nret false\nend\nif eq get i_ors o 0\n" 123 text q_mk1 "\nif eq get i_rtk op 3\nret false\nend\nif lt get i_ors o 0\n" 124 text q_mq0 "\nif ne get i_oim q get i_oim o\n" 125 text q_mq1 "\nif ne get i_oim q get i_oim q\n" 126 note mutant 17: BCE accepts an index one past the proof (X <= L - e + 2) 127 text q_mz0 "ret le x add sub l e 1\n" 128 text q_mz1 "ret le x add sub l e 2\n" 129 note mutant 19: LICM may move shfl (dropped from op_canh's convergent list; o-shfl's pinned row differs) 130 text q_mv0 "eq op 44 eq op 45 or" 131 text q_mv1 "eq op 44 eq op 44 or" 132 text q_om "@ng opt\n@ng opt-count\n" 133 note the fixed-point tail of a second `@ng opt-count`, from phi= on (PHI's count comes right before bce=) 134 text q_fx " phi=0 bce=0 hoisted=0 merged=0 rotated=0 preheaders=0\n" 135 note the ngrun mutants 9..16 (review of `f73dc66d`, P3-3), the i-th pattern of q_np to the i-th of q_nr (fields 136 note ended by "|"): 9 rem MIN/-1 gives a, 10 u64 chk.add never fails, 11 u64 chk.mul never fails, 12 chk.shl 137 note without its negative bound, 13 signed conv lower bound at -2^(w-1), 14 chk.bounds passes e = 0, 138 note 15 narrow neg left uncanonical, 16 call depth cap 70000; field 8 is mutant 18, the step limit one op late 139 note (bay 8 review of `39f04efc` F2: n-loop2 then names 87, not 116) 140 text q_np "if eq b sub ulong 0 1\nret 0\n|\nret lt r a\n|\nret ne div r a b\n|\nif lt sa shr mn sb\n|lo = sub neg hi 1.0\n|ret or eq x 0 or gt b n gt x sub n b\n|ret rn_cn t sub ulong 0 a\n|if ge d 65535\n|if ge get r_s 6 get r_s 5\n|" 141 text q_nr "if eq b sub ulong 0 1\nret a\n|\nret lt r r\n|\nret gt and a 0 a\n|\nif lt sa add mn 00\n|lo = sub neg hi 0.0\n|ret or lt x 0 or gt b n gt x sub n b\n|ret add 000 sub ulong 0 a\n|if ge d 70000\n|if gt get r_s 6 get r_s 5\n|" 142 note the step budget of N cases 143 text q_stp "`1000000`" 144 note the IR.md s11 class names of exits 10..30, in order (the gate's own copy) 145 text q_cn "MAGIC VERSION TRUNCATED NONCANONICAL TRAILING UNKNOWN_OP TYPE USE_BEFORE_DEF DOMINANCE BLOCK_ARITY UNTERMINATED CHECK_CODE EFFECT LIMIT REF UNCHECKED UNREACHABLE IO TOKEN FACT ENTRY " 146 text q_irc "@ng ir-copy\n" 147 text q_hex "`0123456789abcdef`" 148 global q_wo uint 128 149 global q_wl uint 128 150 global q_mo uint 256 151 global q_ml uint 256 152 global q_omc uchar 4096 153 global q_scr uchar 4096 154 global q_pa uchar 8192 155 global q_av uchar 16384 156 global q_b1 uchar `16777216` 157 global q_b2 uchar `16777216` 158 global q_cs uchar `1048576` 159 global q_o uchar 4096 160 global q_stb uchar 4 161 global q_n ulong 32 162 global q_co uint 32 163 global q_cl uint 32 164 global q_fk ulong 256 165 global q_ex uchar 4096 166 global q_ma uchar 128 167 global q_un uchar 65536 168 global q_mb uchar 128 169 note q_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 170 note 5 b1 length, 6 b2 length, 7 cases length, 8 cases cursor, 9 out length, 10 cases run, 171 note 11 failures, 12 current case failed, 13 case line start, 14 control mode, 15 expected exit, 172 note 16 expected offset (or line), 17 offset present, 18 last child exit, 19 name end, 20 mutant id, 173 note 21 expected line length (q_ex), 22..24 fixture fns, blocks, ops, 25 mutant pattern length, 174 note 26 generator cursor in b1, 27..29 random runs ended normally, by exit, by a trap, 30 mutant pattern 175 note matches, 31 a float mutant's replacement length; q_fk counts failures by message (named kills and controls) 176 note ---- words, output ---------------------------------------------------------------------------- 177 fn gt_init to void 178 w = ulong 0 179 s = ulong 0 180 for i ulong len q_w 181 if eq get q_w i 32 182 put q_wo w uint s 183 put q_wl w uint sub i s 184 w = add w 1 185 s = add i 1 186 end 187 end 188 w = 0 189 s = 0 190 for i ulong len q_cn 191 if eq get q_cn i 32 192 put q_co w uint s 193 put q_cl w uint sub i s 194 w = add w 1 195 s = add i 1 196 end 197 end 198 w = 0 199 s = 0 200 for i ulong len q_m 201 if eq get q_m i 124 202 put q_mo w uint s 203 put q_ml w uint sub i s 204 w = add w 1 205 s = add i 1 206 end 207 end 208 end 209 fn gt_c b ulong to void 210 n = get q_n 9 211 if lt n len q_o 212 put q_o n uchar b 213 put q_n 9 add n 1 214 end 215 end 216 fn gt_nl to void 217 gt_c 10 218 r = write 1 q_o 0 get q_n 9 219 put q_n 9 0 220 end 221 fn gt_say i ulong to void 222 s = ulong get q_mo i 223 for j ulong ulong get q_ml i bound 64 224 gt_c ulong get q_m add s j 225 end 226 end 227 fn gt_num v ulong to void 228 if ge v 10 229 gt_num div v 10 230 end 231 gt_c add 48 rem v 10 232 end 233 note echo the current case line 234 fn gt_line to void 235 p = get q_n 13 236 while lt p get q_n 7 bound 4096 237 c = ulong get q_cs p 238 if eq c 10 239 ret 240 end 241 gt_c c 242 p = add p 1 243 end 244 end 245 note a failure of the current case: FAIL [ value] 246 fn gt_fail i ulong to void 247 put q_n 12 1 248 put q_fk i add get q_fk i 1 249 if ne get q_n 14 0 250 ret 251 end 252 gt_say 0 253 gt_line 254 gt_say i 255 end 256 fn gt_failv i ulong v ulong to void 257 gt_fail i 258 if eq get q_n 14 0 259 gt_c 32 260 gt_num v 261 gt_nl 262 end 263 end 264 fn gt_fail0 i ulong to void 265 gt_fail i 266 if eq get q_n 14 0 267 gt_nl 268 end 269 end 270 note ---- paths ---------------------------------------------------------------------------------- 271 fn gt_pclr to void 272 put q_n 0 0 273 end 274 fn gt_pc c ulong to void 275 n = get q_n 0 276 put q_pa n uchar c 277 put q_n 0 add n 1 278 end 279 fn gt_pw i ulong to void 280 s = ulong get q_wo i 281 for j ulong ulong get q_wl i bound 64 282 gt_pc ulong get q_w add s j 283 end 284 end 285 note scratch file word i 286 fn gt_ps i ulong to void 287 gt_pclr 288 for j ulong get q_n 2 bound 4096 289 gt_pc ulong get q_scr j 290 end 291 gt_pw i 292 end 293 note repository file seed/ng/ + word i 294 fn gt_pr i ulong to void 295 gt_pclr 296 gt_pw 0 297 gt_pw i 298 end 299 note fixture seed/ng/tests/ir/.oir, the name at cases [a, b) 300 fn gt_pfix a ulong b ulong to void 301 gt_pfx a b 16 302 end 303 note fixture seed/ng/tests/ir/ 304 fn gt_pfx a ulong b ulong w ulong to void 305 gt_pclr 306 gt_pw 0 307 gt_pw 14 308 for j ulong sub b a bound 256 309 gt_pc ulong get q_cs add a j 310 end 311 gt_pw w 312 end 313 fn gt_open fl ulong to int 314 r = fopen q_pa 0 get q_n 0 int fl 420 315 if lt r 0 316 ret -1 317 end 318 ret int r 319 end 320 fn gt_rdonly to int 321 ret gt_open 524288 322 end 323 fn gt_wronly to int 324 ret gt_open 524865 325 end 326 note ---- whole files ---------------------------------------------------------------------------- 327 note read the file at q_pa into b1 (k 1) or b2 (k 2); false when unreadable or larger than the buffer 328 fn gt_slurp k ulong to bool 329 fd = gt_rdonly 330 if lt fd 0 331 ret false 332 end 333 n = ulong 0 334 ok = true 335 while true bound `16777218` 336 x = long 0 337 if eq k 1 338 x = read fd q_b1 n sub len q_b1 n 339 else 340 x = read fd q_b2 n sub len q_b2 n 341 end 342 if lt x 0 343 ok = false 344 break 345 end 346 if eq x 0 347 break 348 end 349 n = add n ulong x 350 if ge n len q_b1 351 ok = false 352 break 353 end 354 end 355 r = fclose fd 356 put q_n add 4 k n 357 ret ok 358 end 359 note write b1[0, n) to the file at q_pa 360 fn gt_spill n ulong to bool 361 fd = gt_wronly 362 if lt fd 0 363 ret false 364 end 365 o = ulong 0 366 while lt o n bound `16777217` 367 x = write fd q_b1 o sub n o 368 if le x 0 369 r = fclose fd 370 ret false 371 end 372 o = add o ulong x 373 end 374 r = fclose fd 375 ret true 376 end 377 fn gt_same to bool 378 n = get q_n 5 379 if ne n get q_n 6 380 ret false 381 end 382 for j ulong n bound `16777216` 383 if ne get q_b1 j get q_b2 j 384 ret false 385 end 386 end 387 ret true 388 end 389 note ---- children ------------------------------------------------------------------------------- 390 fn gt_aclr to void 391 put q_n 3 2 392 put q_n 4 0 393 end 394 fn gt_aend n ulong to void 395 p = get q_n 3 396 put q_av p uchar and n 255 397 put q_av add p 1 uchar shr n 8 398 put q_n 3 add p add n 2 399 c = add get q_n 4 1 400 put q_n 4 c 401 put q_av 0 uchar and c 255 402 put q_av 1 uchar shr c 8 403 end 404 note append q_pa as the next argument 405 fn gt_apa to void 406 p = add get q_n 3 2 407 n = get q_n 0 408 for j ulong n bound 8192 409 put q_av add p j get q_pa j 410 end 411 gt_aend n 412 end 413 note append word i as the next argument 414 fn gt_aw i ulong to void 415 gt_pclr 416 gt_pw i 417 gt_apa 418 end 419 note run the argument list with stdin, stdout, stderr fds; the exit code, 256 + signal byte otherwise 420 fn gt_spawn fi int fo int fe int to ulong 421 if or lt fi 0 or lt fo 0 lt fe 0 422 gt_fclo fi 423 gt_fclo fo 424 gt_fclo fe 425 ret 512 426 end 427 pid = fork 428 if lt pid 0 429 exit 2 430 end 431 if eq pid 0 432 gt_redir fi 0 433 gt_redir fo 1 434 gt_redir fe 2 435 if eq get q_hs 0 0 436 r = execprog q_av 0 get q_n 3 437 else 438 n = add len q_hent 4 439 r = execenv q_av 0 get q_n 3 q_henv 0 n 440 end 441 exit 127 442 end 443 gt_fclo fi 444 gt_fclo fo 445 gt_fclo fe 446 r = waitpid int pid q_stb 0 len q_stb 0 447 if ne r pid 448 exit 2 449 end 450 x = ulong get q_stb 0 451 if ne x 0 452 ret add 256 x 453 end 454 v = ulong get q_stb 1 455 put q_n 18 v 456 ret v 457 end 458 fn gt_redir s int d int to void 459 if ne dupfd s d 0 long d 460 exit 127 461 end 462 end 463 fn gt_fclo fd int to void 464 if ge fd 0 465 r = fclose fd 466 end 467 end 468 note run tool word t (built in scratch) with no argument, stdin from the path in q_pa, 469 note stdout to scratch word o, stderr to scratch err 470 fn gt_tool t ulong o ulong to ulong 471 fi = gt_rdonly 472 gt_aclr 473 gt_ps t 474 gt_apa 475 gt_ps o 476 fo = gt_wronly 477 gt_ps 21 478 fe = gt_wronly 479 ret gt_spawn fi fo fe 480 end 481 note ---- build --------------------------------------------------------------------------------- 482 note concatenate seed/ng/ and seed/ng/ into scratch src.om, compile it with OMC to scratch 483 fn gt_build a ulong b ulong o ulong to bool 484 gt_pr a 485 if not gt_slurp 1 486 ret false 487 end 488 n = get q_n 5 489 gt_pr b 490 if not gt_slurp 2 491 ret false 492 end 493 m = get q_n 6 494 if gt add n m len q_b1 495 ret false 496 end 497 for j ulong m bound `16777216` 498 put q_b1 add n j get q_b2 j 499 end 500 total = add n m 501 if ne get q_n 20 0 502 if not gt_mutate total 503 ret false 504 end 505 total = get q_n 5 506 end 507 gt_ps 19 508 if not gt_spill total 509 ret false 510 end 511 ret gt_bodyb o 512 end 513 note apply mutant q_n 20 (its pattern q_ma -> q_mb) at its one place in b1[0, n); false, with the number 514 note of matches in q_n 30, unless the pattern occurs exactly once 515 fn gt_mutate n ulong to bool 516 gt_msel get q_n 20 517 put q_n 5 n 518 k = get q_n 25 519 put q_n 30 0 520 if lt n k 521 ret false 522 end 523 at0 = ulong 0 524 for p ulong add sub n k 1 bound `16777216` 525 if gt_mat p k 526 put q_n 30 add get q_n 30 1 527 at0 = p 528 end 529 end 530 if ne get q_n 30 1 531 ret false 532 end 533 if ge get q_n 20 20 534 r = get q_n 31 535 newn = add sub n k r 536 if gt newn len q_b1 537 ret false 538 end 539 for j ulong n bound `16777216` 540 put q_b2 j get q_b1 j 541 end 542 for j ulong r bound 128 543 put q_b1 add at0 j get q_mb j 544 end 545 for j ulong sub n add at0 k bound `16777216` 546 src = add add at0 k j 547 dst = add add at0 r j 548 byteval = get q_b2 src 549 put q_b1 dst byteval 550 end 551 put q_n 5 newn 552 else 553 for j ulong k bound 64 554 put q_b1 add at0 j get q_mb j 555 end 556 end 557 ret true 558 end 559 fn gt_mat p ulong k ulong to bool 560 for j ulong k bound 64 561 if ne get q_b1 add p j get q_ma j 562 ret false 563 end 564 end 565 ret true 566 end 567 note pattern and replacement of mutant id into q_ma, q_mb (length q_n 25) 568 fn gt_msel id ulong to void 569 if eq id 1 570 put q_n 25 len q_mu0 571 for j ulong len q_mu0 bound 64 572 put q_ma j get q_mu0 j 573 put q_mb j get q_mu1 j 574 end 575 end 576 if eq id 2 577 put q_n 25 len q_mp0 578 for j ulong len q_mp0 bound 64 579 put q_ma j get q_mp0 j 580 put q_mb j get q_mp1 j 581 end 582 end 583 if eq id 3 584 put q_n 25 len q_mc0 585 for j ulong len q_mc0 bound 64 586 put q_ma j get q_mc0 j 587 put q_mb j get q_mc1 j 588 end 589 end 590 if eq id 4 591 put q_n 25 len q_mu2 592 for j ulong len q_mu2 bound 64 593 put q_ma j get q_mu2 j 594 put q_mb j get q_mu3 j 595 end 596 end 597 if eq id 5 598 put q_n 25 len q_mr0 599 for j ulong len q_mr0 bound 64 600 put q_ma j get q_mr0 j 601 put q_mb j get q_mr1 j 602 end 603 end 604 if eq id 6 605 put q_n 25 len q_mx0 606 for j ulong len q_mx0 bound 64 607 put q_ma j get q_mx0 j 608 put q_mb j get q_mx1 j 609 end 610 end 611 gt_msel2 id 612 end 613 fn gt_msel2 id ulong to void 614 if eq id 7 615 put q_n 25 len q_mk0 616 for j ulong len q_mk0 bound 64 617 put q_ma j get q_mk0 j 618 put q_mb j get q_mk1 j 619 end 620 end 621 if eq id 8 622 put q_n 25 len q_mq0 623 for j ulong len q_mq0 bound 64 624 put q_ma j get q_mq0 j 625 put q_mb j get q_mq1 j 626 end 627 end 628 if eq id 17 629 put q_n 25 len q_mz0 630 for j ulong len q_mz0 bound 64 631 put q_ma j get q_mz0 j 632 put q_mb j get q_mz1 j 633 end 634 end 635 if and ge id 9 le id 16 636 gt_nsel sub id 9 637 end 638 if eq id 18 639 gt_nsel 8 640 end 641 if eq id 19 642 put q_n 25 len q_mv0 643 for j ulong len q_mv0 bound 64 644 put q_ma j get q_mv0 j 645 put q_mb j get q_mv1 j 646 end 647 end 648 if eq id 20 649 put q_n 25 len q_fp0 650 put q_n 31 len q_fr0 651 for j ulong len q_fp0 bound 128 652 put q_ma j get q_fp0 j 653 end 654 for j ulong len q_fr0 bound 128 655 put q_mb j get q_fr0 j 656 end 657 end 658 if eq id 21 659 put q_n 25 len q_fp1 660 put q_n 31 len q_fr1 661 for j ulong len q_fp1 bound 128 662 put q_ma j get q_fp1 j 663 end 664 for j ulong len q_fr1 bound 128 665 put q_mb j get q_fr1 j 666 end 667 end 668 if eq id 22 669 put q_n 25 len q_fp2 670 put q_n 31 len q_fr2 671 for j ulong len q_fp2 bound 128 672 put q_ma j get q_fp2 j 673 end 674 for j ulong len q_fr2 bound 128 675 put q_mb j get q_fr2 j 676 end 677 end 678 if eq id 24 679 put q_n 25 len q_fp4 680 put q_n 31 len q_fr4 681 for j ulong len q_fp4 bound 128 682 put q_ma j get q_fp4 j 683 end 684 for j ulong len q_fr4 bound 128 685 put q_mb j get q_fr4 j 686 end 687 end 688 if eq id 23 689 put q_n 25 len q_fp3 690 put q_n 31 len q_fr3 691 for j ulong len q_fp3 bound 128 692 put q_ma j get q_fp3 j 693 end 694 for j ulong len q_fr3 bound 128 695 put q_mb j get q_fr3 j 696 end 697 end 698 if eq id 27 699 put q_n 25 len q_fp7 700 put q_n 31 len q_fr7 701 for j ulong len q_fp7 bound 128 702 put q_ma j get q_fp7 j 703 end 704 for j ulong len q_fr7 bound 128 705 put q_mb j get q_fr7 j 706 end 707 end 708 if eq id 28 709 put q_n 25 len q_fp8 710 put q_n 31 len q_fr8 711 for j ulong len q_fp8 bound 128 712 put q_ma j get q_fp8 j 713 end 714 for j ulong len q_fr8 bound 128 715 put q_mb j get q_fr8 j 716 end 717 end 718 if eq id 29 719 put q_n 25 len q_fp9 720 put q_n 31 len q_fr9 721 for j ulong len q_fp9 bound 128 722 put q_ma j get q_fp9 j 723 end 724 for j ulong len q_fr9 bound 128 725 put q_mb j get q_fr9 j 726 end 727 end 728 if eq id 30 729 put q_n 25 len q_fp10 730 put q_n 31 len q_fr10 731 for j ulong len q_fp10 bound 128 732 put q_ma j get q_fp10 j 733 end 734 for j ulong len q_fr10 bound 128 735 put q_mb j get q_fr10 j 736 end 737 end 738 if eq id 32 739 put q_n 25 len q_fp12 740 put q_n 31 len q_fr12 741 for j ulong len q_fp12 bound 128 742 put q_ma j get q_fp12 j 743 end 744 for j ulong len q_fr12 bound 128 745 put q_mb j get q_fr12 j 746 end 747 end 748 if eq id 33 749 put q_n 25 len q_fp13 750 put q_n 31 len q_fr13 751 for j ulong len q_fp13 bound 128 752 put q_ma j get q_fp13 j 753 end 754 for j ulong len q_fr13 bound 128 755 put q_mb j get q_fr13 j 756 end 757 end 758 if eq id 34 759 put q_n 25 len q_fp14 760 put q_n 31 len q_fr14 761 for j ulong len q_fp14 bound 128 762 put q_ma j get q_fp14 j 763 end 764 for j ulong len q_fr14 bound 128 765 put q_mb j get q_fr14 j 766 end 767 end 768 if eq id 31 769 put q_n 25 len q_fp11 770 put q_n 31 len q_fr11 771 for j ulong len q_fp11 bound 128 772 put q_ma j get q_fp11 j 773 end 774 for j ulong len q_fr11 bound 128 775 put q_mb j get q_fr11 j 776 end 777 end 778 if eq id 26 779 put q_n 25 len q_fp6 780 put q_n 31 len q_fr6 781 for j ulong len q_fp6 bound 128 782 put q_ma j get q_fp6 j 783 end 784 for j ulong len q_fr6 bound 128 785 put q_mb j get q_fr6 j 786 end 787 end 788 if eq id 25 789 put q_n 25 len q_fp2 790 put q_n 31 len q_fr5 791 for j ulong len q_fp2 bound 128 792 put q_ma j get q_fp2 j 793 end 794 for j ulong len q_fr5 bound 128 795 put q_mb j get q_fr5 j 796 end 797 end 798 end 799 note field i of q_np into q_ma and of q_nr into q_mb (q_n 25 its length) 800 fn gt_nsel i ulong to void 801 a = gt_fld i true 802 k = ulong 0 803 while ne get q_np add a k 124 bound 64 804 put q_ma k get q_np add a k 805 k = add k 1 806 end 807 put q_n 25 k 808 b = gt_fld i false 809 for j ulong k bound 64 810 put q_mb j get q_nr add b j 811 end 812 end 813 note start of field i of q_np (np) or q_nr 814 fn gt_fld i ulong np bool to ulong 815 c = ulong 0 816 for p ulong len q_np bound 4096 817 if eq c i 818 ret p 819 end 820 x = get q_nr p 821 if np 822 x = get q_np p 823 end 824 if eq x 124 825 c = add c 1 826 end 827 end 828 ret 0 829 end 830 fn gt_bodyb o ulong to bool 831 fi = gt_rdonly 832 gt_aclr 833 gt_pclr 834 for j ulong get q_n 1 bound 4096 835 gt_pc ulong get q_omc j 836 end 837 gt_apa 838 gt_ps o 839 fo = gt_exe 840 gt_ps 21 841 fe = gt_wronly 842 ret eq gt_spawn fi fo fe 0 843 end 844 note open scratch q_pa for writing with mode 0755 (created fresh: unlink first) 845 fn gt_exe to int 846 r = unlink q_pa 0 get q_n 0 847 x = fopen q_pa 0 get q_n 0 524865 493 848 if lt x 0 849 ret -1 850 end 851 ret int x 852 end 853 fn gt_tools to bool 854 if not gt_build 6 7 1 855 ret false 856 end 857 if not gt_build 6 8 2 858 ret false 859 end 860 if not gt_build 9 10 3 861 ret false 862 end 863 if not gt_build 9 11 4 864 ret false 865 end 866 if not gt_build 30 32 31 867 ret false 868 end 869 if not gt_build 30 38 37 870 ret false 871 end 872 note ng through ngbuild: ngbuild build OMC seed/ng/ng.units SCRATCH/ng 873 gt_aclr 874 gt_ps 1 875 gt_apa 876 gt_aw 17 877 gt_pclr 878 for j ulong get q_n 1 bound 4096 879 gt_pc ulong get q_omc j 880 end 881 gt_apa 882 gt_pr 12 883 gt_apa 884 gt_ps 5 885 gt_apa 886 gt_pr 12 887 fi = gt_rdonly 888 gt_ps 20 889 fo = gt_wronly 890 gt_ps 21 891 fe = gt_wronly 892 ret eq gt_spawn fi fo fe 0 893 end 894 fn gt_table to bool 895 gt_aclr 896 gt_ps 2 897 gt_apa 898 gt_aw 18 899 gt_pr 12 900 fi = gt_rdonly 901 gt_ps 20 902 fo = gt_wronly 903 gt_ps 21 904 fe = gt_wronly 905 if ne gt_spawn fi fo fe 0 906 ret false 907 end 908 gt_ps 20 909 if not gt_slurp 1 910 ret false 911 end 912 gt_pr 13 913 if not gt_slurp 2 914 ret false 915 end 916 ret gt_same 917 end 918 note ---- cases parsing ----------------------------------------------------------------------------- 919 fn gt_pk to ulong 920 p = get q_n 8 921 if ge p get q_n 7 922 ret 10 923 end 924 ret ulong get q_cs p 925 end 926 fn gt_adv to void 927 put q_n 8 add get q_n 8 1 928 end 929 fn gt_skip to void 930 while eq gt_pk 32 bound 4096 931 gt_adv 932 end 933 end 934 note a decimal field; q_n 17 = 0 when the field is "-" or absent (value 0) 935 fn gt_dec to ulong 936 gt_skip 937 put q_n 17 0 938 if eq gt_pk 45 939 gt_adv 940 ret 0 941 end 942 v = ulong 0 943 while and ge gt_pk 48 le gt_pk 57 bound 20 944 v = add mul v 10 sub gt_pk 48 945 gt_adv 946 put q_n 17 1 947 end 948 ret v 949 end 950 note a name field: its start; its end goes to q_n 19 951 fn gt_name to ulong 952 gt_skip 953 a = get q_n 8 954 while and ne gt_pk 32 ne gt_pk 10 bound 256 955 gt_adv 956 end 957 put q_n 19 get q_n 8 958 ret a 959 end 960 fn gt_eol to void 961 while ne gt_pk 10 bound 4096 962 gt_adv 963 end 964 gt_adv 965 end 966 note ---- checks --------------------------------------------------------------------------------- 967 note the expected stdout or stderr line is built in q_ex (length q_n 21) 968 fn gt_xclr to void 969 put q_n 21 0 970 end 971 fn gt_xc c ulong to void 972 n = get q_n 21 973 if lt n len q_ex 974 put q_ex n uchar c 975 put q_n 21 add n 1 976 end 977 end 978 fn gt_xs i ulong to void 979 s = ulong get q_mo i 980 for j ulong ulong get q_ml i bound 128 981 gt_xc ulong get q_m add s j 982 end 983 end 984 fn gt_xnum v ulong to void 985 if ge v 10 986 gt_xnum div v 10 987 end 988 gt_xc add 48 rem v 10 989 end 990 note the class name of exit c (10..30), its number otherwise 991 fn gt_xcn c ulong to void 992 if or lt c 10 gt c 30 993 gt_xnum c 994 ret 995 end 996 i = sub c 10 997 s = ulong get q_co i 998 for j ulong ulong get q_cl i bound 64 999 gt_xc ulong get q_cn add s j 1000 end 1001 end 1002 note scratch file word w holds exactly the line in q_ex 1003 fn gt_xok w ulong to bool 1004 gt_ps w 1005 if not gt_slurp 2 1006 ret false 1007 end 1008 n = get q_n 21 1009 if ne get q_n 6 n 1010 ret false 1011 end 1012 for j ulong n bound 4096 1013 if ne get q_b2 j get q_ex j 1014 ret false 1015 end 1016 end 1017 ret true 1018 end 1019 note scratch file word w is empty 1020 fn gt_nil w ulong to bool 1021 gt_ps w 1022 if not gt_slurp 2 1023 ret false 1024 end 1025 ret eq get q_n 6 0 1026 end 1027 note the one refusal line of tool t (2 ngcheck, 3 ngas, 4 ngdis, 5 ng, 6 ngrun) for exit ex at off (IR.md s10, s11) 1028 fn gt_refx t ulong ex ulong off ulong to void 1029 gt_xclr 1030 if eq t 3 1031 if eq ex 23 1032 gt_xs 31 1033 else 1034 gt_xs 30 1035 end 1036 gt_xnum off 1037 gt_xc 10 1038 ret 1039 end 1040 if eq t 2 1041 gt_xs 27 1042 gt_xcn ex 1043 else 1044 if eq t 4 1045 gt_xs 28 1046 else 1047 gt_xs gt_rpre t 1048 end 1049 gt_xnum ex 1050 end 1051 gt_xs 32 1052 gt_xnum off 1053 gt_xc 10 1054 end 1055 fn gt_rpre t ulong to ulong 1056 if eq t 6 1057 ret 92 1058 end 1059 ret 29 1060 end 1061 note a refusal: scratch err is exactly the refusal line and stdout (scratch word o) is empty 1062 fn gt_refok t ulong ex ulong off ulong o ulong to bool 1063 gt_refx t ex off 1064 if not gt_xok 21 1065 gt_fail0 38 1066 ret false 1067 end 1068 if not gt_nil o 1069 gt_fail0 39 1070 ret false 1071 end 1072 ret true 1073 end 1074 note an acceptance: scratch out is exactly "ACCEPT fns=F blocks=B ops=O\n" with 1075 note the counts the gate took from the fixture text (q_n 22..24), and scratch err is empty 1076 fn gt_witok n ulong to void 1077 for j ulong n bound `16777216` 1078 put sh_dat j get q_b1 j 1079 end 1080 sh_all n 1081 gt_xclr 1082 gt_xs 33 1083 for j ulong 32 1084 x = ulong get sh_dig j 1085 gt_xc ulong get q_hex shr x 4 1086 gt_xc ulong get q_hex and x 15 1087 end 1088 gt_xs 34 1089 gt_xnum get q_n 22 1090 gt_xs 35 1091 gt_xnum get q_n 23 1092 gt_xs 36 1093 gt_xnum get q_n 24 1094 gt_xc 10 1095 if not gt_xok 20 1096 gt_fail0 37 1097 ret 1098 end 1099 if not gt_nil 21 1100 gt_fail0 37 1101 end 1102 end 1103 note fixture counts from its text in b2: functions (lines "fn ", "export ", "kernel "), blocks (lines 1104 note "block " inside a function), ops (every other nonempty line inside a function but "end") 1105 fn gt_tcount to void 1106 put q_n 22 0 1107 put q_n 23 0 1108 put q_n 24 0 1109 inf = false 1110 s = ulong 0 1111 for p ulong get q_n 6 bound `16777216` 1112 if eq get q_b2 p 10 1113 inf = gt_tline s p inf 1114 s = add p 1 1115 end 1116 end 1117 end 1118 fn gt_tline s ulong e ulong inf bool to bool 1119 if gt_tfn s e 1120 put q_n 22 add get q_n 22 1 1121 ret true 1122 end 1123 if not inf 1124 ret false 1125 end 1126 if eq sub e s 3 1127 if gt_tpre s e 52 1128 ret false 1129 end 1130 end 1131 if gt_tpre s e 51 1132 put q_n 23 add get q_n 23 1 1133 ret true 1134 end 1135 if gt e s 1136 put q_n 24 add get q_n 24 1 1137 end 1138 ret true 1139 end 1140 fn gt_tfn s ulong e ulong to bool 1141 if gt_tpre s e 48 1142 ret true 1143 end 1144 if gt_tpre s e 49 1145 ret true 1146 end 1147 ret gt_tpre s e 50 1148 end 1149 note line b2[s, e) starts with message i 1150 fn gt_tpre s ulong e ulong i ulong to bool 1151 k = ulong get q_ml i 1152 if lt sub e s k 1153 ret false 1154 end 1155 m = ulong get q_mo i 1156 for j ulong k bound 64 1157 if ne get q_b2 add s j get q_m add m j 1158 ret false 1159 end 1160 end 1161 ret true 1162 end 1163 note assemble fixture [a, b) into scratch bin; false (case failed) when ngas refuses 1164 fn gt_asm a ulong b ulong to bool 1165 gt_pfix a b 1166 x = gt_tool 3 23 1167 if ne x 0 1168 gt_failv 4 x 1169 ret false 1170 end 1171 ret true 1172 end 1173 note T NAME EXIT OFFSET 1174 fn gt_tcase to void 1175 a = gt_name 1176 b = get q_n 19 1177 ex = gt_dec 1178 off = gt_dec 1179 if not gt_asm a b 1180 ret 1181 end 1182 gt_ps 23 1183 x = gt_tool 4 24 1184 if ne x 0 1185 gt_failv 5 x 1186 ret 1187 end 1188 gt_ps 24 1189 if not gt_slurp 1 1190 gt_fail0 21 1191 ret 1192 end 1193 gt_pfix a b 1194 if not gt_slurp 2 1195 gt_fail0 21 1196 ret 1197 end 1198 gt_tcount 1199 if not gt_same 1200 gt_fail0 6 1201 end 1202 gt_ps 23 1203 gt_verdict 2 ex off 1204 gt_ps 23 1205 if not gt_slurp 1 1206 gt_fail0 21 1207 ret 1208 end 1209 n = get q_n 5 1210 if eq ex 0 1211 if eq get q_n 12 0 1212 gt_witok n 1213 end 1214 end 1215 gt_ngchk n ex off false 1216 end 1217 note run tool t (ngcheck 2 or ngdis 4) on the path in q_pa: exit ex, and for a refusal its one line 1218 fn gt_verdict t ulong ex ulong off ulong to void 1219 x = gt_tool t 20 1220 if ne x ex 1221 if eq t 2 1222 gt_failv 7 x 1223 else 1224 gt_failv 20 x 1225 end 1226 ret 1227 end 1228 if ne ex 0 1229 s = gt_refok t ex off 20 1230 end 1231 end 1232 note the classes every reader refuses alike, at the same offset (IR.md s14) 1233 fn gt_strict c ulong to bool 1234 if or eq c 10 or eq c 11 eq c 12 1235 ret true 1236 end 1237 if or eq c 14 or eq c 15 eq c 23 1238 ret true 1239 end 1240 ret eq c 27 1241 end 1242 note ng ir-copy of the unit b1[0, n) that ngcheck judged ex at off: for a structural class (gt_strict) 1243 note the same refusal line; otherwise the same bytes out, or (ngcheck refused) a refusal of its own 1244 fn gt_ngchk n ulong ex ulong off ulong exact bool to void 1245 gt_ps 26 1246 if not gt_spill n 1247 gt_fail0 21 1248 ret 1249 end 1250 k = gt_pre n 1251 gt_ps 22 1252 if not gt_spill add n k 1253 gt_fail0 21 1254 ret 1255 end 1256 gt_ps 22 1257 x = gt_tool 5 20 1258 gt_ngv x ex off exact 1259 end 1260 note put "@ng ir-copy\n" before b1[0, n); its length 1261 fn gt_pre n ulong to ulong 1262 k = len q_irc 1263 for j ulong n bound `16777216` 1264 put q_b1 sub add n k add 1 j get q_b1 sub n add 1 j 1265 end 1266 for j ulong k bound 16 1267 put q_b1 j get q_irc j 1268 end 1269 ret k 1270 end 1271 note judge ng's exit x (stdout scratch out, the unit in scratch unit) against ngcheck's ex at off 1272 fn gt_ngv x ulong ex ulong off ulong exact bool to void 1273 if or exact gt_strict ex 1274 if ne x ex 1275 gt_failv 40 x 1276 ret 1277 end 1278 s = gt_refok 5 ex off 20 1279 ret 1280 end 1281 if eq x 0 1282 if not gt_fcmp 26 20 1283 gt_fail0 11 1284 end 1285 ret 1286 end 1287 if eq ex 0 1288 gt_failv 10 x 1289 ret 1290 end 1291 if or lt x 10 gt x 30 1292 gt_failv 40 x 1293 ret 1294 end 1295 if not gt_nil 20 1296 gt_fail0 39 1297 end 1298 end 1299 note S NAME LINE 1300 fn gt_scase to void 1301 a = gt_name 1302 b = get q_n 19 1303 ln = gt_dec 1304 gt_pfix a b 1305 x = gt_tool 3 23 1306 if ne x 3 1307 gt_failv 4 x 1308 ret 1309 end 1310 s = gt_refok 3 3 ln 23 1311 end 1312 note M BASE POS BYTE EXIT OFF / C BASE LEN EXIT OFF / A BASE BYTE EXIT OFF; optional NGEXIT NGOFF 1313 note pins ng separately when s12 permits a reader capacity different from ngcheck and ngdis 1314 fn gt_mcase k ulong to void 1315 a = gt_name 1316 b = get q_n 19 1317 p = gt_dec 1318 v = ulong 0 1319 if eq k 77 1320 v = gt_dec 1321 end 1322 ex = gt_dec 1323 off = gt_dec 1324 ngex = gt_dec 1325 exact = ne get q_n 17 0 1326 ngoff = gt_dec 1327 if not exact 1328 ngex = ex 1329 ngoff = off 1330 end 1331 if not gt_asm a b 1332 ret 1333 end 1334 gt_ps 23 1335 if not gt_slurp 1 1336 gt_fail0 21 1337 ret 1338 end 1339 n = get q_n 5 1340 if eq k 77 1341 if ge p n 1342 gt_fail0 13 1343 ret 1344 end 1345 put q_b1 p uchar v 1346 end 1347 if eq k 67 1348 n = p 1349 end 1350 if eq k 65 1351 put q_b1 n uchar p 1352 n = add n 1 1353 end 1354 gt_ps 22 1355 if not gt_spill n 1356 gt_fail0 21 1357 ret 1358 end 1359 gt_ps 22 1360 gt_verdict 2 ex off 1361 gt_ps 22 1362 gt_verdict 4 ex off 1363 gt_ngchk n ngex ngoff exact 1364 end 1365 note D EXIT OFF: stdin is the directory seed/ng/tests/ir 1366 fn gt_dcase to void 1367 ex = gt_dec 1368 off = gt_dec 1369 gt_pr 25 1370 gt_verdict 2 ex off 1371 gt_pr 25 1372 gt_verdict 4 ex off 1373 gt_pr 25 1374 x = gt_tool 5 20 1375 gt_ngv x ex off false 1376 gt_pr 25 1377 x = gt_tool 3 23 1378 if ne x ex 1379 gt_failv 4 x 1380 end 1381 end 1382 note G GEN TOOL EXIT OFF: generated input GEN (gt_gen) to TOOL: c ngcheck, d ngdis, n ng ir-copy, 1383 note a ngas (OFF a line), r ngas then ngdis (the text must come back), x ngrun (refusals only) 1384 fn gt_gcase to void 1385 a = gt_name 1386 b = get q_n 19 1387 t = gt_name 1388 tl = ulong get q_cs t 1389 ex = gt_dec 1390 off = gt_dec 1391 if not gt_gen a b eq tl 110 22 1392 gt_fail0 45 1393 ret 1394 end 1395 gt_ps 22 1396 if eq tl 99 1397 gt_verdict 2 ex off 1398 ret 1399 end 1400 if eq tl 100 1401 gt_verdict 4 ex off 1402 ret 1403 end 1404 if eq tl 110 1405 x = gt_tool 5 20 1406 if eq x 0 1407 s = gt_gen a b false 26 1408 end 1409 gt_ngv x ex off false 1410 ret 1411 end 1412 if eq tl 97 1413 x = gt_tool 3 23 1414 if ne x ex 1415 gt_failv 4 x 1416 ret 1417 end 1418 if ne ex 0 1419 s = gt_refok 3 ex off 23 1420 end 1421 ret 1422 end 1423 if eq tl 114 1424 gt_grt 1425 ret 1426 end 1427 if eq tl 120 1428 x = gt_run 31 22 20 21 1429 if ne x ex 1430 gt_failv 87 x 1431 ret 1432 end 1433 s = gt_refok 6 ex off 20 1434 ret 1435 end 1436 gt_fail0 13 1437 end 1438 fn gt_grt to void 1439 x = gt_tool 3 23 1440 if ne x 0 1441 gt_failv 4 x 1442 ret 1443 end 1444 gt_ps 23 1445 x = gt_tool 4 24 1446 if ne x 0 1447 gt_failv 5 x 1448 ret 1449 end 1450 if not gt_fcmp 22 24 1451 gt_fail0 82 1452 end 1453 end 1454 note run scratch tool t with the one argument scratch word i, stdin the same file, stdout and stderr 1455 note to scratch words o and e; its exit code (gt_spawn) 1456 fn gt_run t ulong i ulong o ulong e ulong to ulong 1457 gt_ps i 1458 fi = gt_rdonly 1459 gt_aclr 1460 gt_ps t 1461 gt_apa 1462 gt_ps i 1463 gt_apa 1464 gt_ps o 1465 fo = gt_wronly 1466 gt_ps e 1467 fe = gt_wronly 1468 ret gt_spawn fi fo fe 1469 end 1470 note R NAME: NAME.oir assembled, accepted by ngcheck and run by ngrun; NAME.om compiled by OMC and run; 1471 note exit status, stdout and stderr must be equal (D9 differential) 1472 fn gt_rcase to void 1473 a = gt_name 1474 b = get q_n 19 1475 if not gt_asm a b 1476 ret 1477 end 1478 gt_ps 23 1479 x = gt_tool 2 20 1480 if ne x 0 1481 gt_failv 7 x 1482 ret 1483 end 1484 gt_pfx a b 33 1485 if not gt_bodyb 34 1486 gt_fail0 91 1487 ret 1488 end 1489 x = gt_run 31 23 20 21 1490 y = gt_run 34 23 35 36 1491 if ne x y 1492 gt_fail 87 1493 if eq get q_n 14 0 1494 gt_num x 1495 gt_say 88 1496 gt_num y 1497 gt_nl 1498 end 1499 ret 1500 end 1501 if not gt_fcmp 20 35 1502 gt_fail0 89 1503 ret 1504 end 1505 if not gt_fcmp 21 36 1506 gt_fail0 90 1507 end 1508 end 1509 note ---- the optimizer (seed/ng/src/opt.om through ng's `@ng opt` and `@ng opt-count`) ------------------ 1510 note O NAME, L NAME: fixture seed/ng/tests/opt/NAME.oir assembled into scratch rbin, then gt_oone, then the 1511 note row "ok O NAME fns=.. loops=.. inloop=A->B hoisted=.. merged=.. rotated=.. preheaders=.." of 1512 note `@ng opt-count` on it. L marks a long-running unit: skipped under a mutant. 1513 fn gt_ocase k ulong to void 1514 if and eq k 76 ne get q_n 14 0 1515 ret 1516 end 1517 a = gt_name 1518 b = get q_n 19 1519 gt_pclr 1520 gt_pw 0 1521 gt_pw 46 1522 for j ulong sub b a bound 256 1523 gt_pc ulong get q_cs add a j 1524 end 1525 gt_pw 16 1526 x = gt_tool 3 39 1527 if ne x 0 1528 gt_failv 4 x 1529 ret 1530 end 1531 if not gt_oone 0 eq k 76 1532 ret 1533 end 1534 if not gt_omode 39 1 1535 gt_fail0 109 1536 ret 1537 end 1538 gt_ps 53 1539 x = gt_tool 5 50 1540 gt_ps 50 1541 if or ne x 0 not gt_slurp 2 1542 gt_fail0 109 1543 ret 1544 end 1545 gt_orpr 1546 end 1547 note the opt-count row in q_b2 against the case line: "ok O NAME" and the row, or the failure with the row got; 1548 note under a mutant only the failure is counted (silent), so a mutant that changes what a pass does is seen 1549 fn gt_orpr to void 1550 if not gt_orow 1551 gt_fail 132 1552 if eq get q_n 14 0 1553 for j ulong sub get q_n 6 4 bound 4096 1554 gt_c ulong get q_b2 add j 4 1555 end 1556 end 1557 ret 1558 end 1559 if ne get q_n 14 0 1560 ret 1561 end 1562 gt_say 26 1563 s = get q_n 13 1564 for j ulong sub get q_n 19 s bound 256 1565 gt_c ulong get q_cs add s j 1566 end 1567 for j ulong sub get q_n 6 3 bound 4096 1568 gt_c ulong get q_b2 add j 3 1569 end 1570 end 1571 note the case line after NAME (nothing, or the expected " fns=.. preheaders=..") equals the `@ng opt-count` 1572 note row in q_b2 after its "opt" 1573 fn gt_orow to bool 1574 p = get q_n 19 1575 z = get q_n 7 1576 if ge p z 1577 ret true 1578 end 1579 if eq get q_cs p 10 1580 ret true 1581 end 1582 n = get q_n 6 1583 if lt n 4 1584 ret false 1585 end 1586 m = sub n 4 1587 if gt add p m z 1588 ret false 1589 end 1590 for j ulong m bound 4096 1591 if ne get q_cs add p j get q_b2 add 3 j 1592 ret false 1593 end 1594 end 1595 if lt add p m z 1596 ret eq get q_cs add p m 10 1597 end 1598 ret true 1599 end 1600 note the optimizer on the unit in scratch rbin (s its seed, 0 for a fixture): ngrun before (rout, rerr); 1601 note `@ng opt` (obin) exits 0, stderr empty; ngcheck's whole ACCEPT line on obin; ngas(ngdis(obin)) == 1602 note obin; ngrun after equal (gt_osame; ck: an L kernel, whose stderr is its clock line); `@ng opt-count` on 1603 note obin reports a fixed point (gt_ofix) 1604 fn gt_oone s ulong ck bool to bool 1605 xb = gt_run 31 39 35 36 1606 if not gt_omode 39 0 1607 gt_ofail 109 s 1608 ret false 1609 end 1610 gt_ps 53 1611 x = gt_tool 5 47 1612 if or ne x 0 not gt_nil 21 1613 gt_ofail 109 s 1614 ret false 1615 end 1616 if not gt_oacc s 1617 ret false 1618 end 1619 gt_ps 48 1620 x = gt_tool 3 49 1621 if or ne x 0 not gt_fcmp 47 49 1622 gt_ofail 111 s 1623 ret false 1624 end 1625 xa = gt_run 31 47 20 21 1626 if not gt_osame xb xa ck 1627 gt_ofail 112 s 1628 ret false 1629 end 1630 if not gt_omode 47 1 1631 gt_ofail 109 s 1632 ret false 1633 end 1634 gt_ps 53 1635 x = gt_tool 5 50 1636 if or ne x 0 not gt_ofix 1637 gt_ofail 113 s 1638 ret false 1639 end 1640 ret true 1641 end 1642 note obin: ngdis gives its text (otxt), ngcheck must give the whole ACCEPT line with that text's counts 1643 fn gt_oacc s ulong to bool 1644 gt_ps 47 1645 x = gt_tool 4 48 1646 if ne x 0 1647 gt_ofail 110 s 1648 ret false 1649 end 1650 gt_ps 48 1651 if not gt_slurp 2 1652 gt_ofail 110 s 1653 ret false 1654 end 1655 gt_tcount 1656 gt_ps 47 1657 if not gt_slurp 1 1658 gt_ofail 110 s 1659 ret false 1660 end 1661 n = get q_n 5 1662 gt_ps 47 1663 x = gt_tool 2 20 1664 if ne x 0 1665 gt_ofail 110 s 1666 ret false 1667 end 1668 f = get q_fk 37 1669 gt_witok n 1670 ret eq get q_fk 37 f 1671 end 1672 note a failure of the opt checks, with the seed when there is one 1673 fn gt_ofail i ulong s ulong to void 1674 if eq s 0 1675 gt_fail0 i 1676 ret 1677 end 1678 gt_fail i 1679 if eq get q_n 14 0 1680 gt_say 114 1681 gt_num s 1682 gt_nl 1683 end 1684 end 1685 note scratch oin = the mode line m (0 "@ng opt", 1 "@ng opt-count") and then scratch word w 1686 fn gt_omode w ulong m ulong to bool 1687 gt_ps w 1688 if not gt_slurp 1 1689 ret false 1690 end 1691 n = get q_n 5 1692 k = add 8 mul m 6 1693 t = add n k 1694 if gt t len q_b1 1695 ret false 1696 end 1697 for j ulong n bound `16777216` 1698 c = get q_b1 sub n add 1 j 1699 put q_b1 sub t add 1 j c 1700 end 1701 o = mul m 8 1702 for j ulong k bound 16 1703 put q_b1 j get q_om add o j 1704 end 1705 gt_ps 53 1706 ret gt_spill t 1707 end 1708 note runs before (exit xb, rout, rerr) and after (exit xa, out, err) are equal: exits, stdout bytes, and 1709 note stderr bytes; for an L kernel (ck) one decimal line on each side also counts as equal (its elapsed-time 1710 note clock), so a changed decimal stderr line of a Q unit or an O fixture is a difference (bay 4 P3-5) 1711 fn gt_osame xb ulong xa ulong ck bool to bool 1712 if ne xb xa 1713 ret false 1714 end 1715 if not gt_fcmp 35 20 1716 ret false 1717 end 1718 if gt_fcmp 36 21 1719 ret true 1720 end 1721 if not ck 1722 ret false 1723 end 1724 if not gt_clk 36 1725 ret false 1726 end 1727 ret gt_clk 21 1728 end 1729 note scratch word w is one line of decimal digits 1730 fn gt_clk w ulong to bool 1731 gt_ps w 1732 if not gt_slurp 2 1733 ret false 1734 end 1735 n = get q_n 6 1736 if lt n 2 1737 ret false 1738 end 1739 if ne get q_b2 sub n 1 10 1740 ret false 1741 end 1742 for j ulong sub n 1 bound 64 1743 c = get q_b2 j 1744 if or lt c 48 gt c 57 1745 ret false 1746 end 1747 end 1748 ret true 1749 end 1750 note scratch ocnt ends " phi=0 bce=0 hoisted=0 merged=0 rotated=0 preheaders=0" (q_fx) 1751 fn gt_ofix to bool 1752 gt_ps 50 1753 if not gt_slurp 2 1754 ret false 1755 end 1756 n = get q_n 6 1757 k = len q_fx 1758 if lt n k 1759 ret false 1760 end 1761 for j ulong k bound 64 1762 if ne get q_b2 add sub n k j get q_fx j 1763 ret false 1764 end 1765 end 1766 ret true 1767 end 1768 note build ng (scratch ng) from the units listed in seed/ng/ng.units, in order, with mutant q_n 20 applied 1769 note (gt_mutate) when one is set 1770 fn gt_bng to bool 1771 gt_pr 12 1772 fd = gt_rdonly 1773 if lt fd 0 1774 ret false 1775 end 1776 k = read fd q_un 0 len q_un 1777 r = fclose fd 1778 if le k 0 1779 ret false 1780 end 1781 put q_n 5 0 1782 s = ulong 0 1783 for p ulong ulong k bound 65536 1784 if eq get q_un p 10 1785 if not gt_bunit s p 1786 ret false 1787 end 1788 s = add p 1 1789 end 1790 end 1791 n = get q_n 5 1792 if ne get q_n 20 0 1793 if not gt_mutate n 1794 ret false 1795 end 1796 end 1797 gt_ps 19 1798 if not gt_spill n 1799 ret false 1800 end 1801 ret gt_bodyb 5 1802 end 1803 note append the unit of the ng.units line q_un[s, e) ("HEX PATH", the path from the repository root) to b1 1804 fn gt_bunit s ulong e ulong to bool 1805 if lt e add s 66 1806 ret false 1807 end 1808 gt_pclr 1809 for j ulong sub e add s 65 bound 4096 1810 gt_pc ulong get q_un add add s 65 j 1811 end 1812 if not gt_slurp 2 1813 ret false 1814 end 1815 n = get q_n 5 1816 m = get q_n 6 1817 if gt add n m len q_b1 1818 ret false 1819 end 1820 for j ulong m bound `16777216` 1821 put q_b1 add n j get q_b2 j 1822 end 1823 put q_n 5 add n m 1824 ret true 1825 end 1826 note N NAME EXIT OFF: NAME.oir assembled and run by `ngrun FILE `1000000``: exit EXIT, empty stdout, and an 1827 note empty stderr, or for EXIT 124 (step limit) and 126 (access outside storage) the exact line naming OFF 1828 fn gt_ncase to void 1829 a = gt_name 1830 b = get q_n 19 1831 ex = gt_dec 1832 off = gt_dec 1833 if not gt_asm a b 1834 ret 1835 end 1836 x = gt_nrun 23 20 21 1837 if ne x ex 1838 gt_failv 118 x 1839 ret 1840 end 1841 if not gt_nil 20 1842 gt_fail0 119 1843 ret 1844 end 1845 if or eq ex 124 eq ex 126 1846 gt_xclr 1847 if eq ex 124 1848 gt_xs 121 1849 else 1850 gt_xs 122 1851 end 1852 gt_xnum off 1853 gt_xc 10 1854 if not gt_xok 21 1855 gt_fail0 120 1856 end 1857 ret 1858 end 1859 if not gt_nil 21 1860 gt_fail0 120 1861 end 1862 end 1863 note ngrun (scratch) on scratch word i with the argument q_stp, stdin from i, stdout o, stderr e 1864 fn gt_nrun i ulong o ulong e ulong to ulong 1865 gt_ps i 1866 fi = gt_rdonly 1867 gt_aclr 1868 gt_ps 31 1869 gt_apa 1870 gt_ps i 1871 gt_apa 1872 gt_pclr 1873 for j ulong len q_stp bound 16 1874 gt_pc ulong get q_stp j 1875 end 1876 gt_apa 1877 gt_ps o 1878 fo = gt_wronly 1879 gt_ps e 1880 fe = gt_wronly 1881 ret gt_spawn fi fo fe 1882 end 1883 note ---- random programs (seed/ng/ngrand.om, the D9 differential source) ----------------------------- 1884 fn gt_case2 k ulong to void 1885 if eq k 78 1886 gt_ncase 1887 ret 1888 end 1889 if or eq k 79 eq k 76 1890 gt_ocase k 1891 ret 1892 end 1893 if eq k 81 1894 gt_qcase 1895 ret 1896 end 1897 if eq k 75 1898 gt_kcase 1899 ret 1900 end 1901 gt_fail0 13 1902 end 1903 fn gt_pnum v ulong to void 1904 if ge v 10 1905 gt_pnum div v 10 1906 end 1907 gt_pc add 48 rem v 10 1908 end 1909 note scratch word w = the unit of `ngrand SEED` (k 0) or of `ngrand tape SCRATCH/kbin.tape` (k 1); 1910 note stderr to scratch err 1911 fn gt_rgen s ulong k ulong w ulong to ulong 1912 gt_ps 37 1913 fi = gt_rdonly 1914 gt_aclr 1915 gt_ps 37 1916 gt_apa 1917 if eq k 0 1918 gt_pclr 1919 gt_pnum s 1920 gt_apa 1921 else 1922 gt_aw 45 1923 gt_ps 44 1924 gt_apa 1925 end 1926 gt_ps w 1927 fo = gt_wronly 1928 gt_ps 21 1929 fe = gt_wronly 1930 ret gt_spawn fi fo fe 1931 end 1932 note Q N: seeds 1 .. N (at most 100 under a mutant), each through gt_qone; the first failing seed ends 1933 note the case (every seed under a mutant), else one line "ok random seeds=N normal= exit= trap=" 1934 fn gt_qcase to void 1935 n = gt_dec 1936 q = ne get q_n 14 0 1937 if and q gt n 100 1938 n = 100 1939 end 1940 put q_n 27 0 1941 put q_n 28 0 1942 put q_n 29 0 1943 for j ulong n bound `1048576` 1944 if not gt_qone add j 1 1945 if not q 1946 ret 1947 end 1948 end 1949 end 1950 if not q 1951 gt_say 103 1952 gt_num n 1953 gt_say 104 1954 gt_num get q_n 27 1955 gt_say 105 1956 gt_num get q_n 28 1957 gt_say 106 1958 gt_num get q_n 29 1959 gt_nl 1960 end 1961 end 1962 note one seed: its unit (scratch rbin) accepted, ngas(ngdis(b)) == b, the same bytes again for seed 1, 1963 note and ngrun ends cleanly 1964 fn gt_qone s ulong to bool 1965 x = gt_rgen s 0 39 1966 e = gt_nil 21 1967 if or ne x 0 not e 1968 gt_failv 93 s 1969 ret false 1970 end 1971 if not gt_qacc s 39 1972 ret false 1973 end 1974 gt_ps 40 1975 x = gt_tool 3 41 1976 if ne x 0 1977 gt_failv 96 s 1978 ret false 1979 end 1980 if not gt_fcmp 39 41 1981 gt_failv 96 s 1982 ret false 1983 end 1984 if eq s 1 1985 x = gt_rgen 1 0 41 1986 if or ne x 0 not gt_fcmp 39 41 1987 gt_fail0 98 1988 ret false 1989 end 1990 end 1991 if not gt_qrun s 1992 ret false 1993 end 1994 ret gt_oone s false 1995 end 1996 note the unit in scratch word w: ngdis gives its text (scratch rtxt) and ngcheck the whole ACCEPT line with 1997 note the counts of that text (gt_tcount, gt_witok); ngcheck exit 28 (TOKEN) is the ngrand mutant's check 1998 fn gt_qacc s ulong w ulong to bool 1999 gt_ps w 2000 x = gt_tool 4 40 2001 if ne x 0 2002 gt_failv 96 s 2003 ret false 2004 end 2005 gt_ps 40 2006 if not gt_slurp 2 2007 gt_failv 96 s 2008 ret false 2009 end 2010 gt_tcount 2011 gt_ps w 2012 if not gt_slurp 1 2013 gt_failv 93 s 2014 ret false 2015 end 2016 n = get q_n 5 2017 gt_ps w 2018 x = gt_tool 2 20 2019 if ne x 0 2020 if eq x 28 2021 gt_failv 95 s 2022 else 2023 gt_failv 94 s 2024 end 2025 ret false 2026 end 2027 f = get q_fk 37 2028 gt_witok n 2029 ret eq get q_fk 37 f 2030 end 2031 note ngrun on scratch rbin: exit 0..63 with 0 or 8 stdout bytes (an early return, or the printed hash), 2032 note 64..95 (exit) or 101..114 (a check or trap) with none; stderr empty 2033 fn gt_qrun s ulong to bool 2034 x = gt_run 31 39 20 21 2035 gt_ps 20 2036 if not gt_slurp 2 2037 gt_failv 97 s 2038 ret false 2039 end 2040 m = get q_n 6 2041 ok = false 2042 if le x 63 2043 ok = or eq m 0 eq m 8 2044 put q_n 27 add get q_n 27 1 2045 end 2046 if and ge x 64 le x 95 2047 ok = eq m 0 2048 put q_n 28 add get q_n 28 1 2049 end 2050 if and ge x 101 le x 114 2051 ok = eq m 0 2052 put q_n 29 add get q_n 29 1 2053 end 2054 if ok 2055 if gt_nil 21 2056 ret true 2057 end 2058 end 2059 gt_failv 97 s 2060 ret false 2061 end 2062 note K SEED STATUS: `ngrand shrink SEED STATUS SCRATCH/kbin SCRATCH/ngrun` exits 0 with empty stderr; 2063 note kbin is accepted (whole ACCEPT line), ngrun on it exits STATUS, it is smaller than the unit of SEED, 2064 note and `ngrand tape SCRATCH/kbin.tape` gives kbin again 2065 fn gt_kcase to void 2066 s = gt_dec 2067 st = gt_dec 2068 x = gt_kspawn s st 2069 if or ne x 0 not gt_nil 21 2070 gt_failv 99 x 2071 ret 2072 end 2073 if not gt_qacc s 42 2074 ret 2075 end 2076 n1 = get q_n 5 2077 x = gt_run 31 42 41 21 2078 if ne x st 2079 gt_failv 101 x 2080 ret 2081 end 2082 x = gt_rgen s 0 39 2083 gt_ps 39 2084 if or ne x 0 not gt_slurp 2 2085 gt_failv 93 s 2086 ret 2087 end 2088 if ge n1 get q_n 6 2089 gt_failv 100 n1 2090 ret 2091 end 2092 x = gt_rgen 0 1 41 2093 if or ne x 0 not gt_fcmp 41 42 2094 gt_fail0 107 2095 end 2096 end 2097 fn gt_kspawn s ulong st ulong to ulong 2098 gt_ps 37 2099 fi = gt_rdonly 2100 gt_aclr 2101 gt_ps 37 2102 gt_apa 2103 gt_aw 43 2104 gt_pclr 2105 gt_pnum s 2106 gt_apa 2107 gt_pclr 2108 gt_pnum st 2109 gt_apa 2110 gt_ps 42 2111 gt_apa 2112 gt_ps 31 2113 gt_apa 2114 gt_ps 20 2115 fo = gt_wronly 2116 gt_ps 21 2117 fe = gt_wronly 2118 ret gt_spawn fi fo fe 2119 end 2120 note ---- generated inputs (IR.md s12 capacities) ------------------------------------------------ 2121 note write generator [a, b) of cases (messages 72..81) to scratch word w, after "@ng ir-copy\n" when 2122 note pre; false for an unknown name 2123 fn gt_gen a ulong b ulong pre bool w ulong to bool 2124 g = gt_gid a b 2125 if eq g 0 2126 ret false 2127 end 2128 n = gt_gbuild g 2129 gt_ps w 2130 fd = gt_wronly 2131 if lt fd 0 2132 ret false 2133 end 2134 ok = true 2135 if pre 2136 ok = eq write fd q_irc 0 len q_irc long len q_irc 2137 end 2138 if ok 2139 ok = gt_wrfd fd n 2140 end 2141 if and ok eq g 73 2142 ok = eq write fd q_hex 10 1 1 2143 end 2144 r = fclose fd 2145 ret ok 2146 end 2147 fn gt_gid a ulong b ulong to ulong 2148 for i ulong 10 2149 if gt_gis a b add 72 i 2150 ret add 72 i 2151 end 2152 end 2153 ret 0 2154 end 2155 fn gt_gis a ulong b ulong g ulong to bool 2156 k = ulong get q_ml g 2157 if ne sub b a k 2158 ret false 2159 end 2160 m = ulong get q_mo g 2161 for j ulong k bound 64 2162 if ne get q_cs add a j get q_m add m j 2163 ret false 2164 end 2165 end 2166 ret true 2167 end 2168 fn gt_wrfd fd int n ulong to bool 2169 o = ulong 0 2170 while lt o n bound `16777217` 2171 x = write fd q_b1 o sub n o 2172 if le x 0 2173 ret false 2174 end 2175 o = add o ulong x 2176 end 2177 ret true 2178 end 2179 note build generator g into b1; its length 2180 fn gt_gbuild g ulong to ulong 2181 if le g 73 2182 ret gt_gfull 2183 end 2184 if eq g 74 2185 ret gt_gtyp 2186 end 2187 put q_n 26 0 2188 gt_gs 53 2189 if eq g 75 2190 gt_gty 65536 2191 end 2192 if eq g 76 2193 gt_gty 65537 2194 end 2195 if eq g 77 2196 gt_ggl 2197 end 2198 if eq g 78 2199 gt_gfn 2200 end 2201 if eq g 79 2202 gt_gbl 2203 end 2204 if eq g 80 2205 gt_gfp 2206 end 2207 if eq g 81 2208 gt_gbp 2209 end 2210 ret get q_n 26 2211 end 2212 fn gt_gc c ulong to void 2213 n = get q_n 26 2214 put q_b1 n uchar c 2215 put q_n 26 add n 1 2216 end 2217 fn gt_gs i ulong to void 2218 s = ulong get q_mo i 2219 for j ulong ulong get q_ml i bound 128 2220 gt_gc ulong get q_m add s j 2221 end 2222 end 2223 fn gt_gn v ulong to void 2224 if ge v 10 2225 gt_gn div v 10 2226 end 2227 gt_gc add 48 rem v 10 2228 end 2229 fn gt_zero n ulong to void 2230 for j ulong n bound `16777216` 2231 put q_b1 j 0 2232 end 2233 end 2234 fn gt_put4 p ulong v ulong to void 2235 for j ulong 4 2236 put q_b1 add p j uchar and shr v mul j 8 255 2237 end 2238 end 2239 note the 24-byte header (s3) 2240 fn gt_ghdr to void 2241 s = ulong get q_mo 83 2242 for j ulong ulong get q_ml 83 bound 64 2243 put q_b1 j get q_m add s j 2244 end 2245 put q_b1 7 9 2246 s = ulong get q_mo 84 2247 for j ulong ulong get q_ml 84 bound 64 2248 put q_b1 add 8 j get q_m add s j 2249 end 2250 end 2251 note full: a unit of exactly `16777216` bytes (one ARRAY u8 type, one global of `16777166` data bytes, no 2252 note functions); over is full and one byte more 2253 fn gt_gfull to ulong 2254 gt_zero len q_b1 2255 gt_ghdr 2256 gt_put4 24 1 2257 put q_b1 28 2 2258 gt_put4 29 2 2259 gt_put4 33 `16777166` 2260 gt_put4 37 1 2261 gt_put4 41 32 2262 put q_b1 45 1 2263 ret len q_b1 2264 end 2265 note types: 65537 populated ARRAY u8 type entries, no globals, no functions 2266 fn gt_gtyp to ulong 2267 n = add ulong 36 mul ulong 65537 9 2268 gt_zero n 2269 gt_ghdr 2270 gt_put4 24 65537 2271 for j ulong 65537 2272 p = add 28 mul j 9 2273 put q_b1 p 2 2274 gt_put4 add p 1 2 2275 gt_put4 add p 5 add j 1 2276 end 2277 ret n 2278 end 2279 fn gt_gty k ulong to void 2280 for j ulong k bound 65537 2281 gt_gs 54 2282 gt_gn add j 32 2283 gt_gs 55 2284 gt_gn add j 1 2285 gt_gc 10 2286 end 2287 end 2288 fn gt_ggl to void 2289 gt_gs 56 2290 for j ulong 65537 2291 gt_gs 57 2292 gt_gn j 2293 gt_gs 58 2294 end 2295 end 2296 fn gt_gfn to void 2297 for j ulong 65537 2298 gt_gs 59 2299 gt_gn j 2300 gt_gs 60 2301 end 2302 end 2303 fn gt_gbl to void 2304 gt_gs 61 2305 gt_gs 62 2306 for i ulong 65536 2307 j = add i 1 2308 gt_gs 63 2309 gt_gn j 2310 gt_gs 64 2311 gt_gn j 2312 gt_gs 65 2313 gt_gn j 2314 gt_gc 10 2315 end 2316 gt_gs 71 2317 end 2318 fn gt_gfp to void 2319 gt_gs 66 2320 for i ulong 65537 2321 gt_gs 64 2322 gt_gn add i 1 2323 gt_gs 67 2324 end 2325 gt_gs 68 2326 end 2327 fn gt_gbp to void 2328 gt_gs 61 2329 gt_gs 69 2330 for i ulong 65536 2331 gt_gs 64 2332 gt_gn add i 2 2333 gt_gs 67 2334 end 2335 gt_gs 70 2336 end 2337 note read up to m bytes of fd into b1 (k 1) or b2 (k 2); the count (short only at end of file) 2338 fn gt_rdn fd int k ulong m ulong to ulong 2339 n = ulong 0 2340 while lt n m bound `1048577` 2341 x = long 0 2342 if eq k 1 2343 x = read fd q_b1 n sub m n 2344 else 2345 x = read fd q_b2 n sub m n 2346 end 2347 if le x 0 2348 ret n 2349 end 2350 n = add n ulong x 2351 end 2352 ret n 2353 end 2354 note scratch files w1 and w2 hold the same bytes (any size) 2355 fn gt_fcmp w1 ulong w2 ulong to bool 2356 gt_ps w1 2357 f1 = gt_rdonly 2358 gt_ps w2 2359 f2 = gt_rdonly 2360 ok = and ge f1 0 ge f2 0 2361 dn = false 2362 while and ok not dn bound 4096 2363 a = gt_rdn f1 1 `1048576` 2364 b = gt_rdn f2 2 `1048576` 2365 if ne a b 2366 ok = false 2367 else 2368 if eq a 0 2369 dn = true 2370 end 2371 ok = gt_eqn a 2372 end 2373 end 2374 gt_fclo f1 2375 gt_fclo f2 2376 ret ok 2377 end 2378 fn gt_eqn n ulong to bool 2379 for j ulong n bound `1048576` 2380 if ne get q_b1 j get q_b2 j 2381 ret false 2382 end 2383 end 2384 ret true 2385 end 2386 note ---- the pin check of ngbuild ---------------------------------------------------------------- 2387 note ng.units with its first digest digit changed: ngbuild build must refuse it (exit 3, "ngbuild: sha256 2388 note mismatch seed/ng/src/ir.om have ") before it runs the compiler (scratch nope, 2389 note which does not exist) or writes its output (scratch must) 2390 fn gt_badpin to void 2391 put q_n 10 add get q_n 10 1 2392 gt_pr 30 2393 if not gt_slurp 1 2394 gt_bpf 512 2395 ret 2396 end 2397 n = get q_n 5 2398 for j ulong n bound `16777216` 2399 put sh_dat j get q_b1 j 2400 end 2401 sh_all n 2402 gt_xclr 2403 gt_xs 46 2404 for j ulong 32 2405 x = ulong get sh_dig j 2406 gt_xc ulong get q_hex shr x 4 2407 gt_xc ulong get q_hex and x 15 2408 end 2409 gt_xc 10 2410 gt_pr 12 2411 if not gt_slurp 1 2412 gt_bpf 512 2413 ret 2414 end 2415 if eq get q_b1 0 48 2416 put q_b1 0 49 2417 else 2418 put q_b1 0 48 2419 end 2420 gt_ps 27 2421 if not gt_spill get q_n 5 2422 gt_bpf 512 2423 ret 2424 end 2425 gt_ps 29 2426 r = unlink q_pa 0 get q_n 0 2427 gt_aclr 2428 gt_ps 1 2429 gt_apa 2430 gt_aw 17 2431 gt_ps 28 2432 gt_apa 2433 gt_ps 27 2434 gt_apa 2435 gt_ps 29 2436 gt_apa 2437 gt_ps 27 2438 fi = gt_rdonly 2439 gt_ps 20 2440 fo = gt_wronly 2441 gt_ps 21 2442 fe = gt_wronly 2443 x = gt_spawn fi fo fe 2444 if ne x 3 2445 gt_bpf x 2446 ret 2447 end 2448 if not gt_xok 21 2449 gt_bpf x 2450 ret 2451 end 2452 gt_ps 29 2453 fd = gt_rdonly 2454 if ge fd 0 2455 gt_fclo fd 2456 gt_bpf x 2457 end 2458 end 2459 fn gt_bpf x ulong to void 2460 put q_n 11 add get q_n 11 1 2461 gt_say 0 2462 gt_say 41 2463 gt_say 42 2464 gt_c 32 2465 gt_num x 2466 gt_nl 2467 end 2468 note one case line at the cursor; returns false at the end of the file 2469 fn gt_case to bool 2470 if ge get q_n 8 get q_n 7 2471 ret false 2472 end 2473 put q_n 13 get q_n 8 2474 put q_n 12 0 2475 k = gt_pk 2476 gt_adv 2477 if eq k 35 2478 gt_eol 2479 ret true 2480 end 2481 if eq k 10 2482 ret true 2483 end 2484 put q_n 10 add get q_n 10 1 2485 if eq k 84 2486 gt_tcase 2487 else 2488 if eq k 83 2489 gt_scase 2490 else 2491 if or eq k 77 or eq k 67 eq k 65 2492 gt_mcase k 2493 else 2494 if eq k 82 2495 gt_rcase 2496 else 2497 if eq k 68 2498 gt_dcase 2499 else 2500 if eq k 71 2501 gt_gcase 2502 else 2503 gt_case2 k 2504 end 2505 end 2506 end 2507 end 2508 end 2509 end 2510 if ne get q_n 12 0 2511 put q_n 11 add get q_n 11 1 2512 end 2513 gt_eol 2514 ret true 2515 end 2516 note ---- negative controls of the gate ---------------------------------------------------------------- 2517 note run the first T line of cases again with a broken expectation (mode 1 exit + 1, mode 2 offset + 1, 2518 note mode 3 a round-trip text the fixture does not equal); the case must fail 2519 fn gt_ctl md ulong to void 2520 gt_fkclr 2521 put q_n 14 1 2522 put q_n 12 0 2523 put q_n 8 0 2524 while ne gt_pk 84 bound `1048576` 2525 gt_eol 2526 end 2527 put q_n 13 get q_n 8 2528 gt_adv 2529 a = gt_name 2530 b = get q_n 19 2531 ex = gt_dec 2532 off = gt_dec 2533 if eq md 1 2534 s = gt_asm a b 2535 gt_ps 23 2536 gt_verdict 2 add ex 1 off 2537 end 2538 if eq md 2 2539 gt_ctl2 a b 2540 end 2541 if eq md 3 2542 gt_ctl3 a b 2543 end 2544 put q_n 14 0 2545 if eq get q_fk gt_ctlm md 0 2546 put q_n 11 add get q_n 11 1 2547 gt_say 0 2548 gt_say 14 2549 gt_num md 2550 gt_say 85 2551 gt_nl 2552 end 2553 end 2554 note the check each control must trip: 1 ngcheck exit, 2 refusal line, 3 round trip text 2555 fn gt_ctlm md ulong to ulong 2556 if eq md 1 2557 ret 7 2558 end 2559 if eq md 2 2560 ret 38 2561 end 2562 ret 6 2563 end 2564 fn gt_fkclr to void 2565 for j ulong 256 2566 put q_fk j 0 2567 end 2568 end 2569 note mode 2 uses the first refusal line (exit != 0) 2570 fn gt_ctl2 a ulong b ulong to void 2571 put q_n 8 0 2572 ex = ulong 0 2573 a2 = ulong 0 2574 b2 = ulong 0 2575 off = ulong 0 2576 while eq ex 0 bound 4096 2577 while ne gt_pk 84 bound `1048576` 2578 gt_eol 2579 end 2580 gt_adv 2581 a2 = gt_name 2582 b2 = get q_n 19 2583 ex = gt_dec 2584 off = gt_dec 2585 end 2586 s = gt_asm a2 b2 2587 gt_ps 23 2588 gt_verdict 2 ex add off 1 2589 end 2590 fn gt_ctl3 a ulong b ulong to void 2591 s = gt_asm a b 2592 gt_ps 23 2593 x = gt_tool 4 24 2594 gt_ps 24 2595 s = gt_slurp 1 2596 n = get q_n 5 2597 put q_b1 sub n 2 uchar xor get q_b1 sub n 2 1 2598 gt_pfix a b 2599 s = gt_slurp 2 2600 if not gt_same 2601 gt_fail0 6 2602 end 2603 end 2604 note ---- native safe-host oracle and classified refusal controls -------------------------------- 2605 fn gt_hinit to void 2606 put q_hs 1 ulong getpid 2607 put q_hs 2 0 2608 put q_henv 0 1 2609 put q_henv 1 0 2610 put q_henv 2 uchar len q_hent 2611 put q_henv 3 0 2612 for j ulong len q_hent bound 60 2613 put q_henv add j 4 get q_hent j 2614 end 2615 end 2616 fn gt_hroot kind ulong mode ulong to void 2617 gt_ps 68 2618 gt_pnum kind 2619 gt_pc 45 2620 gt_pnum mode 2621 gt_pc 45 2622 gt_pnum get q_hs 1 2623 n = get q_n 0 2624 base = mul kind 8192 2625 for j ulong n bound 8192 2626 put q_hroot add base j get q_pa j 2627 end 2628 put q_hrlen kind n 2629 put q_hmade kind 0 2630 end 2631 fn gt_hpath kind ulong to void 2632 gt_pclr 2633 base = mul kind 8192 2634 for j ulong get q_hrlen kind bound 8192 2635 gt_pc ulong get q_hroot add base j 2636 end 2637 end 2638 fn gt_harg kind ulong to void 2639 gt_hpath kind 2640 gt_apa 2641 end 2642 fn gt_habsent kind ulong to bool 2643 gt_hpath kind 2644 k = faccess q_pa 0 get q_n 0 0 2645 if ne k -2 2646 ret false 2647 end 2648 put q_hmade kind 1 2649 ret true 2650 end 2651 fn gt_hclean kind ulong to void 2652 if eq get q_hmade kind 0 2653 ret 2654 end 2655 gt_hpath kind 2656 gt_pc 47 2657 gt_pw 69 2658 k = rmdir q_pa 0 get q_n 0 2659 gt_hpath kind 2660 k = rmdir q_pa 0 get q_n 0 2661 put q_hmade kind 0 2662 end 2663 fn gt_hoptarg dash bool to void 2664 gt_pclr 2665 if dash 2666 for j ulong len q_hdash 2667 gt_pc ulong get q_hdash j 2668 end 2669 else 2670 for j ulong len q_hopt 2671 gt_pc ulong get q_hopt j 2672 end 2673 end 2674 gt_apa 2675 end 2676 fn gt_hnative to ulong 2677 gt_ps 23 2678 fi = gt_rdonly 2679 gt_aclr 2680 gt_ps 63 2681 gt_apa 2682 gt_ps 64 2683 gt_apa 2684 gt_harg 0 2685 gt_ps 35 2686 fo = gt_wronly 2687 gt_ps 36 2688 fe = gt_wronly 2689 ret gt_spawn fi fo fe 2690 end 2691 fn gt_hrun unit ulong args bool to ulong 2692 gt_ps 23 2693 fi = gt_rdonly 2694 gt_aclr 2695 gt_ps 31 2696 gt_apa 2697 gt_ps unit 2698 gt_apa 2699 gt_hoptarg false 2700 gt_harg 1 2701 if args 2702 gt_hoptarg true 2703 gt_ps 64 2704 gt_apa 2705 gt_harg 0 2706 end 2707 gt_ps 20 2708 fo = gt_wronly 2709 gt_ps 21 2710 fe = gt_wronly 2711 ret gt_spawn fi fo fe 2712 end 2713 fn gt_hgen mode ulong to ulong 2714 gt_ps 23 2715 fi = gt_rdonly 2716 gt_aclr 2717 gt_ps 66 2718 gt_apa 2719 gt_anum mode 2720 gt_ps 67 2721 fo = gt_wronly 2722 gt_ps 21 2723 fe = gt_wronly 2724 ret gt_spawn fi fo fe 2725 end 2726 fn gt_hword mode ulong to ulong 2727 if eq mode 115 2728 ret 107 2729 end 2730 if eq mode 116 2731 ret 235 2732 end 2733 if eq mode 117 2734 ret 168 2735 end 2736 if eq mode 118 2737 ret 104 2738 end 2739 if or eq mode 119 eq mode 219 2740 ret 110 2741 end 2742 if eq mode 120 2743 ret 135 2744 end 2745 if eq mode 121 2746 ret 142 2747 end 2748 if eq mode 215 2749 ret 233 2750 end 2751 if or eq mode 324 eq mode 325 2752 ret 124 2753 end 2754 if and ge mode 236 le mode 240 2755 ret mode 2756 end 2757 ret 162 2758 end 2759 fn gt_herr code ulong word ulong to bool 2760 gt_xclr 2761 for j ulong len q_hmsg 2762 gt_xc ulong get q_hmsg j 2763 end 2764 gt_xnum code 2765 for j ulong len q_hword 2766 gt_xc ulong get q_hword j 2767 end 2768 gt_xnum word 2769 for j ulong len q_hat 2770 gt_xc ulong get q_hat j 2771 end 2772 m = get q_n 21 2773 gt_ps 21 2774 if not gt_slurp 1 2775 ret false 2776 end 2777 n = get q_n 5 2778 if or le n add m 1 gt n add m 21 2779 ret false 2780 end 2781 for j ulong m bound 128 2782 if ne get q_b1 j get q_ex j 2783 ret false 2784 end 2785 end 2786 if ne get q_b1 sub n 1 10 2787 ret false 2788 end 2789 for j ulong sub sub n m 1 bound 20 2790 c = get q_b1 add m j 2791 if or lt c 48 gt c 57 2792 ret false 2793 end 2794 end 2795 ret true 2796 end 2797 fn gt_hpolicy mode ulong code ulong to void 2798 x = gt_hgen mode 2799 if ne x 0 2800 gt_failv 87 x 2801 ret 2802 end 2803 if not gt_nil 21 2804 gt_fail0 90 2805 ret 2806 end 2807 gt_ps 67 2808 x = gt_tool 2 20 2809 if ne x 0 2810 gt_failv 7 x 2811 ret 2812 end 2813 gt_hroot 1 mode 2814 if not gt_habsent 1 2815 gt_fail0 19 2816 ret 2817 end 2818 x = gt_hrun 67 false 2819 gt_hclean 1 2820 if ne x code 2821 gt_failv 87 x 2822 ret 2823 end 2824 if not gt_nil 20 2825 gt_fail0 89 2826 ret 2827 end 2828 if not gt_herr code gt_hword mode 2829 gt_fail0 90 2830 ret 2831 end 2832 put q_hs 2 add get q_hs 2 1 2833 end 2834 fn gt_hstats to void 2835 gt_ps 36 2836 if not gt_slurp 1 2837 gt_fail0 90 2838 ret 2839 end 2840 n = get q_n 5 2841 if or lt n len q_hstat gt n 128 2842 gt_fail0 90 2843 ret 2844 end 2845 for j ulong len q_hstat 2846 if ne get q_b1 j get q_hstat j 2847 gt_fail0 90 2848 ret 2849 end 2850 end 2851 if eq get q_n 14 0 2852 gt_say 26 2853 for j ulong n bound 128 2854 gt_c ulong get q_b1 j 2855 end 2856 end 2857 end 2858 fn gt_hbody to void 2859 if not gt_build 30 62 63 2860 gt_fail0 1 2861 ret 2862 end 2863 if not gt_build 30 65 66 2864 gt_fail0 1 2865 ret 2866 end 2867 gt_hinit 2868 gt_hroot 0 0 2869 gt_hroot 1 0 2870 if not gt_habsent 0 2871 gt_fail0 19 2872 ret 2873 end 2874 if not gt_habsent 1 2875 gt_fail0 19 2876 ret 2877 end 2878 put q_hs 0 1 2879 x = gt_hnative 2880 if ne x 7 2881 gt_failv 87 x 2882 ret 2883 end 2884 gt_ps 64 2885 x = gt_tool 2 20 2886 if ne x 0 2887 gt_failv 7 x 2888 ret 2889 end 2890 x = gt_hrun 64 true 2891 if ne x 7 2892 gt_failv 87 x 2893 ret 2894 end 2895 if not gt_fcmp 20 35 2896 gt_fail0 89 2897 ret 2898 end 2899 if not gt_nil 21 2900 gt_fail0 90 2901 ret 2902 end 2903 gt_hstats 2904 gt_hclean 0 2905 gt_hclean 1 2906 for j ulong 7 2907 gt_hpolicy add j 115 add j 115 2908 if ne get q_n 12 0 2909 ret 2910 end 2911 end 2912 gt_hpolicy 215 115 2913 gt_hpolicy 219 119 2914 gt_hpolicy 319 119 2915 gt_hpolicy 324 115 2916 gt_hpolicy 325 115 2917 gt_hpolicy 236 115 2918 gt_hpolicy 237 115 2919 gt_hpolicy 238 120 2920 gt_hpolicy 239 115 2921 gt_hpolicy 240 115 2922 if eq get q_n 14 0 2923 for j ulong len q_hpol 2924 gt_c ulong get q_hpol j 2925 end 2926 gt_num get q_hs 2 2927 gt_nl 2928 end 2929 end 2930 fn gt_hosts to void 2931 put q_n 12 0 2932 gt_hbody 2933 put q_hs 0 0 2934 gt_hclean 0 2935 gt_hclean 1 2936 put q_n 10 add get q_n 10 1 2937 if ne get q_n 12 0 2938 put q_n 11 add get q_n 11 1 2939 end 2940 end 2941 fn gt_hatablebody to void 2942 if not gt_build 30 60 61 2943 gt_fail0 1 2944 ret 2945 end 2946 gt_pr 70 2947 fi = gt_rdonly 2948 gt_aclr 2949 gt_ps 61 2950 gt_apa 2951 gt_pr 13 2952 gt_apa 2953 gt_ps 20 2954 fo = gt_wronly 2955 gt_ps 21 2956 fe = gt_wronly 2957 x = gt_spawn fi fo fe 2958 if ne x 0 2959 gt_failv 87 x 2960 ret 2961 end 2962 if not gt_nil 21 2963 gt_fail0 90 2964 ret 2965 end 2966 gt_ps 20 2967 if not gt_slurp 1 2968 gt_fail0 89 2969 ret 2970 end 2971 if ne get q_n 5 len q_hatab 2972 gt_fail0 89 2973 ret 2974 end 2975 for j ulong len q_hatab 2976 if ne get q_b1 j get q_hatab j 2977 gt_fail0 89 2978 ret 2979 end 2980 end 2981 end 2982 fn gt_hatable to void 2983 put q_n 12 0 2984 gt_hatablebody 2985 put q_n 10 add get q_n 10 1 2986 if ne get q_n 12 0 2987 put q_n 11 add get q_n 11 1 2988 end 2989 end 2990 note Decimal argv for the independent conversion oracle. 2991 2992 fn gt_anum v ulong to void 2993 gt_pclr 2994 gt_pnum v 2995 gt_apa 2996 end 2997 fn gt_ivrun s uint t uint j uint to ulong 2998 gt_ps 23 2999 fi = gt_rdonly 3000 gt_aclr 3001 gt_ps 58 3002 gt_apa 3003 gt_anum ulong s 3004 gt_anum ulong t 3005 gt_anum ulong j 3006 gt_ps 59 3007 fo = gt_wronly 3008 gt_ps 21 3009 fe = gt_wronly 3010 ret gt_spawn fi fo fe 3011 end 3012 fn gt_ivbody to void 3013 if not gt_build 30 57 58 3014 gt_fail0 1 3015 ret 3016 end 3017 for si uint 6 3018 s = add si 2 3019 t0 = uint 6 3020 nt = uint 4 3021 nj = uint 8 3022 if ge si 4 3023 s = add si 9 3024 t0 = 2 3025 nt = 8 3026 nj = 16 3027 end 3028 for ti uint nt bound 8 3029 for j uint nj bound 16 3030 x = gt_ivrun s add ti t0 j 3031 if and ne x 0 ne x 105 3032 gt_failv 87 x 3033 ret 3034 end 3035 gt_ps 59 3036 z = gt_tool 2 20 3037 if ne z 0 3038 gt_failv 7 z 3039 ret 3040 end 3041 y = gt_run 31 59 20 21 3042 if ne x y 3043 gt_failv 87 y 3044 ret 3045 end 3046 if not gt_nil 20 3047 gt_fail0 89 3048 ret 3049 end 3050 if not gt_nil 21 3051 gt_fail0 90 3052 ret 3053 end 3054 end 3055 end 3056 end 3057 end 3058 fn gt_intcv to void 3059 put q_n 12 0 3060 gt_ivbody 3061 put q_n 10 add get q_n 10 1 3062 if ne get q_n 12 0 3063 put q_n 11 add get q_n 11 1 3064 end 3065 end 3066 fn gt_float to void 3067 put q_n 12 0 3068 gt_fbody 3069 put q_n 10 add get q_n 10 1 3070 if ne get q_n 12 0 3071 put q_n 11 add get q_n 11 1 3072 end 3073 end 3074 note Native omc is the independent float oracle: it emits a unit with expected raw-bit checks. 3075 fn gt_fbody to void 3076 if not gt_build 30 54 55 3077 gt_fail0 1 3078 ret 3079 end 3080 x = gt_run 55 23 56 21 3081 if ne x 0 3082 gt_failv 87 x 3083 ret 3084 end 3085 gt_ps 56 3086 x = gt_tool 2 20 3087 if ne x 0 3088 gt_failv 7 x 3089 ret 3090 end 3091 x = gt_run 31 56 20 21 3092 if ne x 0 3093 gt_failv 87 x 3094 ret 3095 end 3096 if not gt_nil 20 3097 gt_fail0 89 3098 end 3099 if not gt_nil 21 3100 gt_fail0 90 3101 end 3102 end 3103 note a tool mutant id (gt_msel): rebuild ngcheck with it and rerun every case quietly; it is killed when 3104 note its named check fails at least once (1 ngcheck exit, 2 witness line, 3 refusal line, 4 run exits 3105 note differ: x-fuel ends instead of trapping); otherwise 3106 note the gate fails. The correct ngcheck is rebuilt afterwards. A pattern that does not occur exactly 3107 note once in its source fails "FAIL mutant ...: pattern not unique, matches=K". 3108 fn gt_mrun id ulong to void 3109 c10 = get q_n 10 3110 c11 = get q_n 11 3111 put q_n 20 id 3112 put q_n 30 1 3113 ok = gt_mbuild id 3114 put q_n 20 0 3115 if not ok 3116 put q_n 11 add c11 1 3117 gt_say 0 3118 gt_say gt_mlab id 3119 if ne get q_n 30 1 3120 gt_say 108 3121 gt_num get q_n 30 3122 else 3123 gt_say 24 3124 end 3125 gt_nl 3126 ret 3127 end 3128 gt_fkclr 3129 put q_n 14 1 3130 put q_n 11 0 3131 put q_n 8 0 3132 while gt_case bound 65536 3133 end 3134 if or and ge id 20 le id 23 or and ge id 25 le id 26 and ge id 28 le id 31 3135 gt_float 3136 end 3137 if eq id 24 3138 gt_intcv 3139 end 3140 if eq id 27 3141 gt_hosts 3142 end 3143 k = get q_n 11 3144 nk = get q_fk gt_mnam id 3145 put q_n 14 0 3146 put q_n 10 c10 3147 put q_n 11 c11 3148 if not gt_mbuild id 3149 put q_n 11 add c11 1 3150 gt_say 0 3151 gt_say 1 3152 gt_nl 3153 ret 3154 end 3155 if eq nk 0 3156 put q_n 11 add c11 1 3157 gt_say 0 3158 gt_say gt_mlab id 3159 gt_say 47 3160 gt_num k 3161 gt_nl 3162 ret 3163 end 3164 gt_say 26 3165 gt_say gt_mlab id 3166 gt_say 25 3167 gt_num nk 3168 gt_nl 3169 end 3170 fn gt_mbuild id ulong to bool 3171 if ge id 20 3172 ret gt_build 30 32 31 3173 end 3174 if eq id 18 3175 ret gt_build 30 32 31 3176 end 3177 if ge id 17 3178 ret gt_bng 3179 end 3180 if ge id 9 3181 ret gt_build 30 32 31 3182 end 3183 if ge id 6 3184 ret gt_bng 3185 end 3186 if eq id 4 3187 ret gt_build 30 32 31 3188 end 3189 if eq id 5 3190 ret gt_build 30 38 37 3191 end 3192 ret gt_build 6 8 2 3193 end 3194 fn gt_mlab id ulong to ulong 3195 if ge id 27 3196 ret add 142 sub id 27 3197 end 3198 if ge id 20 3199 ret add 135 sub id 20 3200 end 3201 if ge id 18 3202 ret add 115 id 3203 end 3204 if eq id 17 3205 ret 131 3206 end 3207 if ge id 9 3208 ret add 114 id 3209 end 3210 if ge id 6 3211 ret add 109 id 3212 end 3213 if eq id 5 3214 ret 102 3215 end 3216 if eq id 1 3217 ret 22 3218 end 3219 if eq id 2 3220 ret 43 3221 end 3222 if eq id 4 3223 ret 86 3224 end 3225 ret 44 3226 end 3227 fn gt_mnam id ulong to ulong 3228 if ge id 20 3229 ret 87 3230 end 3231 if eq id 19 3232 ret 132 3233 end 3234 if eq id 18 3235 ret 120 3236 end 3237 if eq id 17 3238 ret 112 3239 end 3240 if or eq id 9 or eq id 12 eq id 13 3241 ret 87 3242 end 3243 if ge id 9 3244 ret 118 3245 end 3246 if eq id 8 3247 ret 112 3248 end 3249 if ge id 6 3250 ret 110 3251 end 3252 if eq id 5 3253 ret 95 3254 end 3255 if eq id 1 3256 ret 7 3257 end 3258 if eq id 2 3259 ret 37 3260 end 3261 if eq id 4 3262 ret 87 3263 end 3264 ret 38 3265 end 3266 note ---- PART (ham/ngrun-gate-part) -------------------------------------------------------------- 3267 note gate-ir OMC SCRATCH N/K runs part N of K (1 <= N <= K <= 64). The full gate is one ordered walk of 3268 note items: the ngcheck table, the bad pin, each case line that is not a comment or blank line, the 3269 note float, intcv, host table and host policy groups, the three negative controls and the 31 mutants. 3270 note A part runs item i (0-based) only when rem i K + 1 = N; the tools are built in every part, and a 3271 note mutant still reruns every case. A part ends "NGIRGATE PASS part=N/K items=I cases=C" (exit 0) or 3272 note the FAIL line followed by " part=N/K" (exit 1). 3273 note gate-ir OMC SCRATCH parts K N1 N2 ... is the partition proof inside the gate: the same walk 3274 note through the same selector, with nothing built and nothing run. Every item's part must be listed 3275 note exactly once, so a missing part or a repeated part fails ("FAIL parts item=I selected=C" per 3276 note item, then "NGIRGATE PARTS FAIL failed=F cases=C", exit 1). Otherwise it prints each part's 3277 note "part=N items=I cases=C" and "NGIRGATE PARTS PASS K=K items=I cases=C" (exit 0): the items of all 3278 note listed parts are the walk's items, and their cases equal the full gate's cases count. 3279 note A malformed PART prints the usage line and exits 2. Without PART the gate is the full gate, unchanged. 3280 text q_mp "NGIRGATE PASS part=|/| items=|NGIRGATE PARTS PASS K=|FAIL parts item=| selected=|usage: gate-ir OMC SCRATCH [N/K or parts K N...]| part=|part=|NGIRGATE PARTS FAIL failed=|parts|" 3281 global q_mpo uint 16 3282 global q_mpl uint 16 3283 global q_pg uchar 64 3284 note q_pt: 0 K (0 = full gate), 1 N, 2 items walked, 3 items selected (proof: listed selections), 3285 note 4 proof mode, 5 cases selected (proof), 6 cases walked 3286 global q_pt ulong 8 3287 note proof mode: q_pl[p] times part p is listed; q_pi[p] and q_pc[p] the items and cases of part p 3288 global q_pl ulong 65 3289 global q_pi ulong 65 3290 global q_pc ulong 65 3291 fn gt_pinit to void 3292 w = ulong 0 3293 s = ulong 0 3294 for i ulong len q_mp 3295 if eq get q_mp i 124 3296 put q_mpo w uint s 3297 put q_mpl w uint sub i s 3298 w = add w 1 3299 s = add i 1 3300 end 3301 end 3302 end 3303 fn gt_says i ulong to void 3304 s = ulong get q_mpo i 3305 for j ulong ulong get q_mpl i bound 64 3306 gt_c ulong get q_mp add s j 3307 end 3308 end 3309 note the part that owns item i 3310 fn gt_own i ulong to ulong 3311 ret add rem i get q_pt 0 1 3312 end 3313 note the next item of the walk; true when it runs here. cnt: the item adds to the cases count 3314 fn gt_sel cnt bool to bool 3315 i = get q_pt 2 3316 put q_pt 2 add i 1 3317 if cnt 3318 put q_pt 6 add get q_pt 6 1 3319 end 3320 if eq get q_pt 0 0 3321 ret true 3322 end 3323 o = gt_own i 3324 if ne get q_pt 4 0 3325 c = get q_pl o 3326 put q_pi o add get q_pi o 1 3327 put q_pt 3 add get q_pt 3 c 3328 if cnt 3329 put q_pc o add get q_pc o 1 3330 put q_pt 5 add get q_pt 5 c 3331 end 3332 if ne c 1 3333 put q_n 11 add get q_n 11 1 3334 gt_says 4 3335 gt_num i 3336 gt_says 5 3337 gt_num c 3338 gt_nl 3339 end 3340 ret false 3341 end 3342 if ne o get q_pt 1 3343 ret false 3344 end 3345 put q_pt 3 add get q_pt 3 1 3346 ret true 3347 end 3348 note one line of cases under PART: comments and blank lines go to gt_case as in the full gate; a case 3349 note line is one item, skipped to its end when another part owns it 3350 fn gt_pcase to bool 3351 if ge get q_n 8 get q_n 7 3352 ret false 3353 end 3354 k = gt_pk 3355 if or eq k 35 eq k 10 3356 ret gt_case 3357 end 3358 if gt_sel true 3359 ret gt_case 3360 end 3361 gt_eol 3362 ret true 3363 end 3364 note argument i into q_pg; its length, 0 when absent or longer than 63 bytes 3365 fn gt_parg i ulong to ulong 3366 r = argread i q_pg 0 len q_pg 3367 if or lt r 1 gt r 63 3368 ret 0 3369 end 3370 ret ulong r 3371 end 3372 note decimal q_pg[a, b) of 1 or 2 digits; 0 when malformed 3373 fn gt_pdec a ulong b ulong to ulong 3374 if or ge a b gt sub b a 2 3375 ret 0 3376 end 3377 v = ulong 0 3378 for j ulong sub b a bound 2 3379 c = ulong get q_pg add a j 3380 if or lt c 48 gt c 57 3381 ret 0 3382 end 3383 v = add mul v 10 sub c 48 3384 end 3385 ret v 3386 end 3387 note true when q_pg[0, n) is the word "parts" 3388 fn gt_pisw n ulong to bool 3389 s = ulong get q_mpo 10 3390 if ne n ulong get q_mpl 10 3391 ret false 3392 end 3393 for j ulong n bound 8 3394 if ne get q_pg j get q_mp add s j 3395 ret false 3396 end 3397 end 3398 ret true 3399 end 3400 note PART from arguments 3..; false when malformed 3401 fn gt_ppart to bool 3402 n = gt_parg 3 3403 if eq n 0 3404 ret false 3405 end 3406 if eq argcnt 4 3407 sl = ulong 0 3408 for j ulong n bound 64 3409 if eq get q_pg j 47 3410 sl = add j 1 3411 end 3412 end 3413 if eq sl 0 3414 ret false 3415 end 3416 np = gt_pdec 0 sub sl 1 3417 k = gt_pdec sl n 3418 if or eq np 0 or eq k 0 or gt k 64 gt np k 3419 ret false 3420 end 3421 put q_pt 0 k 3422 put q_pt 1 np 3423 ret true 3424 end 3425 if not gt_pisw n 3426 ret false 3427 end 3428 n = gt_parg 4 3429 k = gt_pdec 0 n 3430 if or eq k 0 gt k 64 3431 ret false 3432 end 3433 na = ulong argcnt 3434 if gt na 261 3435 ret false 3436 end 3437 put q_pt 0 k 3438 put q_pt 4 1 3439 for j ulong sub na 5 bound 256 3440 m = gt_parg add j 5 3441 p = gt_pdec 0 m 3442 if or eq p 0 gt p k 3443 ret false 3444 end 3445 put q_pl p add get q_pl p 1 3446 end 3447 ret true 3448 end 3449 note the partition proof's result 3450 fn gt_pdone to int 3451 k = get q_pt 0 3452 for p ulong k bound 64 3453 gt_says 8 3454 gt_num add p 1 3455 gt_says 2 3456 gt_num get q_pi add p 1 3457 gt_say 17 3458 gt_num get q_pc add p 1 3459 gt_nl 3460 end 3461 ok = eq get q_n 11 0 3462 a = get q_pt 3 3463 if ne a get q_pt 2 3464 ok = false 3465 end 3466 a = get q_pt 5 3467 if ne a get q_pt 6 3468 ok = false 3469 end 3470 if ok 3471 gt_says 3 3472 gt_num k 3473 gt_says 2 3474 gt_num get q_pt 2 3475 gt_say 17 3476 gt_num get q_pt 6 3477 gt_nl 3478 ret 0 3479 end 3480 gt_says 9 3481 gt_num get q_n 11 3482 gt_say 17 3483 gt_num get q_pt 5 3484 gt_nl 3485 ret 1 3486 end 3487 fn main to int 3488 gt_init 3489 gt_pinit 3490 if lt argcnt 3 3491 gt_say 18 3492 gt_nl 3493 ret 2 3494 end 3495 if gt argcnt 3 3496 if not gt_ppart 3497 gt_says 6 3498 gt_nl 3499 ret 2 3500 end 3501 end 3502 r = argread 1 q_omc 0 4095 3503 if lt r 1 3504 ret 2 3505 end 3506 put q_n 1 ulong r 3507 r = argread 2 q_scr 0 4094 3508 if lt r 1 3509 ret 2 3510 end 3511 n = ulong r 3512 x = makedir q_scr 0 n 448 3513 if and ne x 0 ne x -17 3514 gt_say 19 3515 gt_nl 3516 ret 2 3517 end 3518 put q_scr n 47 3519 put q_n 2 add n 1 3520 if eq get q_pt 4 0 3521 if not gt_tools 3522 gt_say 0 3523 gt_say 1 3524 gt_nl 3525 ret 3 3526 end 3527 end 3528 if gt_sel false 3529 if not gt_table 3530 put q_n 11 1 3531 gt_say 0 3532 gt_say 2 3533 gt_nl 3534 end 3535 end 3536 gt_pr 14 3537 gt_pw 15 3538 fd = gt_rdonly 3539 if lt fd 0 3540 ret 2 3541 end 3542 k = read fd q_cs 0 len q_cs 3543 r = fclose fd 3544 if le k 0 3545 ret 2 3546 end 3547 put q_n 7 ulong k 3548 if gt_sel true 3549 gt_badpin 3550 end 3551 put q_n 8 0 3552 while gt_pcase bound 65536 3553 end 3554 if gt_sel true 3555 gt_float 3556 end 3557 if gt_sel true 3558 gt_intcv 3559 end 3560 if gt_sel true 3561 gt_hatable 3562 end 3563 if gt_sel true 3564 gt_hosts 3565 end 3566 for md ulong 3 3567 if gt_sel false 3568 gt_ctl add md 1 3569 end 3570 end 3571 for id ulong 34 3572 if gt_sel false 3573 gt_mrun add id 1 3574 end 3575 end 3576 if ne get q_pt 4 0 3577 ret gt_pdone 3578 end 3579 f = get q_n 11 3580 if eq f 0 3581 if eq get q_pt 0 0 3582 gt_say 15 3583 gt_num get q_n 10 3584 gt_nl 3585 ret 0 3586 end 3587 gt_says 0 3588 gt_num get q_pt 1 3589 gt_says 1 3590 gt_num get q_pt 0 3591 gt_says 2 3592 gt_num get q_pt 3 3593 gt_say 17 3594 gt_num get q_n 10 3595 gt_nl 3596 ret 0 3597 end 3598 gt_say 16 3599 gt_num f 3600 gt_say 17 3601 gt_num get q_n 10 3602 if ne get q_pt 0 0 3603 gt_says 7 3604 gt_num get q_pt 1 3605 gt_says 1 3606 gt_num get q_pt 0 3607 end 3608 gt_nl 3609 ret 1 3610 end