interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / ng / gate-ir.om

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