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 / gpu / runtime / gate.om

1348 lines · 25261 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/runtime/gate.om: OMEGA-GPU-RUNTIME, the gate of gpu/runtime/ (the inventory of CUDApp src/, the C runtime, and
3note the Omega rewrites of its files done so far), in
4note seeded Omega (OM-2 program mode, Linux AArch64). Build from the repository root:
5note { printf 'om2\n'; cat seed/ng/sha256.om gpu/runtime/zsha.om gpu/runtime/gate.om; } | seed/out/omc > gate
6note Run from the repository root: gate OMC SCRATCH
7note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing
8note runs (exit 69, nothing written)
9note SCRATCH a new directory (created 0700); an existing one is refused (exit 2)
10note Checks. gpu/runtime/checks.tsv, one per line, tab separated: NAME PARTS EXPECT MPART FIND REPLACE.
11note NAME one or more of A-Z a-z 0-9 _ -, once. PARTS: paths joined by commas, composed in order, each followed by a
12note newline into SCRATCH/uK.om (K the number of the name, counted from 1 in the order names are read, so a name
13note never becomes a file name); the part om2 is the literal line om2. The unit is compiled by OMC and run from
14note the repository root with no argument: exit 0, and its stdout holds exactly the bytes of the file EXPECT.
15note Mutant control: the same composition with the first FIND in part number MPART (from 1) replaced by
16note REPLACE must compile, and its run must exit nonzero or print other bytes. FIND absent is a FAIL.
17note Inventory controls. gpu/runtime/controls.tsv, tab separated: NAME FILE TOKEN EXIT. The check named
18note inventory is run as SCRATCH/uI.bin DIR (I its number), DIR a copy of its inputs in SCRATCH: first unchanged (the
19note output must be gpu/runtime/INVENTORY.tsv, exit 0), then once per row with FILE's byte after the first
20note TOKEN changed (0 becomes 1, anything else 0; an empty TOKEN is the first byte). Caught: EXIT - when the
21note run exits nonzero or prints other bytes, a number when it exits with exactly that code.
22note Rewrites. Every row of gpu/runtime/rewrites.tsv (CUDAPP-PATH TAB OMEGA-PATH) must have its OMEGA-PATH as one
23note whole part of the PARTS of some check row, or it is a FAIL line. Control: the first row's OMEGA-PATH less its
24note last byte must be in no check's PARTS (a matcher that took a prefix or substring would pass it).
25note Control: a compiler one byte longer fails the digest check.
26note Output: one line per check and control, then
27note OMEGA-GPU-RUNTIME PASS|FAIL checks=N controls=C caught=K hardware=NOT_RUN; PASS needs N above 0, no FAIL line
28note and K equal to C. N and C follow the tables (each check row adds a check and a control, each control row a
29note control, plus the compiler control and the rewrites control), so no other file restates them.
30note Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 4 the host refused memory, 69 compiler digest refused.
31note Memory grows with the input (run-time pools), names included. The one fixed limit is the Linux path limit:
32note PATH_MAX is 4096 bytes with the terminating zero, so every path the gate builds (OMC, or SCRATCH/ plus a
33note file name of its own) must be under 4096 bytes, and a longer one is refused (exit 2) before any system call takes it.
34note A child that runs past 600 s is killed and is a FAIL line.
35text t_pin "seed/out/omc.sha256"
36text t_tab "gpu/runtime/checks.tsv"
37text t_ctab "gpu/runtime/controls.tsv"
38text t_inv "inventory"
39text t_invx "gpu/runtime/INVENTORY.tsv"
40text t_rt "gpu/runtime/"
41text t_null "/dev/null"
42text t_base "base"
43text t_in1 "cudapp-src.sha256.txt"
44text t_in2 "omega-base.sha256.txt"
45text t_in3 "cudapp-ident.txt"
46text t_in4 "pathmap.tsv"
47text t_in5 "rewrites.tsv"
48text t_om ".om"
49text t_bin ".bin"
50text t_err ".err"
51text t_out ".out"
52text t_mom ".m.om"
53text t_mbin ".m.bin"
54text t_merr ".m.err"
55text t_mout ".m.out"
56text t_l2 "om2"
57text t_plus "omc-plus-one"
58text t_usage "usage: gate OMC SCRATCH (run from the omega-mv repository root)\n"
59text t_refd "OMEGA-GPU-RUNTIME REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n"
60text t_nopin "OMEGA-GPU-RUNTIME INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n"
61text t_noscr "OMEGA-GPU-RUNTIME INVALID: SCRATCH exists or cannot be made\n"
62text t_notab "OMEGA-GPU-RUNTIME INVALID: cannot read gpu/runtime/checks.tsv or controls.tsv\n"
63text t_plong "OMEGA-GPU-RUNTIME INVALID: a path longer than 4095 bytes\n"
64text t_mem "OMEGA-GPU-RUNTIME: the host refused memory\n"
65text t_ok "ok "
66text t_fail "FAIL "
67text t_chk "check "
68text t_ctl "control "
69text t_bytes " bytes="
70text t_sha " sha256="
71text t_exit " exit="
72text t_mut " mutant"
73text t_row "malformed row"
74text t_src "source unreadable"
75text t_cmp "compile failed"
76text t_mcmp "mutant compile failed"
77text t_find "FIND not in part MPART"
78text t_wr "cannot write in SCRATCH"
79text t_run "run exit not 0"
80text t_diff "output differs from EXPECT"
81text t_mto "child passed the 600 s deadline and was killed: a timeout is not a catch"
82text t_noexp "EXPECT unreadable"
83text t_nobin "no inventory check"
84text t_none "no check passed"
85text t_ntok "TOKEN not in FILE"
86text t_caught " caught"
87text t_esc " ESCAPED"
88text t_sum "OMEGA-GPU-RUNTIME "
89text t_pass "PASS"
90text t_fl "FAIL"
91text t_sk " checks="
92text t_sc " controls="
93text t_sg " caught="
94text t_hw " hardware=NOT_RUN\n"
95text t_rwk "rewrite "
96text t_nochk " is in no check's PARTS"
97text t_rwc "rewrite-unchecked"
98text t_pre " prefix of a rewrite path"
99global g_pa uchar 4096
100global g_scr uchar 4096
101global g_omc uchar 4096
102global g_nm uchar *
103global g_pin uchar 64
104global g_stb uchar 4
105global g_n ulong 32
106global g_b uchar *
107global g_c uchar *
108global g_t uchar *
109global g_o uchar *
110note execprog takes a fixed array: at most two path arguments of under 4096 bytes each (pc refuses longer)
111global g_av uchar 8196
112note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length,
113note 6 g_b length, 7 g_c length, 8 checks passed, 9 name number K, 10 the inventory check's K, 11 failures,
114note 12 controls, 13 caught, 14 name length,
115note 15 g_t length, 16 inventory check passed, 17 a field start, 18 a field end
116note ---- memory
117fn die4 to void
118r = write 2 t_mem 0 len t_mem
119exit 4
120end
121fn growb n ulong to void
122if gt n len g_b
123r = enlarge g_b add mul len g_b 2 n
124if ne r 0
125die4
126end
127end
128end
129note g_nm holds at least n bytes
130fn nmgrow n ulong to void
131if gt n len g_nm
132r = enlarge g_nm add mul len g_nm 2 n
133if ne r 0
134die4
135end
136end
137end
138fn growc n ulong to void
139if gt n len g_c
140r = enlarge g_c add mul len g_c 2 n
141if ne r 0
142die4
143end
144end
145end
146note ---- output
147fn oc c ulong to void
148n = get g_n 5
149if ge n len g_o
150r = enlarge g_o add mul n 2 4096
151if ne r 0
152die4
153end
154end
155put g_o n uchar c
156put g_n 5 add n 1
157end
158fn ot t view uchar * to void
159for i ulong len t bound 4096
160oc ulong get t i
161end
162end
163fn onm to void
164for i ulong get g_n 14 bound 9223372036854775807
165oc ulong get g_nm i
166end
167end
168fn onum v ulong to void
169if ge v 10
170onum div v 10
171end
172oc add 48 rem v 10
173end
174fn ohex to void
175for j ulong 32
176b = get sh_dig j
177oc ulong sh_hexd uint shr b 4
178oc ulong sh_hexd uint and b 15
179end
180end
181fn oflush to void
182n = get g_n 5
183o = ulong 0
184while lt o n bound 9223372036854775807
185x = write 1 g_o o sub n o
186if le x 0
187exit 2
188end
189o = add o ulong x
190end
191put g_n 5 0
192end
193fn onl to void
194oc 10
195oflush
196end
197note a failed check: FAIL KIND NAME then the reason; counts a failure
198fn ofail kind view uchar * why view uchar * to void
199ot t_fail
200ot kind
201onm
202oc 32
203ot why
204onl
205put g_n 11 add get g_n 11 1
206end
207note ---- paths: g_pa[0, g_n 0)
208fn pclr to void
209put g_n 0 0
210end
211fn pc c ulong to void
212n = get g_n 0
213if ge n 4095
214r = write 2 t_plong 0 len t_plong
215exit 2
216end
217put g_pa n uchar c
218put g_n 0 add n 1
219end
220fn pt t view uchar * to void
221for i ulong len t bound 4096
222pc ulong get t i
223end
224end
225fn pscr to void
226for j ulong get g_n 2 bound 4096
227pc ulong get g_scr j
228end
229end
230note the scratch file stem uK: u, then K in decimal
231fn pstem k ulong to void
232pc 117
233pdec k
234end
235fn pdec v ulong to void
236if ge v 10
237pdec div v 10
238end
239pc add 48 rem v 10
240end
241note g_t[a, b) as path bytes
242fn ptr a ulong b ulong to void
243for i ulong sub b a bound 9223372036854775807
244pc ulong get g_t add a i
245end
246end
247note scratch file uK then suffix, K the number of the current name (g_n 9)
248fn psn suf view uchar * to void
249pclr
250pscr
251pstem get g_n 9
252pt suf
253end
254fn nmset t view uchar * to void
255put g_n 9 add get g_n 9 1
256nmgrow len t
257for i ulong len t bound 4096
258put g_nm i get t i
259end
260put g_n 14 len t
261end
262note ---- files
263fn fopn fl ulong mode ulong to int
264r = fopen g_pa 0 get g_n 0 int fl int mode
265if lt r 0
266ret -1
267end
268ret int r
269end
270fn frd to int
271ret fopn 524288 0
272end
273fn fwr to int
274ret fopn 524865 420
275end
276fn fexe to int
277r = unlink g_pa 0 get g_n 0
278ret fopn 524865 448
279end
280fn fclo fd int to void
281if ge fd 0
282r = fclose fd
283end
284end
285fn rdb fd int n ulong to long
286growb add n 65536
287ret read fd g_b n sub len g_b n
288end
289fn rdc fd int n ulong to long
290growc add n 65536
291ret read fd g_c n sub len g_c n
292end
293note append the file at g_pa to g_b (w 0) or g_c (w 1); false when unreadable
294fn fload w ulong to bool
295fd = frd
296if lt fd 0
297ret false
298end
299ok = true
300while true bound 9223372036854775807
301n = get g_n add 6 w
302x = long 0
303if eq w 0
304x = rdb fd n
305else
306x = rdc fd n
307end
308if lt x 0
309ok = false
310break
311end
312if eq x 0
313break
314end
315put g_n add 6 w add n ulong x
316end
317fclo fd
318ret ok
319end
320note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe)
321fn bsave exe bool to bool
322fd = int -1
323if exe
324fd = fexe
325else
326fd = fwr
327end
328if lt fd 0
329ret false
330end
331n = get g_n 6
332o = ulong 0
333ok = true
334while lt o n bound 9223372036854775807
335x = write fd g_b o sub n o
336if le x 0
337ok = false
338break
339end
340o = add o ulong x
341end
342fclo fd
343ret ok
344end
345note sha256 of the file at g_pa into sh_dig; false when unreadable
346fn fhash to bool
347fd = frd
348if lt fd 0
349ret false
350end
351zbeg
352ok = zfd fd
353fclo fd
354zend
355ret ok
356end
357note sha256 of g_b[0, g_n 6) into sh_dig
358fn bhash to void
359zbeg
360for i ulong get g_n 6 bound 9223372036854775807
361zbyte ulong get g_b i
362end
363zend
364end
365note g_b[0, g_n 6) equals g_c[0, g_n 7)
366fn bceq to bool
367n = get g_n 6
368if ne n get g_n 7
369ret false
370end
371for i ulong n bound 9223372036854775807
372if ne get g_b i get g_c i
373ret false
374end
375end
376ret true
377end
378note ---- processes
379fn aclr to void
380put g_n 3 2
381put g_n 4 0
382put g_av 0 0
383put g_av 1 0
384end
385note append g_pa as one argument
386fn apa to void
387p = get g_n 3
388n = get g_n 0
389for j ulong n bound 4096
390put g_av add add p 2 j get g_pa j
391end
392put g_av p uchar and n 255
393put g_av add p 1 uchar shr n 8
394put g_n 3 add p add n 2
395c = add get g_n 4 1
396put g_n 4 c
397put g_av 0 uchar and c 255
398put g_av 1 uchar shr c 8
399end
400fn redir s int d int to void
401if ne dupfd s d 0 long d
402exit 127
403end
404end
405note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512
406note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed)
407fn spawn fi int fo int fe int to ulong
408if or lt fi 0 or lt fo 0 lt fe 0
409fclo fi
410fclo fo
411fclo fe
412ret 512
413end
414pid = fork
415if lt pid 0
416exit 2
417end
418if eq pid 0
419redir fi 0
420redir fo 1
421redir fe 2
422r = execprog g_av 0 get g_n 3
423exit 127
424end
425fclo fi
426fclo fo
427fclo fe
428t0 = monons
429while true bound 9223372036854775807
430r = waitpid int pid g_stb 0 len g_stb 1
431if eq r pid
432x = ulong get g_stb 0
433if ne x 0
434ret add 256 x
435end
436ret ulong get g_stb 1
437end
438if lt r 0
439exit 2
440end
441if gt sub monons t0 600000000000
442r = killpid int pid 9
443r = waitpid int pid g_stb 0 len g_stb 0
444ret 1000
445end
446q = sleepns 200000
447end
448exit 2
449end
450fn pomc to void
451pclr
452for j ulong get g_n 1 bound 4096
453pc ulong get g_omc j
454end
455end
456note OMC < SCRATCH/uK.SRC > SCRATCH/uK.BIN 2> SCRATCH/uK.ERR
457fn omc src view uchar * bin view uchar * err view uchar * to ulong
458psn src
459fi = frd
460aclr
461pomc
462apa
463psn bin
464fo = fexe
465psn err
466fe = fwr
467ret spawn fi fo fe
468end
469note SCRATCH/uK.BIN < /dev/null > SCRATCH/uK.OUT 2> SCRATCH/uK.ERR
470fn runb bin view uchar * outf view uchar * err view uchar * to ulong
471pclr
472pt t_null
473fi = frd
474aclr
475psn bin
476apa
477psn outf
478fo = fwr
479psn err
480fe = fwr
481ret spawn fi fo fe
482end
483note ---- the compiler digest
484fn pinread to bool
485pclr
486pt t_pin
487put g_n 6 0
488if not fload 0
489ret false
490end
491if lt get g_n 6 64
492ret false
493end
494for j ulong 64
495c = get g_b j
496ok = or and ge c 48 le c 57 and ge c 97 le c 102
497if not ok
498ret false
499end
500put g_pin j c
501end
502ret true
503end
504note the file at g_pa hashes to g_pin
505fn pinok to bool
506if not fhash
507ret false
508end
509for j ulong 32
510b = get sh_dig j
511if ne get g_pin mul j 2 sh_hexd uint shr b 4
512ret false
513end
514if ne get g_pin add mul j 2 1 sh_hexd uint and b 15
515ret false
516end
517end
518ret true
519end
520note ---- the table g_t
521fn tis i ulong e ulong c ulong to bool
522if ge i e
523ret false
524end
525ret eq ulong get g_t i c
526end
527fn eol p ulong to ulong
528e = get g_n 15
529q = p
530while lt q e bound 9223372036854775807
531if eq get g_t q 10
532ret q
533end
534q = add q 1
535end
536ret e
537end
538note field k (from 0) of the tab-separated line [s, z) into g_n 17, 18; false when the line has fewer fields
539fn fld s ulong z ulong k ulong to bool
540a = s
541for f ulong k bound 9223372036854775807
542while and lt a z not tis a z 9 bound 9223372036854775807
543a = add a 1
544end
545if ge a z
546ret false
547end
548a = add a 1
549end
550b = a
551while and lt b z not tis b z 9 bound 9223372036854775807
552b = add b 1
553end
554put g_n 17 a
555put g_n 18 b
556ret true
557end
558fn nameok c ulong to bool
559if and ge c 48 le c 57
560ret true
561end
562if and ge c 65 le c 90
563ret true
564end
565if and ge c 97 le c 122
566ret true
567end
568ret or eq c 95 eq c 45
569end
570note field 0 of [s, z) to g_nm; false unless one or more name bytes
571fn nmfld s ulong z ulong to bool
572put g_n 9 add get g_n 9 1
573if not fld s z 0
574ret false
575end
576a = get g_n 17
577b = get g_n 18
578if eq a b
579ret false
580end
581nmgrow sub b a
582for i ulong sub b a bound 9223372036854775807
583c = ulong get g_t add a i
584if not nameok c
585ret false
586end
587put g_nm i uchar c
588end
589put g_n 14 sub b a
590ret true
591end
592note ---- compose: parts field [a, b), part number mp (from 1) mutated by FIND [fa, fb) to REPLACE [ra, rb)
593note when mp is not 0; false (a FAIL line written) when a part is unreadable or FIND is absent
594fn cat i ulong fa ulong k ulong to bool
595for j ulong k bound 9223372036854775807
596c = get g_c add i j
597if ne c get g_t add fa j
598ret false
599end
600end
601ret true
602end
603note the first FIND [fa, fb) in g_c[0, g_n 7), or g_n 7 when absent or empty
604fn cfind fa ulong fb ulong to ulong
605n = get g_n 7
606k = sub fb fa
607if or eq k 0 gt k n
608ret n
609end
610for i ulong add sub n k 1 bound 9223372036854775807
611if cat i fa k
612ret i
613end
614end
615ret n
616end
617fn bput c ulong to void
618n = get g_n 6
619growb add n 1
620put g_b n uchar c
621put g_n 6 add n 1
622end
623note g_c to g_b, the first FIND replaced; false when FIND is absent
624fn cmut fa ulong fb ulong ra ulong rb ulong to bool
625n = get g_n 7
626p = cfind fa fb
627if ge p n
628ret false
629end
630for i ulong p bound 9223372036854775807
631bput ulong get g_c i
632end
633for i ulong sub rb ra bound 9223372036854775807
634bput ulong get g_t add ra i
635end
636q = add p sub fb fa
637for i ulong sub n q bound 9223372036854775807
638bput ulong get g_c add q i
639end
640ret true
641end
642fn ctx t view uchar * to void
643for i ulong len t bound 4096
644bput ulong get t i
645end
646end
647fn isom2 a ulong b ulong to bool
648if ne sub b a 3
649ret false
650end
651for i ulong 3
652if ne get g_t add a i get t_l2 i
653ret false
654end
655end
656ret true
657end
658fn compose a ulong b ulong mp ulong to bool
659put g_n 6 0
660i = a
661k = ulong 1
662while lt i b bound 9223372036854775807
663j = i
664while and lt j b not tis j b 44 bound 9223372036854775807
665j = add j 1
666end
667if isom2 i j
668ctx t_l2
669else
670pclr
671ptr i j
672put g_n 7 0
673if not fload 1
674ofail t_chk t_src
675ret false
676end
677if eq k mp
678if not cmut get g_n 19 get g_n 20 get g_n 21 get g_n 22
679ofail t_chk t_find
680ret false
681end
682else
683for q ulong get g_n 7 bound 9223372036854775807
684bput ulong get g_c q
685end
686end
687end
688bput 10
689k = add k 1
690i = add j 1
691end
692ret true
693end
694note ---- one check row [s, z)
695note load EXPECT [ea, eb) into g_c, SCRATCH/uK.OUTF into g_b; true when equal (the output sha256 in sh_dig)
696fn cmpout ea ulong eb ulong outf view uchar * to ulong
697pclr
698ptr ea eb
699put g_n 7 0
700if not fload 1
701ret 2
702end
703psn outf
704put g_n 6 0
705if not fload 0
706ret 1
707end
708bhash
709if bceq
710ret 0
711end
712ret 1
713end
714fn cfail why view uchar * r ulong to void
715ot t_fail
716ot t_chk
717onm
718oc 32
719ot why
720ot t_exit
721onum r
722onl
723put g_n 11 add get g_n 11 1
724end
725fn crow s ulong z ulong to void
726if not nmset2 s z
727ret
728end
729if not fld s z 1
730ofail t_chk t_row
731ret
732end
733pa = get g_n 17
734pb = get g_n 18
735if not fld s z 2
736ofail t_chk t_row
737ret
738end
739ea = get g_n 17
740eb = get g_n 18
741if not crowm s z
742ofail t_chk t_row
743ret
744end
745if not compose pa pb 0
746ret
747end
748psn t_om
749if not bsave false
750ofail t_chk t_wr
751ret
752end
753r = omc t_om t_bin t_err
754if ne r 0
755cfail t_cmp r
756ret
757end
758r = runb t_bin t_out t_err
759if ne r 0
760cfail t_run r
761ret
762end
763c = cmpout ea eb t_out
764if eq c 2
765ofail t_chk t_noexp
766ret
767end
768if ne c 0
769ofail t_chk t_diff
770ret
771end
772ot t_ok
773ot t_chk
774onm
775ot t_bytes
776onum get g_n 6
777ot t_sha
778ohex
779onl
780put g_n 8 add get g_n 8 1
781if istx t_inv
782put g_n 16 1
783put g_n 10 get g_n 9
784end
785cmutant pa pb ea eb
786end
787note name field to g_nm, or a FAIL line
788fn nmset2 s ulong z ulong to bool
789if nmfld s z
790ret true
791end
792put g_n 14 0
793ofail t_chk t_row
794ret false
795end
796note MPART, FIND, REPLACE of row [s, z) into g_n 23, 19..22
797fn crowm s ulong z ulong to bool
798if not fld s z 3
799ret false
800end
801a = get g_n 17
802b = get g_n 18
803if or eq a b gt sub b a 18
804ret false
805end
806m = ulong 0
807for i ulong sub b a bound 32
808c = ulong get g_t add a i
809if or lt c 48 gt c 57
810ret false
811end
812m = add mul m 10 sub c 48
813end
814if eq m 0
815ret false
816end
817put g_n 23 m
818if not fld s z 4
819ret false
820end
821if eq get g_n 17 get g_n 18
822ret false
823end
824put g_n 19 get g_n 17
825put g_n 20 get g_n 18
826if not fld s z 5
827ret false
828end
829put g_n 21 get g_n 17
830put g_n 22 get g_n 18
831ret true
832end
833fn istx t view uchar * to bool
834if ne get g_n 14 len t
835ret false
836end
837for i ulong len t bound 4096
838if ne get g_nm i get t i
839ret false
840end
841end
842ret true
843end
844note the mutant of the current check: compiles, then exits nonzero or prints other bytes
845fn cmutant pa ulong pb ulong ea ulong eb ulong to void
846put g_n 12 add get g_n 12 1
847if not compose pa pb get g_n 23
848ret
849end
850psn t_mom
851if not bsave false
852ofail t_chk t_wr
853ret
854end
855r = omc t_mom t_mbin t_merr
856if ne r 0
857cfail t_mcmp r
858ret
859end
860r = runb t_mbin t_mout t_merr
861if eq r 1000
862cfail t_mto r
863ret
864end
865c = cmpout ea eb t_mout
866if eq c 2
867ofail t_chk t_noexp
868ret
869end
870caught or ne r 0 ne c 0 t_mut
871end
872fn caught c bool what view uchar * to void
873if c
874ot t_ok
875ot t_ctl
876onm
877ot what
878ot t_caught
879onl
880put g_n 13 add get g_n 13 1
881else
882ot t_fail
883ot t_ctl
884onm
885ot what
886ot t_esc
887onl
888put g_n 11 add get g_n 11 1
889end
890end
891fn tload tb view uchar * to bool
892pclr
893pt tb
894put g_n 6 0
895if not fload 0
896ret false
897end
898n = get g_n 6
899r = enlarge g_t n
900if ne r 0
901die4
902end
903for i ulong n bound 9223372036854775807
904put g_t i get g_b i
905end
906put g_n 15 n
907ret true
908end
909fn rowskip s ulong z ulong to bool
910if eq s z
911ret true
912end
913ret eq get g_t s 35
914end
915fn checks to void
916e = get g_n 15
917s = ulong 0
918while lt s e bound 9223372036854775807
919z = eol s
920if not rowskip s z
921crow s z
922end
923s = add z 1
924end
925end
926note ---- rewrites.tsv against the PARTS of checks.tsv (in g_t)
927note g_b[a, b) equals g_t[i, j)
928fn bteq a ulong b ulong i ulong j ulong to bool
929if ne sub b a sub j i
930ret false
931end
932for k ulong sub b a bound 9223372036854775807
933if ne get g_b add a k get g_t add i k
934ret false
935end
936end
937ret true
938end
939note one comma-separated part of the PARTS of the check row [s, z) is g_b[a, b)
940fn rowhas a ulong b ulong s ulong z ulong to bool
941if not fld s z 1
942ret false
943end
944i = get g_n 17
945e = get g_n 18
946while le i e bound 9223372036854775807
947j = i
948while and lt j e not tis j e 44 bound 9223372036854775807
949j = add j 1
950end
951if bteq a b i j
952ret true
953end
954i = add j 1
955end
956ret false
957end
958fn tabhas a ulong b ulong to bool
959e = get g_n 15
960s = ulong 0
961while lt s e bound 9223372036854775807
962z = eol s
963if not rowskip s z
964if rowhas a b s z
965ret true
966end
967end
968s = add z 1
969end
970ret false
971end
972note the first byte c (or q) in g_b[p, q)
973fn bto p ulong q ulong c ulong to ulong
974i = p
975while lt i q bound 9223372036854775807
976if eq ulong get g_b i c
977ret i
978end
979i = add i 1
980end
981ret q
982end
983fn rwnot a ulong b ulong to void
984ot t_fail
985ot t_rwk
986for i ulong sub b a bound 9223372036854775807
987oc ulong get g_b add a i
988end
989ot t_nochk
990onl
991put g_n 11 add get g_n 11 1
992end
993fn rwchk to void
994pclr
995pt t_rt
996pt t_in5
997put g_n 6 0
998if not fload 0
999nmset t_in5
1000ofail t_chk t_src
1001ret
1002end
1003e = get g_n 6
1004s = ulong 0
1005first = true
1006while lt s e bound 9223372036854775807
1007z = bto s e 10
1008if and lt s z ne get g_b s 35
1009t = bto s z 9
1010if ge add t 1 z
1011nmset t_in5
1012ofail t_chk t_row
1013ret
1014end
1015a = add t 1
1016b = bto a z 9
1017if not tabhas a b
1018rwnot a b
1019end
1020if first
1021first = false
1022put g_n 12 add get g_n 12 1
1023nmset t_rwc
1024caught not tabhas a sub b 1 t_pre
1025end
1026end
1027s = add z 1
1028end
1029end
1030note ---- inventory controls
1031note copy gpu/runtime/FILE to SCRATCH/uKd/FILE (K the number of the current name); with flip, change the byte
1032note after the first TOKEN [ta, tb) of g_n 19, 20 when FILE is FL [fa, fb) of g_t; false on a failure
1033fn cpin f view uchar * flip bool fa ulong fb ulong to bool
1034pclr
1035pt t_rt
1036pt f
1037put g_n 7 0
1038if not fload 1
1039ret false
1040end
1041put g_n 6 0
1042mine = flip
1043if mine
1044mine = tfeq fa fb f
1045end
1046if mine
1047p = cfind get g_n 19 get g_n 20
1048if eq get g_n 19 get g_n 20
1049p = ulong 0
1050else
1051p = add p sub get g_n 20 get g_n 19
1052end
1053if ge p get g_n 7
1054put g_n 24 1
1055ret true
1056end
1057c = get g_c p
1058if eq c 48
1059put g_c p 49
1060else
1061put g_c p 48
1062end
1063end
1064for q ulong get g_n 7 bound 9223372036854775807
1065bput ulong get g_c q
1066end
1067pdir
1068pt f
1069ret bsave false
1070end
1071fn tfeq a ulong b ulong t view uchar * to bool
1072if ne sub b a len t
1073ret false
1074end
1075for i ulong len t bound 4096
1076if ne get g_t add a i get t i
1077ret false
1078end
1079end
1080ret true
1081end
1082fn pdir to void
1083pclr
1084pscr
1085pstem get g_n 9
1086pc 100
1087pc 47
1088end
1089note make SCRATCH/uKd with the inventory inputs, FILE [fa, fb) flipped when flip
1090fn mkin flip bool fa ulong fb ulong to bool
1091pdir
1092x = makedir g_pa 0 sub get g_n 0 1 448
1093if ne x 0
1094ret false
1095end
1096put g_n 24 0
1097ok = cpin t_in1 flip fa fb
1098ok = and ok cpin t_in2 flip fa fb
1099ok = and ok cpin t_in3 flip fa fb
1100ok = and ok cpin t_in4 flip fa fb
1101ok = and ok cpin t_in5 flip fa fb
1102ret ok
1103end
1104note run SCRATCH/uI.bin SCRATCH/uKd (I the inventory check's number, g_n 10); out and err as uK.out / uK.err
1105fn invrun to ulong
1106aclr
1107pclr
1108pscr
1109pstem get g_n 10
1110pt t_bin
1111apa
1112pdir
1113put g_n 0 sub get g_n 0 1
1114apa
1115pclr
1116pt t_null
1117fi = frd
1118psn t_out
1119fo = fwr
1120psn t_err
1121fe = fwr
1122ret spawn fi fo fe
1123end
1124note the unchanged copy SCRATCH/uKd: exit 0 and exactly INVENTORY.tsv (proves the copied input set is complete)
1125fn ctlbase to bool
1126nmset t_base
1127if not mkin false 0 0
1128ofail t_ctl t_wr
1129ret false
1130end
1131r = invrun
1132pclr
1133pt t_invx
1134put g_n 7 0
1135if not fload 1
1136ofail t_ctl t_noexp
1137ret false
1138end
1139c = invout
1140if or ne r 0 not c
1141cfail t_diff r
1142ret false
1143end
1144ot t_ok
1145ot t_ctl
1146onm
1147ot t_bytes
1148onum get g_n 6
1149onl
1150ret true
1151end
1152note SCRATCH/uK.out of the last invrun (K the row name's number) into g_b; equal to g_c
1153fn invout to bool
1154psn t_out
1155put g_n 6 0
1156if not fload 0
1157ret false
1158end
1159ret bceq
1160end
1161fn ctlrow s ulong z ulong to void
1162put g_n 12 add get g_n 12 1
1163if not nmfld s z
1164put g_n 14 0
1165ofail t_ctl t_row
1166ret
1167end
1168if not fld s z 1
1169ofail t_ctl t_row
1170ret
1171end
1172fa = get g_n 17
1173fb = get g_n 18
1174if not fld s z 2
1175ofail t_ctl t_row
1176ret
1177end
1178put g_n 19 get g_n 17
1179put g_n 20 get g_n 18
1180if not fld s z 3
1181ofail t_ctl t_row
1182ret
1183end
1184ea = get g_n 17
1185eb = get g_n 18
1186if not mkin true fa fb
1187ofail t_ctl t_wr
1188ret
1189end
1190if ne get g_n 24 0
1191ofail t_ctl t_ntok
1192ret
1193end
1194r = invrun
1195if eq r 1000
1196ofail t_ctl t_mto
1197ret
1198end
1199pclr
1200pt t_invx
1201put g_n 7 0
1202if not fload 1
1203ofail t_ctl t_noexp
1204ret
1205end
1206c = invout
1207ex = ctlexp ea eb
1208if eq ex 1000000
1209caught or ne r 0 not c t_mut
1210else
1211caught eq r ex t_mut
1212end
1213end
1214note EXIT field [a, b): - is 1000000, else the number
1215fn ctlexp a ulong b ulong to ulong
1216if and eq sub b a 1 eq get g_t a 45
1217ret 1000000
1218end
1219m = ulong 0
1220for i ulong sub b a bound 32
1221c = ulong get g_t add a i
1222m = add mul m 10 sub c 48
1223end
1224ret m
1225end
1226fn controls to void
1227if eq get g_n 16 0
1228nmset t_inv
1229ofail t_ctl t_nobin
1230ret
1231end
1232pclr
1233pt t_invx
1234put g_n 7 0
1235if not fload 1
1236nmset t_inv
1237ofail t_ctl t_noexp
1238ret
1239end
1240if not ctlbase
1241ret
1242end
1243e = get g_n 15
1244s = ulong 0
1245while lt s e bound 9223372036854775807
1246z = eol s
1247if not rowskip s z
1248ctlrow s z
1249end
1250s = add z 1
1251end
1252end
1253note ---- the wrong-compiler control: OMC one byte longer must fail the digest check
1254fn cwrong to void
1255put g_n 12 add get g_n 12 1
1256pomc
1257put g_n 6 0
1258ok = fload 0
1259bput 0
1260nmset t_plus
1261psn t_bin
1262ok = and ok bsave true
1263psn t_bin
1264c = and ok not pinok
1265caught c t_mut
1266end
1267note ---- main
1268fn ausage to int
1269r = write 2 t_usage 0 len t_usage
1270ret 2
1271end
1272fn main to int
1273if ne argcnt 3
1274ret ausage
1275end
1276r = argread 1 g_omc 0 4095
1277if lt r 0
1278r = write 2 t_plong 0 len t_plong
1279ret 2
1280end
1281if eq r 0
1282ret ausage
1283end
1284put g_n 1 ulong r
1285if not pinread
1286r = write 2 t_nopin 0 len t_nopin
1287ret 2
1288end
1289pomc
1290if not pinok
1291r = write 2 t_refd 0 len t_refd
1292ret 69
1293end
1294r = argread 2 g_scr 0 4094
1295if lt r 0
1296r = write 2 t_plong 0 len t_plong
1297ret 2
1298end
1299if eq r 0
1300ret ausage
1301end
1302n = ulong r
1303x = makedir g_scr 0 n 448
1304if ne x 0
1305r = write 2 t_noscr 0 len t_noscr
1306ret 2
1307end
1308put g_scr n 47
1309put g_n 2 add n 1
1310if not tload t_tab
1311r = write 2 t_notab 0 len t_notab
1312ret 2
1313end
1314checks
1315rwchk
1316if not tload t_ctab
1317r = write 2 t_notab 0 len t_notab
1318ret 2
1319end
1320controls
1321cwrong
1322if eq get g_n 8 0
1323nmset t_tab
1324ofail t_chk t_none
1325end
1326f = get g_n 11
1327ot t_sum
1328if eq f 0
1329ot t_pass
1330else
1331ot t_fl
1332end
1333ot t_sk
1334onum get g_n 8
1335ot t_sc
1336onum get g_n 12
1337ot t_sg
1338onum get g_n 13
1339ot t_hw
1340oflush
1341if ne f 0
1342ret 1
1343end
1344if ne get g_n 12 get g_n 13
1345ret 1
1346end
1347ret 0
1348end