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 / front / gate-front-ir.om

1553 lines · 31957 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/front/gate-front-ir.om: the ΩIR emission gate of ng-front (Hive NG M1). Owner: ng-front lane.
3note Handwritten seeded Omega, program mode, Linux AArch64. The child and file helpers follow
4note seed/ng/gate-ir.om; seed/ng/sha256.om supplies sh_dat, sh_all and sh_dig.
5note Build: cat seed/ng/sha256.om seed/ng/front/gate-front-ir.om | seed/out/omc > gate-front-ir
6note Run from the repository root: gate-front-ir OMC OMC_SHA256 SCRATCH CASES
7note OMC the oracle compiler; its sha256 must be OMC_SHA256 (64 lowercase hex) or nothing runs (INVALID)
8note SCRATCH a new directory (created 0700; an existing one is INVALID)
9note CASES lines `run NAME SRC`, `refuse NAME SRC` or `host NAME SRC C` (SRC a path from the repository
10note root, C a decimal exit); lines starting
11note with # and blank lines are skipped
12note 1. OMC builds ng (the units of seed/ng/ng.units concatenated in order, so a stage unit such as src/a64.om
13note comes with the list), ngcheck (seed/ng/sha256.om, seed/ng/ngcheck.om) and ngrun (seed/ng/src/ir.om,
14note seed/ng/ngrun.om); a failed build is exit 3. The mutants must occur exactly once in all the units.
15note 2. run: OMC compiles SRC and the binary runs (empty stdin). ng reads `@ng front-ir` then SRC and must exit
16note 0; ngcheck must exit 0 on its stdout with a line starting "ACCEPT "; ngrun runs that ΩIR. The exit
17note status and the stdout of ngrun must equal the OMC binary's (stderr is not compared: the bench kernels
18note write their timing there; a trap is exit 100 + code on both sides).
19note refuse: OMC refuses SRC (exit not 0); ng in front-ir mode exits with the same code and the same stderr
20note bytes and writes no stdout (fe_check is the refusal path of front-ir).
21note host: a host-word fixture. OMC compiles SRC and the binary runs (empty stdin, the repository root as its
22note working directory: the host fixtures name only empty or /dev/null paths and invalid descriptors). ng
23note front-ir exits 0 and ngcheck ACCEPTs its stdout; ngrun runs that ΩIR with --scratch SCRATCH/hK (K a new
24note number, so a new directory per run). C 0: exit and stdout equal the binary's, as for run. C 115..123:
25note ngrun refuses the word by that class of IR.md s7.11 (exit C, no stdout): the ΩIR is checked, not run.
26note 3. negative controls, each must fail a case: eighteen lowering mutants of seed/ng/src/front.om (the for
27note latch adds 2; and, or, xor shifted to the next op; a part's offset and count swapped; a mixed-type
28note shift amount checked against its own width; fma's second and third operands swapped; a struct
29note field index that adds the length for the offset, an array bound taken from the offset, a big-endian layout
30note field read and written with the byte order reversed, the dup32 retained check with eq as ne) over the run
31note cases; two host lowering mutants (a long argument typed int; chk.bounds for a host slice's chk.slice)
32note over the host cases; fmin lowered as max and fmax as min, qty add/sub/mul without their checks, and every array parameter declared read-only, over the run cases; the first run case through ng in `@ng front-check` mode (no ΩIR); the first refuse case
33note through ng in `@ng ir-copy` mode.
34note Deadline: every child (omc, the binary, ng, ngcheck, ngrun) is killed after 600 s of wall time (ngrun has
35note no step cap of its own yet); a case with a killed child prints `NOT_RUN NAME: ...` and is neither ok nor
36note FAIL, and does not kill a mutant or trip a control.
37note Output: a line per case (ok / FAIL / NOT_RUN), a line per control, then
38note FRONTIRGATE PASS|FAIL|NOT_RUN cases=N run=R refuse=F host=H classed=Q fail=K mutants=M killed=X controls=C
39note tripped=T notrun=U (N = R + F + H; Q of the H host cases were checked and refused by ngrun's class)
40note Exit 0 PASS, 1 FAIL, 2 INVALID (usage, oracle, scratch, case list), 3 a tool did not build, 4 NOT_RUN (no
41note failure, but U > 0 cases passed the deadline: never PASS).
42note Globals g_*, functions gi_*.
43text g_w "seed/ng/ src/ir.om src/front.om src/main.om sha256.om ngcheck.om ngrun.om ng ngcheck ngrun src.om bin in ir o1 o2 e1 e2 ck err nul ngm run refuse ng.units host --scratch h "
44text g_m "FAIL |ok |: omc exit |: ng exit |: ngcheck exit |: ngcheck did not accept|: exit omc=| ngrun=|: stdout differs|: omc accepted a refuse case|: ng stderr differs|: ng wrote stdout| exit=|FRONTIRGATE PASS|FRONTIRGATE FAIL|FRONTIRGATE INVALID: | cases=| run=| refuse=| fail=| mutants=| killed=| controls=| tripped=|usage: gate-front-ir OMC OMC_SHA256 SCRATCH CASES|oracle sha256 differs from OMC_SHA256|scratch exists or cannot be made|case list unreadable|build failed: |malformed case line|mutant |: survived every run case|: killed by |control front-check mode|control ir-copy mode|: not tripped|: tripped by |: pattern not present exactly once|: source unreadable|NOT_RUN |: a child passed the 600 s deadline and was killed|FRONTIRGATE NOT_RUN| notrun=| host=| classed=|: ngrun exit is not the expected class |: ngrun wrote stdout|"
45text g_pfr "@ng front-ir\n"
46text g_acc "ACCEPT "
47text g_pfc "@ng front-check\n"
48text g_pic "@ng ir-copy\n"
49note the lowering mutants (pattern, replacement of the same length; each pattern occurs once in front.om)
50text g_mu0 "\nar_pu 71 n0 fe_lp2 10 t iv fe_lcst t 1\n"
51text g_mu1 "\nar_pu 71 n0 fe_lp2 10 t iv fe_lcst t 2\n"
52text g_mu2 "\nfe_lval fe_lp2 uint add sub c 38 16 t a b t\n"
53text g_mu3 "\nfe_lval fe_lp2 uint add sub c 38 17 t a b t\n"
54text g_mu4 "\nir_set o 2 off\nir_set o 3 n\n"
55text g_mu5 "\nir_set o 2 n\nir_set o 3 off\n"
56note 4: a mixed-type shift amount checked against its own width, not the value's (fe_lsham); 5: fma's
57note second and third operands swapped (fe_lfma)
58text g_mu6 "\nk = fe_lp2 32 1 u fe_lcst 5 fe_twid a\n"
59text g_mu7 "\nk = fe_lp2 32 1 u fe_lcst 5 fe_twid b\n"
60text g_mu8 "\nir_set o 1 fb\nir_set o 2 fc\n"
61text g_mu9 "\nir_set o 1 fc\nir_set o 2 fb\n"
62note 6: a long host argument lowered as int (fe_lhost); 7: chk.bounds in place of a host slice's chk.slice
63text g_mu10 "\nif eq ch 108\nt = ulong 9\n"
64text g_mu11 "\nif eq ch 108\nt = ulong 8\n"
65text g_mu12 "\nfe_lck3 80 ar ao an\n"
66text g_mu13 "\nfe_lck3 79 ar ao an\n"
67note 8: fmin lowered as max and fmax as min (fe_lfmm). The real opcode is 24+(c-93).
68note A same-length swap is sub 118 add c 0 (25 when c is 93, 24 when c is 94).
69note add 25 sub c 93 is not that swap: fmax becomes opcode 26 (fsqrt, one operand).
70text g_mu14 "\nfe_lval fe_lp2 uint add 24 sub c 93 t a get f_lrv 0 t\n"
71text g_mu15 "\nfe_lval fe_lp2 uint sub 118 add c 0 t a get f_lrv 0 t\n"
72note 9: qty add, sub and mul without their chk (fe_lbop tests type 14, which no value has)
73text g_mu16 "\nif or s eq t 13\n"
74text g_mu17 "\nif or s eq t 14\n"
75note 10: every array parameter declared with access 0 (fe_lfpar), so an edit parameter is read-only
76text g_mu18 "\nv = ir_fpar f ir_tslc fe_lty t a 0\n"
77text g_mu19 "\nv = ir_fpar f ir_tslc fe_lty t 0 0\n"
78text g_mu20 "\nfe_lck1 82 code get f_lrv 0\n"
79text g_mu21 "\nfe_lck1 82 code fe_lcst 1 1\n"
80text g_mu22 "\nfe_lcscan 2\n"
81text g_mu23 "\nfe_lcscan 0\n"
82text g_mu24 "\nfe_lck1 82 10 get f_lrv 0\n"
83text g_mu25 "\nfe_lck1 82 10 fe_lcst 1 1\n"
84note 11-15: struct, layout and nominal lowering (fe_lstindex, fe_llyget, fe_llyput, fe_lseal): a struct field
85note index adds the length in place of the offset (11); the array bound is the offset in place of the length
86note (12); a big-endian layout field read and written from the wrong byte (13, 14); the dup32 retained check
87note compares the halves with ne in place of eq (15)
88text g_mu26 "\nend\nret fe_lp2 10 5 ix fe_lcst 5 off\n"
89text g_mu27 "\nend\nret fe_lp2 10 5 ix fe_lcst 5 cnt\n"
90text g_mu28 "fe_lcst 5 cnt\nend\nret fe_lp2 10 5 ix"
91text g_mu29 "fe_lcst 5 off\nend\nret fe_lp2 10 5 ix"
92text g_mu30 "\nk = sub sub n 1 j\nend\nb = fe_lp2 20 5 b"
93text g_mu31 "\nk = sub sub n 0 j\nend\nb = fe_lp2 20 5 b"
94text g_mu32 "\nk = sub sub n 1 j\nend\nb = fe_lp2 21 5 v"
95text g_mu33 "\nk = sub sub n 0 j\nend\nb = fe_lp2 21 5 v"
96text g_mu34 "\nok = fe_lp2 30 1 hi lo\n"
97text g_mu35 "\nok = fe_lp2 31 1 hi lo\n"
98global g_wo uint 64
99global g_wl uint 64
100global g_mo uint 64
101global g_ml uint 64
102global g_omc uchar 4096
103global g_scr uchar 4096
104global g_pa uchar 8192
105global g_av uchar 16384
106global g_b1 uchar 16777216
107global g_b2 uchar 16777216
108global g_cs uchar 1048576
109global g_o uchar 4096
110global g_stb uchar 4
111global g_hx uchar 128
112global g_ma uchar 64
113global g_mb uchar 64
114global g_n ulong 32
115note g_hc: the expected class C of the current host case; g_hk: the last ngrun scratch number
116global g_hc ulong 1
117global g_hk ulong 1
118note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 b1 length,
119note 6 b2 length, 7 cases length, 8 cases cursor, 9 out length, 10 cases, 11 run cases, 12 refuse cases,
120note 13 failed cases, 14 quiet (controls and mutants), 15 current case failed, 16 name start, 17 name end,
121note 18 source start, 19 source end, 20 mutants, 21 killed, 22 controls, 23 tripped, 24 ng mode (0 front-ir,
122note 1 front-check, 2 ir-copy), 25 ng binary word, 26 line start, 27 mutant pattern length, 28 NOT_RUN cases,
123note 29 a child of the current case passed the deadline (g_n 15 is 0 ok, 1 failed, 2 NOT_RUN), 30 host cases,
124note 31 host cases ngrun refused by their class
125
126note ---- words and output ------------------------------------------------------------------------
127fn gi_init to void
128w = ulong 0
129s = ulong 0
130for i ulong len g_w
131if eq get g_w i 32
132put g_wo w uint s
133put g_wl w uint sub i s
134w = add w 1
135s = add i 1
136end
137end
138w = 0
139s = 0
140for i ulong len g_m
141if eq get g_m i 124
142put g_mo w uint s
143put g_ml w uint sub i s
144w = add w 1
145s = add i 1
146end
147end
148put g_n 25 7
149end
150fn gi_c b ulong to void
151n = get g_n 9
152if lt n len g_o
153put g_o n uchar b
154put g_n 9 add n 1
155end
156end
157fn gi_nl to void
158gi_c 10
159r = write 1 g_o 0 get g_n 9
160put g_n 9 0
161end
162fn gi_say i ulong to void
163s = ulong get g_mo i
164for j ulong ulong get g_ml i bound 128
165gi_c ulong get g_m add s j
166end
167end
168fn gi_num v ulong to void
169if ge v 10
170gi_num div v 10
171end
172gi_c add 48 rem v 10
173end
174note the name of the current case
175fn gi_name to void
176for p ulong sub get g_n 17 get g_n 16 bound 4096
177gi_c ulong get g_cs add get g_n 16 p
178end
179end
180note a failure of the current case: FAIL NAME<message i>, unless quiet
181fn gi_fail i ulong to void
182put g_n 15 1
183if ne get g_n 14 0
184ret
185end
186gi_say 0
187gi_name
188gi_say i
189end
190fn gi_fail0 i ulong to void
191gi_fail i
192if eq get g_n 14 0
193gi_nl
194end
195end
196fn gi_failv i ulong v ulong to void
197gi_fail i
198if eq get g_n 14 0
199gi_num v
200gi_nl
201end
202end
203
204note ---- paths --------------------------------------------------------------------------------------
205fn gi_pclr to void
206put g_n 0 0
207end
208fn gi_pc c ulong to void
209n = get g_n 0
210if lt n len g_pa
211put g_pa n uchar c
212put g_n 0 add n 1
213end
214end
215fn gi_pw i ulong to void
216s = ulong get g_wo i
217for j ulong ulong get g_wl i bound 64
218gi_pc ulong get g_w add s j
219end
220end
221note scratch file word i
222fn gi_ps i ulong to void
223gi_pclr
224for j ulong get g_n 2 bound 4096
225gi_pc ulong get g_scr j
226end
227gi_pw i
228end
229note repository file seed/ng/ + word i
230fn gi_pr i ulong to void
231gi_pclr
232gi_pw 0
233gi_pw i
234end
235note the source path of the current case
236fn gi_psrc to void
237gi_pclr
238for p ulong sub get g_n 19 get g_n 18 bound 4096
239gi_pc ulong get g_cs add get g_n 18 p
240end
241end
242fn gi_open fl ulong to int
243r = fopen g_pa 0 get g_n 0 int fl 420
244if lt r 0
245ret -1
246end
247ret int r
248end
249fn gi_rdonly to int
250ret gi_open 524288
251end
252fn gi_wronly to int
253ret gi_open 524865
254end
255note open scratch g_pa for writing with mode 0755 (created fresh: unlink first)
256fn gi_exe to int
257r = unlink g_pa 0 get g_n 0
258x = fopen g_pa 0 get g_n 0 524865 493
259if lt x 0
260ret -1
261end
262ret int x
263end
264fn gi_fclo fd int to void
265if ge fd 0
266r = fclose fd
267end
268end
269
270note ---- whole files ----------------------------------------------------------------------------------
271note read the file at g_pa into b1 (k 1) or b2 (k 2) at offset o; its length, or 2^63 when unreadable or too big
272fn gi_slurp k ulong o ulong to ulong
273fd = gi_rdonly
274if lt fd 0
275ret shl ulong 1 63
276end
277n = o
278ok = true
279while true bound 16777218
280x = long 0
281if eq k 1
282x = read fd g_b1 n sub len g_b1 n
283else
284x = read fd g_b2 n sub len g_b2 n
285end
286if lt x 0
287ok = false
288break
289end
290if eq x 0
291break
292end
293n = add n ulong x
294if ge n len g_b1
295ok = false
296break
297end
298end
299gi_fclo fd
300if not ok
301ret shl ulong 1 63
302end
303ret sub n o
304end
305note write b1[0, n) to the file at g_pa (fd from gi_wronly or gi_exe when ex)
306fn gi_spill n ulong ex bool to bool
307fd = int -1
308if ex
309fd = gi_exe
310else
311fd = gi_wronly
312end
313if lt fd 0
314ret false
315end
316o = ulong 0
317while lt o n bound 16777217
318x = write fd g_b1 o sub n o
319if le x 0
320gi_fclo fd
321ret false
322end
323o = add o ulong x
324end
325gi_fclo fd
326ret true
327end
328note read up to m bytes of fd into b1 (k 1) or b2 (k 2); the count (0 at the end)
329fn gi_rdn fd int k ulong m ulong to ulong
330n = ulong 0
331while lt n m bound 1048577
332x = long 0
333if eq k 1
334x = read fd g_b1 n sub m n
335else
336x = read fd g_b2 n sub m n
337end
338if le x 0
339ret n
340end
341n = add n ulong x
342end
343ret n
344end
345fn gi_eqn n ulong to bool
346for j ulong n bound 1048576
347if ne get g_b1 j get g_b2 j
348ret false
349end
350end
351ret true
352end
353note the scratch files w1 and w2 have the same bytes
354fn gi_fcmp w1 ulong w2 ulong to bool
355gi_ps w1
356f1 = gi_rdonly
357gi_ps w2
358f2 = gi_rdonly
359ok = and ge f1 0 ge f2 0
360dn = false
361while and ok not dn bound 4096
362a = gi_rdn f1 1 1048576
363b = gi_rdn f2 2 1048576
364if ne a b
365ok = false
366else
367if eq a 0
368dn = true
369end
370ok = gi_eqn a
371end
372end
373gi_fclo f1
374gi_fclo f2
375ret ok
376end
377note bytes in scratch file w (2^63 when it cannot be opened)
378fn gi_size w ulong to ulong
379gi_ps w
380fd = gi_rdonly
381if lt fd 0
382ret shl ulong 1 63
383end
384r = fseek fd 0 2
385gi_fclo fd
386if lt r 0
387ret shl ulong 1 63
388end
389ret ulong r
390end
391
392note ---- children ------------------------------------------------------------------------------------
393fn gi_aclr to void
394put g_n 3 2
395put g_n 4 0
396end
397note append g_pa as the next argument
398fn gi_apa to void
399p = get g_n 3
400n = get g_n 0
401for j ulong n bound 8192
402put g_av add add p 2 j get g_pa j
403end
404put g_av p uchar and n 255
405put g_av add p 1 uchar shr n 8
406put g_n 3 add p add n 2
407c = add get g_n 4 1
408put g_n 4 c
409put g_av 0 uchar and c 255
410put g_av 1 uchar shr c 8
411end
412fn gi_redir s int d int to void
413if ne dupfd s d 0 long d
414exit 127
415end
416end
417note run the argument list with stdin, stdout, stderr fds (closed here); the exit code, 256 + the signal
418fn gi_spawn fi int fo int fe int to ulong
419if or lt fi 0 or lt fo 0 lt fe 0
420gi_fclo fi
421gi_fclo fo
422gi_fclo fe
423ret 512
424end
425pid = fork
426if lt pid 0
427exit 2
428end
429if eq pid 0
430gi_redir fi 0
431gi_redir fo 1
432gi_redir fe 2
433r = execprog g_av 0 get g_n 3
434exit 127
435end
436gi_fclo fi
437gi_fclo fo
438gi_fclo fe
439t0 = monons
440while true bound 1000000000
441r = waitpid int pid g_stb 0 len g_stb 1
442if eq r pid
443x = ulong get g_stb 0
444if ne x 0
445ret add 256 x
446end
447ret ulong get g_stb 1
448end
449if lt r 0
450exit 2
451end
452if gt sub monons t0 600000000000
453r = killpid int pid 9
454r = waitpid int pid g_stb 0 len g_stb 0
455put g_n 29 1
456ret 1000
457end
458q = sleepns 1000000
459end
460exit 2
461end
462note a child of the current case passed the deadline: the case is NOT_RUN (g_n 15 = 2), never ok or FAIL
463fn gi_dl to bool
464if eq get g_n 29 0
465ret false
466end
467put g_n 15 2
468if eq get g_n 14 0
469gi_say 39
470gi_name
471gi_say 40
472gi_nl
473end
474ret true
475end
476note run program word p (a scratch file) with optional argument scratch word a (0 none); stdin scratch word
477note i, stdout scratch word o (an executable when ex), stderr scratch word e
478fn gi_run p ulong a ulong i ulong o ulong e ulong to ulong
479gi_ps i
480fi = gi_rdonly
481gi_aclr
482gi_ps p
483gi_apa
484if ne a 0
485gi_ps a
486gi_apa
487end
488gi_ps o
489fo = gi_wronly
490gi_ps e
491fe = gi_wronly
492ret gi_spawn fi fo fe
493end
494note OMC with stdin at g_pa (already set), stdout scratch word o (an executable), stderr scratch word e
495fn gi_omc o ulong e ulong to ulong
496fi = gi_rdonly
497gi_aclr
498gi_pclr
499for j ulong get g_n 1 bound 4096
500gi_pc ulong get g_omc j
501end
502gi_apa
503gi_ps o
504fo = gi_exe
505gi_ps e
506fe = gi_wronly
507ret gi_spawn fi fo fe
508end
509
510note ---- building -------------------------------------------------------------------------------------
511note append seed/ng/ + word i to b1 at its length (g_n 5); false when unreadable
512fn gi_cat i ulong to bool
513gi_pr i
514n = gi_slurp 1 get g_n 5
515if ge n shl ulong 1 63
516ret false
517end
518put g_n 5 add get g_n 5 n
519ret true
520end
521note compile b1[0, g_n 5) with OMC to scratch word o
522fn gi_bld o ulong to bool
523gi_ps 10
524if not gi_spill get g_n 5 false
525ret false
526end
527ret eq gi_omc o 19 0
528end
529note the units of seed/ng/ng.units (lines `SHA256 PATH`, in order) appended to b1: ng's source, whatever
530note stage units the list holds (the pins are ngbuild's to check, gate-ir's ngbuild phase); false when the
531note list or a unit cannot be read
532fn gi_units to bool
533gi_pr 24
534k = gi_slurp 2 0
535if ge k shl ulong 1 63
536ret false
537end
538s = ulong 0
539for i ulong k bound 65536
540if eq get g_b2 i 10
541if not gi_unit s i
542ret false
543end
544s = add i 1
545end
546end
547ret gi_unit s k
548end
549note the unit on the units-list line b2[s, e) (64 hex digits, a space, the path) appended to b1; an empty
550note line adds nothing
551fn gi_unit s ulong e ulong to bool
552if eq s e
553ret true
554end
555if le e add s 65
556ret false
557end
558gi_pclr
559for i ulong sub e add s 65 bound 4096
560gi_pc ulong get g_b2 add add s 65 i
561end
562n = gi_slurp 1 get g_n 5
563if ge n shl ulong 1 63
564ret false
565end
566put g_n 5 add get g_n 5 n
567ret true
568end
569fn gi_tools to bool
570put g_n 5 0
571if not gi_units
572ret false
573end
574if not gi_bld 7
575ret false
576end
577put g_n 5 0
578if or not gi_cat 4 not gi_cat 5
579ret false
580end
581if not gi_bld 8
582ret false
583end
584put g_n 5 0
585if or not gi_cat 1 not gi_cat 6
586ret false
587end
588ret gi_bld 9
589end
590note ng with mutant m (1 to 5) of front.om, built to scratch ngm; false unless its pattern occurs exactly once
591note in the units
592fn gi_mbld m ulong to bool
593gi_msel m
594put g_n 5 0
595if not gi_units
596ret false
597end
598if ne gi_msub 0 get g_n 5 1
599ret false
600end
601ret gi_bld 21
602end
603fn gi_msel m ulong to void
604if eq m 1
605put g_n 27 len g_mu0
606for j ulong len g_mu0 bound 64
607put g_ma j get g_mu0 j
608put g_mb j get g_mu1 j
609end
610end
611if eq m 2
612put g_n 27 len g_mu2
613for j ulong len g_mu2 bound 64
614put g_ma j get g_mu2 j
615put g_mb j get g_mu3 j
616end
617end
618if eq m 3
619put g_n 27 len g_mu4
620for j ulong len g_mu4 bound 64
621put g_ma j get g_mu4 j
622put g_mb j get g_mu5 j
623end
624end
625if eq m 4
626put g_n 27 len g_mu6
627for j ulong len g_mu6 bound 64
628put g_ma j get g_mu6 j
629put g_mb j get g_mu7 j
630end
631end
632if eq m 5
633put g_n 27 len g_mu8
634for j ulong len g_mu8 bound 64
635put g_ma j get g_mu8 j
636put g_mb j get g_mu9 j
637end
638end
639if eq m 6
640put g_n 27 len g_mu10
641for j ulong len g_mu10 bound 64
642put g_ma j get g_mu10 j
643put g_mb j get g_mu11 j
644end
645end
646if eq m 7
647put g_n 27 len g_mu12
648for j ulong len g_mu12 bound 64
649put g_ma j get g_mu12 j
650put g_mb j get g_mu13 j
651end
652end
653if eq m 8
654put g_n 27 len g_mu14
655for j ulong len g_mu14 bound 64
656put g_ma j get g_mu14 j
657put g_mb j get g_mu15 j
658end
659end
660if eq m 9
661put g_n 27 len g_mu16
662for j ulong len g_mu16 bound 64
663put g_ma j get g_mu16 j
664put g_mb j get g_mu17 j
665end
666end
667if eq m 10
668put g_n 27 len g_mu18
669for j ulong len g_mu18 bound 64
670put g_ma j get g_mu18 j
671put g_mb j get g_mu19 j
672end
673end
674if eq m 11
675put g_n 27 len g_mu20
676for j ulong len g_mu20 bound 64
677put g_ma j get g_mu20 j
678put g_mb j get g_mu21 j
679end
680end
681if eq m 12
682put g_n 27 len g_mu22
683for j ulong len g_mu22 bound 64
684put g_ma j get g_mu22 j
685put g_mb j get g_mu23 j
686end
687end
688if eq m 13
689put g_n 27 len g_mu24
690for j ulong len g_mu24 bound 64
691put g_ma j get g_mu24 j
692put g_mb j get g_mu25 j
693end
694end
695if eq m 14
696put g_n 27 len g_mu26
697for j ulong len g_mu26 bound 64
698put g_ma j get g_mu26 j
699put g_mb j get g_mu27 j
700end
701end
702if eq m 15
703put g_n 27 len g_mu28
704for j ulong len g_mu28 bound 64
705put g_ma j get g_mu28 j
706put g_mb j get g_mu29 j
707end
708end
709if eq m 16
710put g_n 27 len g_mu30
711for j ulong len g_mu30 bound 64
712put g_ma j get g_mu30 j
713put g_mb j get g_mu31 j
714end
715end
716if eq m 17
717put g_n 27 len g_mu32
718for j ulong len g_mu32 bound 64
719put g_ma j get g_mu32 j
720put g_mb j get g_mu33 j
721end
722end
723if eq m 18
724put g_n 27 len g_mu34
725for j ulong len g_mu34 bound 64
726put g_ma j get g_mu34 j
727put g_mb j get g_mu35 j
728end
729end
730end
731note the places of the pattern in b1[s, e), counted; when there is exactly one it is replaced
732fn gi_msub s ulong e ulong to ulong
733k = get g_n 27
734c = ulong 0
735if lt e k
736ret 0
737end
738p = s
739while le add p k e bound 16777216
740if gi_mat p k
741c = add c 1
742end
743p = add p 1
744end
745if ne c 1
746ret c
747end
748p = s
749while le add p k e bound 16777216
750if gi_mat p k
751for j ulong k bound 64
752put g_b1 add p j get g_mb j
753end
754ret 1
755end
756p = add p 1
757end
758ret 0
759end
760fn gi_mat p ulong k ulong to bool
761for j ulong k bound 64
762if ne get g_b1 add p j get g_ma j
763ret false
764end
765end
766ret true
767end
768
769note ---- one case --------------------------------------------------------------------------------------
770note scratch in = the mode line of g_n 24, then the source; false when the source cannot be read
771fn gi_mkin to bool
772md = get g_n 24
773n = ulong 0
774if eq md 0
775n = len g_pfr
776for j ulong n bound 64
777put g_b1 j get g_pfr j
778end
779end
780if eq md 1
781n = len g_pfc
782for j ulong n bound 64
783put g_b1 j get g_pfc j
784end
785end
786if eq md 2
787n = len g_pic
788for j ulong n bound 64
789put g_b1 j get g_pic j
790end
791end
792gi_psrc
793m = gi_slurp 1 n
794if ge m shl ulong 1 63
795ret false
796end
797gi_ps 12
798ret gi_spill add n m false
799end
800note run NAME SRC
801fn gi_rcase to void
802if not gi_mkin
803gi_fail0 38
804ret
805end
806gi_psrc
807x = gi_omc 11 16
808if gi_dl
809ret
810end
811if ne x 0
812gi_failv 2 x
813ret
814end
815x = gi_run get g_n 25 0 12 13 17
816if gi_dl
817ret
818end
819if ne x 0
820gi_failv 3 x
821ret
822end
823note Compare compile diagnostics before the runtime overwrites its stderr file.
824if not gi_fcmp 16 17
825gi_fail0 10
826ret
827end
828x1 = gi_run 11 0 20 14 16
829if gi_dl
830ret
831end
832x = gi_run 8 0 13 18 19
833if gi_dl
834ret
835end
836if ne x 0
837gi_failv 4 x
838ret
839end
840if not gi_acc
841gi_fail0 5
842ret
843end
844x2 = gi_run 9 13 20 15 17
845if gi_dl
846ret
847end
848if ne x1 x2
849gi_fail 6
850if eq get g_n 14 0
851gi_num x1
852gi_say 7
853gi_num x2
854gi_nl
855end
856ret
857end
858if not gi_fcmp 14 15
859gi_fail0 8
860ret
861end
862if eq get g_n 14 0
863gi_say 1
864gi_name
865gi_say 12
866gi_num x1
867gi_nl
868end
869end
870note host NAME SRC C (header, host)
871fn gi_hcase to void
872if not gi_mkin
873gi_fail0 38
874ret
875end
876gi_psrc
877x = gi_omc 11 16
878if gi_dl
879ret
880end
881if ne x 0
882gi_failv 2 x
883ret
884end
885x1 = gi_run 11 0 20 14 16
886if gi_dl
887ret
888end
889x = gi_run get g_n 25 0 12 13 17
890if gi_dl
891ret
892end
893if ne x 0
894gi_failv 3 x
895ret
896end
897x = gi_run 8 0 13 18 19
898if gi_dl
899ret
900end
901if ne x 0
902gi_failv 4 x
903ret
904end
905if not gi_acc
906gi_fail0 5
907ret
908end
909x2 = gi_hng
910if gi_dl
911ret
912end
913c = get g_hc 0
914if eq c 0
915if ne x1 x2
916gi_fail 6
917if eq get g_n 14 0
918gi_num x1
919gi_say 7
920gi_num x2
921gi_nl
922end
923ret
924end
925if not gi_fcmp 14 15
926gi_fail0 8
927ret
928end
929else
930if ne x2 c
931gi_fail 45
932if eq get g_n 14 0
933gi_num c
934gi_say 7
935gi_num x2
936gi_nl
937end
938ret
939end
940if ne gi_size 15 0
941gi_fail0 46
942ret
943end
944if eq get g_n 14 0
945put g_n 31 add get g_n 31 1
946end
947end
948if eq get g_n 14 0
949gi_say 1
950gi_name
951gi_say 12
952gi_num x2
953gi_nl
954end
955end
956note ngrun ir --scratch SCRATCH/hK (K the next number), stdin nul, stdout o2, stderr e2
957fn gi_hng to ulong
958gi_ps 20
959fi = gi_rdonly
960gi_aclr
961gi_ps 9
962gi_apa
963gi_ps 13
964gi_apa
965gi_pclr
966gi_pw 26
967gi_apa
968gi_ps 27
969k = add get g_hk 0 1
970put g_hk 0 k
971gi_pnum k
972gi_apa
973gi_ps 15
974fo = gi_wronly
975gi_ps 17
976fe = gi_wronly
977ret gi_spawn fi fo fe
978end
979fn gi_pnum v ulong to void
980if ge v 10
981gi_pnum div v 10
982end
983gi_pc add 48 rem v 10
984end
985note scratch ck starts with "ACCEPT "
986fn gi_acc to bool
987gi_ps 18
988fd = gi_rdonly
989if lt fd 0
990ret false
991end
992n = gi_rdn fd 1 7
993gi_fclo fd
994if ne n 7
995ret false
996end
997for j ulong 7
998if ne get g_b1 j get g_acc j
999ret false
1000end
1001end
1002ret true
1003end
1004note refuse NAME SRC
1005fn gi_fcase to void
1006if not gi_mkin
1007gi_fail0 38
1008ret
1009end
1010gi_psrc
1011x1 = gi_omc 11 16
1012if gi_dl
1013ret
1014end
1015if eq x1 0
1016gi_fail0 9
1017ret
1018end
1019x2 = gi_run get g_n 25 0 12 13 17
1020if gi_dl
1021ret
1022end
1023if ne x1 x2
1024gi_fail 6
1025if eq get g_n 14 0
1026gi_num x1
1027gi_say 7
1028gi_num x2
1029gi_nl
1030end
1031ret
1032end
1033if not gi_fcmp 16 17
1034gi_fail0 10
1035ret
1036end
1037if ne gi_size 13 0
1038gi_fail0 11
1039ret
1040end
1041if eq get g_n 14 0
1042gi_say 1
1043gi_name
1044gi_say 12
1045gi_num x1
1046gi_nl
1047end
1048end
1049
1050note ---- the case list ---------------------------------------------------------------------------------
1051fn gi_sp p ulong to bool
1052c = get g_cs p
1053ret or eq c 32 eq c 9
1054end
1055note the next field of the line at or after p (before e) into (start, end) at g_n s, s+1; false when none
1056fn gi_fld p ulong e ulong s ulong to ulong
1057q = p
1058while and lt q e gi_sp q bound 1048576
1059q = add q 1
1060end
1061put g_n s q
1062while and lt q e not gi_sp q bound 1048576
1063q = add q 1
1064end
1065put g_n add s 1 q
1066ret q
1067end
1068note the next case line from the cursor: 0 none left, 1 run, 2 refuse, 3 malformed, 4 host (fields in g_n 16..19,
1069note a host case's C in g_hc)
1070fn gi_next to ulong
1071cs = get g_n 7
1072while lt get g_n 8 cs bound 1048576
1073p = get g_n 8
1074e = p
1075while and lt e cs ne get g_cs e 10 bound 1048576
1076e = add e 1
1077end
1078put g_n 8 add e 1
1079put g_n 26 p
1080q = p
1081while and lt q e gi_sp q bound 1048576
1082q = add q 1
1083end
1084if and lt q e ne get g_cs q 35
1085q = gi_fld q e 16
1086k = sub get g_n 17 get g_n 16
1087a = get g_n 16
1088q = gi_fld q e 16
1089q = gi_fld q e 18
1090if eq get g_n 18 get g_n 19
1091ret 3
1092end
1093if gi_isw a k 22
1094ret 1
1095end
1096if gi_isw a k 23
1097ret 2
1098end
1099if gi_isw a k 25
1100ret gi_hcls q e
1101end
1102ret 3
1103end
1104end
1105ret 0
1106end
1107note hcls: the class field of a host line, after the cursor q (before e): 1 to 3 decimal digits into g_hc and
1108note kind 4, else 3 (malformed); nothing may follow it
1109fn gi_hcls q ulong e ulong to ulong
1110p = q
1111while and lt p e gi_sp p bound 1048576
1112p = add p 1
1113end
1114v = ulong 0
1115d = ulong 0
1116while and lt p e not gi_sp p bound 1048576
1117c = ulong get g_cs p
1118if or lt c 48 gt c 57
1119ret 3
1120end
1121v = add mul v 10 sub c 48
1122d = add d 1
1123p = add p 1
1124end
1125while and lt p e gi_sp p bound 1048576
1126p = add p 1
1127end
1128if or or eq d 0 gt d 3 lt p e
1129ret 3
1130end
1131put g_hc 0 v
1132ret 4
1133end
1134note cases[a, a + k) is word i
1135fn gi_isw a ulong k ulong i ulong to bool
1136if ne k ulong get g_wl i
1137ret false
1138end
1139s = ulong get g_wo i
1140for j ulong k bound 64
1141if ne get g_cs add a j get g_w add s j
1142ret false
1143end
1144end
1145ret true
1146end
1147note every case of the list (kinds in kd: bit 1 run, 2 refuse, 4 host); in quiet mode stop at the first failure;
1148note true when some case failed. A case past the deadline is NOT_RUN (g_n 28 counts them outside quiet mode),
1149note neither a failure nor, under a mutant, a kill
1150fn gi_all kd ulong to bool
1151put g_n 8 0
1152while true bound 65536
1153k = gi_next
1154if eq k 0
1155ret false
1156end
1157put g_n 15 0
1158put g_n 29 0
1159if eq k 3
1160gi_fail0 29
1161else
1162if eq k 1
1163if ne and kd 1 0
1164gi_rcase
1165if eq get g_n 14 0
1166put g_n 11 add get g_n 11 1
1167end
1168end
1169else
1170if eq k 4
1171if ne and kd 4 0
1172gi_hcase
1173if eq get g_n 14 0
1174put g_n 30 add get g_n 30 1
1175end
1176end
1177else
1178if ne and kd 2 0
1179gi_fcase
1180if eq get g_n 14 0
1181put g_n 12 add get g_n 12 1
1182end
1183end
1184end
1185end
1186end
1187if eq get g_n 15 2
1188if eq get g_n 14 0
1189put g_n 28 add get g_n 28 1
1190end
1191end
1192if eq get g_n 15 1
1193if ne get g_n 14 0
1194ret true
1195end
1196put g_n 13 add get g_n 13 1
1197end
1198end
1199ret false
1200end
1201note the first case of kind kd only, quietly; true when it failed (a NOT_RUN case does not trip a control)
1202fn gi_first kd ulong to bool
1203put g_n 8 0
1204while true bound 65536
1205k = gi_next
1206if eq k 0
1207ret false
1208end
1209put g_n 15 0
1210put g_n 29 0
1211if eq k kd
1212if eq kd 1
1213gi_rcase
1214else
1215gi_fcase
1216end
1217ret eq get g_n 15 1
1218end
1219end
1220ret false
1221end
1222
1223note ---- negative controls -----------------------------------------------------------------------------
1224fn gi_mut m ulong kd ulong to void
1225put g_n 20 add get g_n 20 1
1226gi_say 30
1227gi_num m
1228if not gi_mbld m
1229gi_say 37
1230gi_nl
1231put g_n 13 add get g_n 13 1
1232ret
1233end
1234put g_n 14 1
1235put g_n 25 21
1236hit = gi_all kd
1237put g_n 14 0
1238put g_n 25 7
1239if hit
1240put g_n 21 add get g_n 21 1
1241gi_say 32
1242gi_name
1243else
1244gi_say 31
1245put g_n 13 add get g_n 13 1
1246end
1247gi_nl
1248end
1249fn gi_ctl md ulong kd ulong to void
1250put g_n 22 add get g_n 22 1
1251gi_say add 32 md
1252put g_n 14 1
1253put g_n 24 md
1254hit = gi_first kd
1255put g_n 24 0
1256put g_n 14 0
1257if hit
1258put g_n 23 add get g_n 23 1
1259gi_say 36
1260gi_name
1261else
1262gi_say 35
1263put g_n 13 add get g_n 13 1
1264end
1265gi_nl
1266end
1267
1268note ---- main ----------------------------------------------------------------------------------------------
1269fn gi_inval i ulong to int
1270gi_say 15
1271gi_say i
1272gi_nl
1273ret 2
1274end
1275note OMC hashes to the hex of argument 2
1276fn gi_oracle to bool
1277gi_pclr
1278for j ulong get g_n 1 bound 4096
1279gi_pc ulong get g_omc j
1280end
1281fd = gi_rdonly
1282if lt fd 0
1283ret false
1284end
1285n = ulong 0
1286while true bound 16777218
1287x = read fd sh_dat n sub len sh_dat n
1288if le x 0
1289break
1290end
1291n = add n ulong x
1292if ge n len sh_dat
1293gi_fclo fd
1294ret false
1295end
1296end
1297gi_fclo fd
1298sh_all n
1299r = argread 2 g_hx 0 128
1300if ne r 64
1301ret false
1302end
1303for j ulong 32
1304b = get sh_dig j
1305if ne get g_hx mul j 2 sh_hexd uint shr b 4
1306ret false
1307end
1308if ne get g_hx add mul j 2 1 sh_hexd uint and b 15
1309ret false
1310end
1311end
1312ret true
1313end
1314note Import run/refuse/emit sources directly from the compiler's contract manifest.
1315note Emit rows also exercise runtime here; compiler diagnostic text is the check-parity gate's job.
1316text g_contracts "seed/omc/contracts/contracts.cases"
1317text g_crun "run "
1318text g_cref "refuse "
1319text g_cemit "emit "
1320global g_cf ulong 6
1321fn gi_ccopy a ulong b ulong to void
1322for i ulong sub b a
1323n = get g_n 7
1324if ge n len g_cs
1325exit gi_inval 27
1326end
1327put g_cs n get g_b2 add a i
1328put g_n 7 add n 1
1329end
1330end
1331fn gi_cbyte c uchar to void
1332n = get g_n 7
1333if ge n len g_cs
1334exit gi_inval 27
1335end
1336put g_cs n c
1337put g_n 7 add n 1
1338end
1339fn gi_cmatch a ulong b ulong kind ulong to bool
1340n = ulong 3
1341if eq kind 2
1342n = ulong 6
1343end
1344if eq kind 3
1345n = ulong 4
1346end
1347if ne sub b a n
1348ret false
1349end
1350for i ulong n
1351c = uchar 0
1352if eq kind 1
1353c = get g_crun i
1354end
1355if eq kind 2
1356c = get g_cref i
1357end
1358if eq kind 3
1359c = get g_cemit i
1360end
1361if ne get g_b2 add a i c
1362ret false
1363end
1364end
1365ret true
1366end
1367fn gi_contracts to void
1368gi_pclr
1369for i ulong len g_contracts
1370gi_pc ulong get g_contracts i
1371end
1372n = gi_slurp 2 0
1373if ge n shl ulong 1 63
1374exit gi_inval 27
1375end
1376p = ulong 0
1377gi_cbyte 10
1378while lt p n
1379q = p
1380while and lt q n ne get g_b2 q 10
1381q = add q 1
1382end
1383x = p
1384for f ulong 3
1385while and lt x q le get g_b2 x 32
1386x = add x 1
1387end
1388put g_cf mul f 2 x
1389while and lt x q gt get g_b2 x 32
1390x = add x 1
1391end
1392put g_cf add mul f 2 1 x
1393end
1394a = get g_cf 2
1395b = get g_cf 3
1396kind = ulong 0
1397if or gi_cmatch a b 1 gi_cmatch a b 3
1398kind = ulong 1
1399end
1400if gi_cmatch a b 2
1401kind = ulong 2
1402end
1403if ne kind 0
1404if eq get g_cf 4 get g_cf 5
1405exit gi_inval 27
1406end
1407if eq kind 1
1408for i ulong len g_crun
1409gi_cbyte get g_crun i
1410end
1411else
1412for i ulong len g_cref
1413gi_cbyte get g_cref i
1414end
1415end
1416gi_ccopy get g_cf 0 get g_cf 1
1417gi_cbyte 32
1418gi_ccopy get g_cf 4 get g_cf 5
1419gi_cbyte 10
1420end
1421p = add q 1
1422end
1423end
1424fn gi_contract_front original ulong to void
1425total = get g_n 7
1426extra = sub total original
1427for j ulong total
1428put g_b1 j get g_cs j
1429end
1430for j ulong extra
1431put g_cs j get g_b1 add original j
1432end
1433for j ulong original
1434put g_cs add extra j get g_b1 j
1435end
1436end
1437fn main to int
1438gi_init
1439if ne argcnt 5
1440ret gi_inval 24
1441end
1442r = argread 1 g_omc 0 4095
1443if lt r 1
1444ret gi_inval 24
1445end
1446put g_n 1 ulong r
1447if not gi_oracle
1448ret gi_inval 25
1449end
1450r = argread 3 g_scr 0 4094
1451if lt r 1
1452ret gi_inval 24
1453end
1454n = ulong r
1455x = makedir g_scr 0 n 448
1456if ne x 0
1457ret gi_inval 26
1458end
1459put g_scr n 47
1460put g_n 2 add n 1
1461r = argread 4 g_pa 0 4095
1462if lt r 1
1463ret gi_inval 24
1464end
1465put g_n 0 ulong r
1466fd = gi_rdonly
1467if lt fd 0
1468ret gi_inval 27
1469end
1470k = read fd g_cs 0 len g_cs
1471gi_fclo fd
1472if or le k 0 ge ulong k len g_cs
1473ret gi_inval 27
1474end
1475put g_n 7 ulong k
1476gi_contracts
1477gi_contract_front ulong k
1478gi_ps 20
1479put g_n 5 0
1480if not gi_spill 0 false
1481ret gi_inval 26
1482end
1483if not gi_tools
1484gi_say 28
1485gi_ps 19
1486r = write 1 g_pa 0 get g_n 0
1487gi_nl
1488ret 3
1489end
1490hit = gi_all 7
1491gi_mut 1 1
1492gi_mut 2 1
1493gi_mut 3 1
1494gi_mut 4 1
1495gi_mut 5 1
1496gi_mut 6 4
1497gi_mut 7 4
1498gi_mut 8 1
1499gi_mut 9 1
1500gi_mut 10 1
1501gi_mut 11 1
1502gi_mut 12 1
1503gi_mut 13 1
1504gi_mut 14 1
1505gi_mut 15 1
1506gi_mut 16 1
1507gi_mut 17 1
1508gi_mut 18 1
1509gi_ctl 1 1
1510gi_ctl 2 2
1511f = get g_n 13
1512nr = get g_n 28
1513if ne f 0
1514gi_say 14
1515else
1516if ne nr 0
1517gi_say 41
1518else
1519gi_say 13
1520end
1521end
1522gi_say 16
1523nc = add get g_n 11 get g_n 12
1524gi_num add nc get g_n 30
1525gi_say 17
1526gi_num get g_n 11
1527gi_say 18
1528gi_num get g_n 12
1529gi_say 43
1530gi_num get g_n 30
1531gi_say 44
1532gi_num get g_n 31
1533gi_say 19
1534gi_num f
1535gi_say 20
1536gi_num get g_n 20
1537gi_say 21
1538gi_num get g_n 21
1539gi_say 22
1540gi_num get g_n 22
1541gi_say 23
1542gi_num get g_n 23
1543gi_say 42
1544gi_num nr
1545gi_nl
1546if ne f 0
1547ret 1
1548end
1549if ne nr 0
1550ret 4
1551end
1552ret 0
1553end