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 / qualification / security673 / relational / evidence / run1 / gate.src

2216 lines · 36494 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/qualification/om2/gate.om: OM-2 qualification coordinator (#748, ledger L836).
3note Handwritten seeded Omega, program mode, Linux AArch64, modelled on security673/gate669.om.
4note
5note Run from the repository root: gate OMC OMC_SHA256 CASES SCRATCH
6note OMC compiler under test (path); every case source is compiled by it
7note OMC_SHA256 64 lowercase hex digits; the gate hashes OMC itself (FIPS 180-4 SHA-256 written
8note below, constants read from the bc-derived fixtures) and refuses to run any case
9note when the digest differs: every case is then NOT_RUN and the gate is INVALID
10note CASES case list file, at most 1048576 bytes
11note SCRATCH evidence directory; must not exist (exit 91), created 0700, never overwritten
12note
13note Case list: one line per case, words separated by single or repeated spaces, # starts a comment
14note line. Paths are relative to the working directory. Scratch files are SCRATCH/<line>.<suffix>.
15note NAME run SRC STDIN STDOUT STDERR EXIT [ARG ...] compile SRC (exit 0, ELF), run it with
16note a deadline; PASS only if exit, stdout and stderr all equal the expectation
17note NAME kill SRC STDIN ORACLE STDERR EXIT [ARG ...] a mutant: PASS only if it exits with EXIT,
18note stderr matches and stdout DIFFERS from the oracle (reports the first byte); a
19note survivor or any other exit is FAIL; a signal or timeout is INVALID, never a kill
20note NAME refuse SRC CODE PASS only if the compiler exits CODE, writes no output and its
21note diagnostic names "error CODE"
22note NAME emit SRC STDOUT STDERR EXIT compile only: PASS only if the compiler exits EXIT and its
23note stdout and stderr equal the expectations (the C2 manifest is a list of these)
24note NAME same SRC1 SRC2 PASS only if both compile with exit 0 to byte-identical outputs
25note (SRC2's scratch files carry a .b suffix); never after a subst
26note NAME notrun REASON ... recorded as NOT_RUN (a planned case whose prerequisite is absent)
27note cc pinned | cc SRC later cases use OMC, or a compiler built from SRC by the pinned OMC;
28note the built compiler's sha256 is printed; a failed build makes later cases NOT_RUN
29note deadline SECONDS per-child deadline, 1..900 (default 30)
30note subst FROMFILE TOFILE the next run/kill/refuse/cc source gets the bytes of FROMFILE
31note replaced by those of TOFILE; the source must contain FROMFILE exactly once
32note SRC is one segment or several joined by + (concatenated in order into SCRATCH/<line>.src, at
33note most 16 MiB): a path, pack:PATH:OFF:LEN (LEN bytes of PATH from byte OFF) or cyc:PATH:N (N bytes
34note repeating the bytes of PATH).
35note STDIN: - (/dev/null) | file:PATH | rep:BYTE:N (N copies) | seq:N (byte i = i mod 251) |
36note rnd:SEED:N (splitmix64 from SEED, each output word little endian).
37note STDOUT, STDERR: - (empty) | file:PATH | line:TEXT (TEXT and a newline) | any (STDERR, and emit
38note STDOUT). emit STDOUT also: sha:HEX (sha256 of the compiler output, 64 lowercase hex).
39note emit STDERR also: err:LINE:CODE (exactly "omc: line LINE: error CODE" and a newline),
40note has:PATH (each line of PATH is a whole stderr line, in any order) and tok:PATH (each
41note line of PATH has all its words, as whole words, in one stderr line).
42note EXIT 127 is refused: the child uses it to report an exec or redirect failure.
43note
44note Per case: CASE line, one " $" line per child command with its redirects, one VERDICT line:
45note PASS, FAIL (deterministic wrong behaviour), INVALID (no evidence: malformed line, unreadable
46note input, signal, timeout, exec failure, scratch I/O) or NOT_RUN. Final line, exit status:
47note OM2GATE PASS 0 | FAIL 1 | NOT_RUN 2 | INVALID 3 (any INVALID case, identity mismatch, no cases).
48note Usage error 90, existing scratch 91. This is not a sandbox: children run with the caller's
49note permissions, the deadline covers only the direct child, and only trusted sources belong here.
50text words "run\nkill\nrefuse\nnotrun\ncc\ndeadline\nsubst\npinned\n-\nfile:\nline:\nrep:\nseq:\nrnd:\nany\n.src\n.elf\n.cout\n.cerr\n.in\n.exp\n.eexp\n.out\n.err\nerror \nseed/qualification/om2/fixtures/sha256-k.dec\nseed/qualification/om2/fixtures/sha256-iv.dec\n/dev/null\nemit\nsame\nsha:\n.b\nerr:\nomc: line \n: error \nhas:\ntok:\ncyc:\npack:\n"
51text msg "VERDICT \n PASS\n FAIL\n INVALID\n NOT_RUN\n compile exit=\n expected=\n run exit=\n stdout=match\n stdout differs at byte \n stderr=match\n stderr differs at byte \n mutant survived: stdout equals the oracle\n killed: stdout differs from the oracle at byte \n compiler exit 0 but its output is not an ELF file\n refusal wrote compiler output\n diagnostic does not name the expected error\n child signal; wait low byte=\n child deadline exceeded, sent SIGKILL; wait low byte=\n malformed case line\n input, source or fixture unreadable or too large\n scratch I/O, fork or argument capacity failure\n exec or redirect failed (child exit 127)\n refused with the expected error\nOM2GATE PASS\nOM2GATE FAIL\nOM2GATE INVALID\nOM2GATE NOT_RUN\n cases=\n pass=\n fail=\n invalid=\n not_run=\nIDENTITY omc \n sha256=\n pinned=\n match\n MISMATCH: every case is NOT_RUN and the gate is INVALID\n $ \n < \n > \n 2> \nCASE \n line=\n compiler build failed earlier; case not run\n omc identity mismatch; case not run\n substitution must match exactly once; matches=\n MUTATE exact-once substitution at byte \nCOMPILER \n stderr=unchecked\n a substitution was not followed by a source-building line\n no cases\nUSAGE gate OMC OMC_SHA256 CASES SCRATCH; INVALID\nINVALID scratch directory exists or cannot be created\nINVALID SHA-256 constant fixture unreadable or malformed\nINVALID case list unreadable or larger than 1048576 bytes\n not run:\n; not a meaningful kill\n compiler build: compile exit=\nDEADLINE \nSUBST \n source line=\nOM2GATE START cases=\n scratch=\n stdout sha256 differs; expected \n stdout=unchecked\n outputs identical\n outputs differ at byte \n second compile exit=\n stderr lacks expected line \n"
52global pb uchar 4096
53global pn ulong 1
54global scr uchar 4096
55global scn ulong 1
56global omc uchar 4096
57global omn ulong 1
58global ccp uchar 4096
59global ccn ulong 1
60global pin uchar 64
61global hexd uchar 64
62global av uchar 4096
63global ap ulong 2
64global lst uchar 1048576
65global lsn ulong 1
66global tko ulong 64
67global tkl ulong 64
68global ntk ulong 1
69global big uchar 16777216
70global bgn ulong 1
71global sfr uchar 65536
72global sto uchar 65536
73global sb ulong 3
74global sx ulong 2
75global buf uchar 65536
76global oth uchar 65536
77global dig uchar 32
78global stb uchar 4
79global gst ulong 1
80global wlow ulong 1
81global dl long 1
82global cnt ulong 4
83global ccbad ulong 1
84global idok ulong 1
85global wpos ulong 2
86global lno ulong 1
87global res ulong 8
88global rz ulong 2
89global kk uint 64
90global ivs uint 8
91global hv uint 8
92global ws uint 64
93global st uint 8
94global blk uchar 64
95global bk ulong 2
96global nums ulong 64
97note ---- output -------------------------------------------------------------------------------
98fn say id ulong to void
99k = ulong 1
100s = ulong 0
101for i ulong len msg
102if eq get msg i 10
103if eq k id
104r = write 1 msg s sub i s
105ret
106end
107k = add k 1
108s = add i 1
109end
110end
111exit 99
112end
113fn newline to void
114put dig 0 10
115r = write 1 dig 0 1
116end
117fn space to void
118put dig 0 32
119r = write 1 dig 0 1
120end
121fn decimal v ulong to ulong
122x = v
123n = ulong 0
124while ge x 10
125put dig n uchar add 48 rem x 10
126x = div x 10
127n = add n 1
128end
129put dig n uchar add 48 x
130ret add n 1
131end
132fn num v ulong to void
133n = decimal v
134for i ulong n
135r = write 1 dig sub sub n i 1 1
136end
137end
138fn showpb to void
139r = write 1 pb 0 get pn 0
140end
141fn showtok t ulong to void
142r = write 1 lst get tko t get tkl t
143end
144fn setbad id ulong to void
145if eq get gst 0 0
146put gst 0 id
147end
148end
149note ---- fixed words and tokens ---------------------------------------------------------------
150fn wordat id ulong to void
151k = ulong 1
152s = ulong 0
153for i ulong len words
154if eq get words i 10
155if eq k id
156put wpos 0 s
157put wpos 1 sub i s
158ret
159end
160k = add k 1
161s = add i 1
162end
163end
164exit 99
165end
166fn tokpre t ulong id ulong to bool
167wordat id
168n = get wpos 1
169if lt get tkl t n
170ret false
171end
172o = get tko t
173s = get wpos 0
174for i ulong n
175if ne get lst add o i get words add s i
176ret false
177end
178end
179ret true
180end
181fn tokword t ulong id ulong to bool
182wordat id
183if ne get tkl t get wpos 1
184ret false
185end
186ret tokpre t id
187end
188note decimal digits lst[o .. o+n); malformed or overflowing text marks the case malformed
189fn decat o ulong n ulong to ulong
190if or eq n 0 gt n 20
191setbad 20
192ret 0
193end
194m = not ulong 0
195v = ulong 0
196for i ulong n
197c = get lst add o i
198if or lt c 48 gt c 57
199setbad 20
200ret 0
201end
202d = ulong sub c 48
203if gt v div sub m d 10
204setbad 20
205ret 0
206end
207v = add mul v 10 d
208end
209ret v
210end
211note field k (0-based) of the ':'-separated fields after the first skip bytes of token t
212fn fieldat t ulong skip ulong k ulong to ulong
213o = add get tko t skip
214e = add get tko t get tkl t
215f = ulong 0
216s = o
217for i ulong sub e o
218if eq get lst add o i 58
219if eq f k
220ret decat s sub add o i s
221end
222f = add f 1
223s = add add o i 1
224end
225end
226if eq f k
227ret decat s sub e s
228end
229setbad 20
230ret 0
231end
232fn fields t ulong skip ulong to ulong
233f = ulong 1
234o = add get tko t skip
235for i ulong sub get tkl t skip
236if eq get lst add o i 58
237f = add f 1
238end
239end
240ret f
241end
242note ---- paths and child argument lists --------------------------------------------------------
243fn pclear to void
244put pn 0 0
245end
246fn pbyte b uchar to void
247n = get pn 0
248if ge n 4095
249setbad 22
250ret
251end
252put pb n b
253put pn 0 add n 1
254end
255fn pword id ulong to void
256wordat id
257s = get wpos 0
258for i ulong get wpos 1
259pbyte get words add s i
260end
261end
262fn plst o ulong n ulong to void
263for i ulong n
264pbyte get lst add o i
265end
266end
267fn pnum v ulong to void
268n = decimal v
269for i ulong n
270pbyte get dig sub sub n i 1
271end
272end
273fn pomc to void
274pclear
275for i ulong get omn 0
276pbyte get omc i
277end
278end
279fn pccp to void
280pclear
281for i ulong get ccn 0
282pbyte get ccp i
283end
284end
285note SCRATCH/<line>.<word id>, with ".b" appended while sx[0] is set (the second source of `same`)
286fn pfile id ulong to void
287pclear
288for i ulong get scn 0
289pbyte get scr i
290end
291pnum get lno 0
292pword id
293if ne get sx 0 0
294pword 32
295end
296end
297fn popen fl int to int
298if ne get gst 0 0
299ret -1
300end
301r = fopen pb 0 get pn 0 fl 384
302if lt r 0
303ret -1
304end
305ret int r
306end
307fn fclo fd int to void
308if ge fd 0
309r = fclose fd
310end
311end
312fn aclear to void
313put ap 0 2
314put ap 1 0
315end
316fn ahead n ulong to bool
317p = get ap 0
318if or gt add add p n 2 len av ge get ap 1 64
319setbad 22
320ret false
321end
322put av p uchar and n 255
323put av add p 1 uchar shr n 8
324put ap 0 add p 2
325put ap 1 add get ap 1 1
326ret true
327end
328fn apb to void
329n = get pn 0
330if ahead n
331p = get ap 0
332for i ulong n
333put av add p i get pb i
334end
335put ap 0 add p n
336end
337end
338fn atok t ulong to void
339n = get tkl t
340o = get tko t
341if ahead n
342p = get ap 0
343for i ulong n
344put av add p i get lst add o i
345end
346put ap 0 add p n
347end
348end
349note ---- children ------------------------------------------------------------------------------
350fn redir s int d int to void
351if ne s d
352if ne dupfd s d 0 long d
353exit 127
354end
355end
356end
357fn reap pid int to ulong
358t0 = monons
359while true
360r = waitpid pid stb 0 len stb 1
361if eq r long pid
362if ne get stb 0 0
363put wlow 0 ulong get stb 0
364setbad 18
365ret 0
366end
367x = ulong get stb 1
368if eq x 127
369setbad 23
370end
371ret x
372end
373if lt r 0
374setbad 22
375ret 0
376end
377now = monons
378if or lt now t0 gt sub now t0 get dl 0
379r = killpid pid 9
380r = waitpid pid stb 0 len stb 0
381put wlow 0 ulong get stb 0
382setbad 19
383ret 0
384end
385if ne sleepns 1000000 0
386setbad 22
387ret 0
388end
389end
390exit 99
391end
392fn spawn fi int fo int fe int to ulong
393newline
394if ne get gst 0 0
395fclo fi
396fclo fo
397fclo fe
398ret 0
399end
400put av 0 uchar and get ap 1 255
401put av 1 uchar shr get ap 1 8
402pid = fork
403if lt pid 0
404fclo fi
405fclo fo
406fclo fe
407setbad 22
408ret 0
409end
410if eq pid 0
411redir fi 0
412redir fo 1
413redir fe 2
414r = execprog av 0 get ap 0
415exit 127
416end
417fclo fi
418fclo fo
419fclo fe
420ret reap int pid
421end
422note compile SCRATCH/<line>.src with the pinned omc (pinned true) or the current compiler
423fn compile pinned bool to ulong
424aclear
425say 39
426if pinned
427pomc
428else
429pccp
430end
431showpb
432apb
433say 40
434pfile 16
435showpb
436fi = popen 524288
437say 41
438pfile 17
439showpb
440fo = popen 524481
441say 42
442pfile 19
443showpb
444fe = popen 524481
445ret spawn fi fo fe
446end
447fn stdinpath t ulong to void
448pclear
449if tokword t 9
450pword 28
451ret
452end
453if tokpre t 10
454plst add get tko t 5 sub get tkl t 5
455ret
456end
457pfile 20
458end
459fn runprog to ulong
460aclear
461say 39
462pfile 17
463showpb
464apb
465for j ulong sub get ntk 0 7
466space
467showtok add j 7
468atok add j 7
469end
470say 40
471stdinpath 3
472showpb
473fi = popen 524288
474say 41
475pfile 23
476showpb
477fo = popen 524481
478say 42
479pfile 24
480showpb
481fe = popen 524481
482ret spawn fi fo fe
483end
484note ---- file helpers --------------------------------------------------------------------------
485fn rfulla fd int to long
486n = ulong 0
487while lt n len buf
488r = read fd buf n sub len buf n
489if lt r 0
490ret r
491end
492if eq r 0
493ret long n
494end
495n = add n ulong r
496end
497ret long n
498end
499fn rfullb fd int to long
500n = ulong 0
501while lt n len oth
502r = read fd oth n sub len oth n
503if lt r 0
504ret r
505end
506if eq r 0
507ret long n
508end
509n = add n ulong r
510end
511ret long n
512end
513fn firstdif m ulong to ulong
514for i ulong m
515if ne get buf i get oth i
516ret i
517end
518end
519ret m
520end
521note first differing byte of two scratch files, or not 0 when they are equal; file b carries the
522note ".b" suffix when sx[1] is set
523fn diffat a ulong b ulong to ulong
524pfile a
525fa = popen 524288
526put sx 0 get sx 1
527pfile b
528put sx 0 0
529fb = popen 524288
530if or lt fa 0 lt fb 0
531fclo fa
532fclo fb
533setbad 22
534ret 0
535end
536off = ulong 0
537while true
538ra = rfulla fa
539rb = rfullb fb
540if or lt ra 0 lt rb 0
541fclo fa
542fclo fb
543setbad 22
544ret 0
545end
546m = ulong ra
547if lt rb ra
548m = ulong rb
549end
550d = firstdif m
551if lt d m
552fclo fa
553fclo fb
554ret add off d
555end
556if or ne ra rb eq ra 0
557fclo fa
558fclo fb
559if eq ra rb
560ret not ulong 0
561end
562ret add off m
563end
564off = add off m
565end
566exit 99
567end
568fn copyfd s int d int to void
569while true
570r = rfulla s
571if lt r 0
572setbad 21
573ret
574end
575if eq r 0
576ret
577end
578if ne write d buf 0 ulong r r
579setbad 22
580ret
581end
582end
583end
584note compiler output: ELF magic, then made executable (0700); false when it is not an ELF file
585fn elfok to bool
586pfile 17
587fd = popen 524288
588if lt fd 0
589setbad 22
590ret false
591end
592r = read fd buf 0 4
593ok = eq r 4
594if ok
595m1 = and eq get buf 0 127 eq get buf 1 69
596m2 = and eq get buf 2 76 eq get buf 3 70
597ok = and m1 m2
598end
599if ok
600if ne fchmod fd 448 0
601setbad 22
602end
603end
604fclo fd
605ret ok
606end
607fn isempty id ulong to bool
608pfile id
609fd = popen 524288
610if lt fd 0
611setbad 22
612ret false
613end
614r = read fd buf 0 1
615fclo fd
616ret eq r 0
617end
618note does SCRATCH/<line>.cerr contain "error CODE" not followed by another digit
619fn names code ulong to bool
620pfile 19
621fd = popen 524288
622if lt fd 0
623setbad 22
624ret false
625end
626r = rfulla fd
627fclo fd
628if lt r 0
629setbad 22
630ret false
631end
632wordat 25
633s = get wpos 0
634k = get wpos 1
635for i ulong k
636put oth i get words add s i
637end
638n = decimal code
639for i ulong n
640put oth add k i get dig sub sub n i 1
641end
642k = add k n
643hay = ulong r
644for i ulong hay
645if le add i k hay
646if hasat i k
647if eq add i k hay
648ret true
649end
650c = get buf add i k
651if or lt c 48 gt c 57
652ret true
653end
654end
655end
656end
657ret false
658end
659fn hasat i ulong k ulong to bool
660for j ulong k
661if ne get buf add i j get oth j
662ret false
663end
664end
665ret true
666end
667note ---- inputs and expectations ---------------------------------------------------------------
668fn splitmix to ulong
669s = add get rz 0 11400714819323198485
670put rz 0 s
671z = mul xor s shr s 30 13787848793156543929
672z = mul xor z shr z 27 10723151780598845931
673ret xor z shr z 31
674end
675fn genone kind ulong a ulong i ulong to uchar
676if eq kind 12
677ret uchar a
678end
679if eq kind 13
680ret uchar rem i 251
681end
682j = rem i 8
683if eq j 0
684put rz 1 splitmix
685end
686ret uchar and shr get rz 1 mul j 8 255
687end
688fn genbytes fd int kind ulong a ulong n ulong to void
689put rz 0 a
690done = ulong 0
691while lt done n
692c = sub n done
693if gt c len buf
694c = len buf
695end
696for i ulong c
697put buf i genone kind a add done i
698end
699if ne write fd buf 0 c long c
700setbad 22
701ret
702end
703done = add done c
704end
705end
706fn geninput t ulong to void
707if tokword t 9
708ret
709end
710if tokpre t 10
711stdinpath t
712fd = popen 524288
713if lt fd 0
714setbad 21
715end
716fclo fd
717ret
718end
719kind = ulong 0
720a = ulong 0
721n = ulong 0
722if tokpre t 12
723if ne fields t 4 2
724setbad 20
725end
726kind = ulong 12
727a = fieldat t 4 0
728n = fieldat t 4 1
729if gt a 255
730setbad 20
731end
732end
733if tokpre t 13
734if ne fields t 4 1
735setbad 20
736end
737kind = ulong 13
738n = fieldat t 4 0
739end
740if tokpre t 14
741if ne fields t 4 2
742setbad 20
743end
744kind = ulong 14
745a = fieldat t 4 0
746n = fieldat t 4 1
747end
748if or eq kind 0 gt n 1073741824
749setbad 20
750end
751pfile 20
752fd = popen 524481
753if ge fd 0
754genbytes fd kind a n
755end
756fclo fd
757end
758note SCRATCH/<line>.<id> from an expectation word: -, file:PATH, has:PATH (a copy, compared line by
759note line), line:TEXT or err:LINE:CODE (the human diagnostic "omc: line LINE: error CODE")
760fn mkexp t ulong id ulong to void
761pfile id
762fo = popen 524481
763if lt fo 0
764setbad 22
765ret
766end
767if tokword t 9
768fclo fo
769ret
770end
771if or or tokpre t 10 tokpre t 36 tokpre t 37
772k = ulong 5
773if or tokpre t 36 tokpre t 37
774k = ulong 4
775end
776pclear
777plst add get tko t k sub get tkl t k
778fi = popen 524288
779if lt fi 0
780setbad 21
781else
782copyfd fi fo
783end
784fclo fi
785fclo fo
786ret
787end
788if tokpre t 11
789n = sub get tkl t 5
790o = add get tko t 5
791for i ulong n
792put buf i get lst add o i
793end
794put buf n 10
795if ne write fo buf 0 add n 1 long add n 1
796setbad 22
797end
798fclo fo
799ret
800end
801if tokpre t 33
802if ne fields t 4 2
803setbad 20
804fclo fo
805ret
806end
807n = bufword 0 34
808n = bufnum n fieldat t 4 0
809n = bufword n 35
810n = bufnum n fieldat t 4 1
811put buf n 10
812if eq get gst 0 0
813if ne write fo buf 0 add n 1 long add n 1
814setbad 22
815end
816end
817fclo fo
818ret
819end
820setbad 20
821fclo fo
822end
823fn bufword n ulong id ulong to ulong
824wordat id
825s = get wpos 0
826k = get wpos 1
827for i ulong k
828put buf add n i get words add s i
829end
830ret add n k
831end
832fn bufnum n ulong v ulong to ulong
833k = decimal v
834for i ulong k
835put buf add n i get dig sub sub k i 1
836end
837ret add n k
838end
839note has: every LF-terminated line of SCRATCH/<line>.eexp is a whole line of SCRATCH/<line>.cerr;
840note tok (tm): every such line has all its space-separated words, as whole words, in one stderr
841note line. Not 0 when so, else the 1-based number of the first expected line not found
842fn hasall tm bool to ulong
843pfile 19
844fa = popen 524288
845pfile 22
846fb = popen 524288
847if or lt fa 0 lt fb 0
848fclo fa
849fclo fb
850setbad 22
851ret 0
852end
853ra = rfulla fa
854rb = rfullb fb
855fclo fa
856fclo fb
857if or or lt ra 0 lt rb 0 or ge ra long len buf ge rb long len oth
858setbad 21
859ret 0
860end
861na = ulong ra
862nb = ulong rb
863s = ulong 0
864ln = ulong 0
865for i ulong nb
866if eq get oth i 10
867ln = add ln 1
868found = false
869if tm
870found = tokline na s sub i s
871else
872found = hasline na s sub i s
873end
874if not found
875ret ln
876end
877s = add i 1
878end
879end
880if ne s nb
881setbad 20
882ret 0
883end
884ret not ulong 0
885end
886fn eqat p ulong s ulong k ulong to bool
887for j ulong k
888if ne get buf add p j get oth add s j
889ret false
890end
891end
892ret true
893end
894note does buf[p-1] equal c, or is p the lower bound b
895fn startat p ulong b ulong c uchar to bool
896if eq p b
897ret true
898end
899ret eq get buf sub p 1 c
900end
901fn hasline na ulong s ulong k ulong to bool
902if gt k na
903ret false
904end
905for p ulong add sub na k 1
906if startat p 0 10
907if or eq add p k na eq get buf add p k 10
908if eqat p s k
909ret true
910end
911end
912end
913end
914ret false
915end
916fn tokline na ulong s ulong k ulong to bool
917ls = ulong 0
918for i ulong add na 1
919if or eq i na eq get buf i 10
920if alltoks ls i s k
921ret true
922end
923ls = add i 1
924end
925end
926ret false
927end
928fn alltoks lb ulong lz ulong s ulong k ulong to bool
929ts = s
930for i ulong add k 1
931if or eq i k eq get oth add s i 32
932te = add s i
933if gt te ts
934if not hastok lb lz ts sub te ts
935ret false
936end
937end
938ts = add te 1
939end
940end
941ret true
942end
943fn hastok lb ulong lz ulong ts ulong tl ulong to bool
944if gt tl sub lz lb
945ret false
946end
947for q ulong add sub sub lz lb tl 1
948if startat add lb q lb 32
949if endat add add lb q tl lz 32
950if eqat add lb q ts tl
951ret true
952end
953end
954end
955end
956ret false
957end
958note is e the upper bound z, or does buf[e] equal c
959fn endat e ulong z ulong c uchar to bool
960if eq e z
961ret true
962end
963ret eq get buf e c
964end
965note ---- case sources --------------------------------------------------------------------------
966note one +-separated SRC segment lst[o .. o+n): a path, pack:PATH:OFF:LEN (LEN bytes of PATH from byte
967note OFF) or cyc:PATH:N (N bytes repeating the contents of PATH, 1..65535 bytes); appended to big
968fn addpart o ulong n ulong to void
969if segpre o n 39
970addpack add o 5 sub n 5
971ret
972end
973if segpre o n 38
974addcyc add o 4 sub n 4
975ret
976end
977addfile o n
978end
979fn segpre o ulong n ulong id ulong to bool
980wordat id
981k = get wpos 1
982if lt n k
983ret false
984end
985s = get wpos 0
986for i ulong k
987if ne get lst add o i get words add s i
988ret false
989end
990end
991ret true
992end
993note offset of the last ':' in lst[o .. o+n), or n when there is none
994fn lastcol o ulong n ulong to ulong
995i = n
996while gt i 0
997i = sub i 1
998if eq get lst add o i 58
999ret i
1000end
1001end
1002ret n
1003end
1004fn addpack o ulong n ulong to void
1005q = lastcol o n
1006if ge q n
1007setbad 20
1008ret
1009end
1010p = lastcol o q
1011if ge p q
1012setbad 20
1013ret
1014end
1015k = decat add add o q 1 sub sub n q 1
1016off = decat add add o p 1 sub sub q p 1
1017if ne get gst 0 0
1018ret
1019end
1020if gt k sub len big get bgn 0
1021setbad 21
1022ret
1023end
1024pclear
1025plst o p
1026fd = popen 524288
1027if lt fd 0
1028setbad 21
1029ret
1030end
1031ok = preadall fd off k
1032fclo fd
1033if not ok
1034setbad 21
1035ret
1036end
1037put bgn 0 add get bgn 0 k
1038end
1039note k bytes of fd from position off to big at bgn
1040fn preadall fd int off ulong k ulong to bool
1041b = get bgn 0
1042done = ulong 0
1043while lt done k
1044c = sub k done
1045if gt c 1048576
1046c = ulong 1048576
1047end
1048r = pread fd big add b done c long add off done
1049if le r 0
1050ret false
1051end
1052done = add done ulong r
1053end
1054ret true
1055end
1056fn addcyc o ulong n ulong to void
1057q = lastcol o n
1058if ge q n
1059setbad 20
1060ret
1061end
1062k = decat add add o q 1 sub sub n q 1
1063if ne get gst 0 0
1064ret
1065end
1066if gt k sub len big get bgn 0
1067setbad 21
1068ret
1069end
1070pclear
1071plst o q
1072fd = popen 524288
1073if lt fd 0
1074setbad 21
1075ret
1076end
1077r = rfullb fd
1078fclo fd
1079if or le r 0 ge r long len oth
1080setbad 21
1081ret
1082end
1083cycfill ulong r k
1084end
1085note big[bgn .. bgn+k) = oth[i mod m], in 65536-byte rows (a loop with a value count traps 4 after
1086note 1000000 passes)
1087fn cycfill m ulong k ulong to void
1088b = get bgn 0
1089for r ulong add div k 65536 1
1090s = mul r 65536
1091c = sub k s
1092if gt c 65536
1093c = ulong 65536
1094end
1095cycrow b s c m
1096end
1097put bgn 0 add b k
1098end
1099fn cycrow b ulong s ulong c ulong m ulong to void
1100for i ulong c
1101put big add add b s i get oth rem add s i m
1102end
1103end
1104fn addfile o ulong n ulong to void
1105pclear
1106plst o n
1107fd = popen 524288
1108if lt fd 0
1109setbad 21
1110ret
1111end
1112while true
1113b = get bgn 0
1114c = sub len big b
1115if gt c len buf
1116c = len buf
1117end
1118if eq c 0
1119r = read fd buf 0 1
1120if ne r 0
1121setbad 21
1122end
1123fclo fd
1124ret
1125end
1126r = read fd big b c
1127if lt r 0
1128setbad 21
1129fclo fd
1130ret
1131end
1132if eq r 0
1133fclo fd
1134ret
1135end
1136put bgn 0 add b ulong r
1137end
1138end
1139fn matchat p ulong to bool
1140for j ulong get sb 1
1141if ne get big add p j get sfr j
1142ret false
1143end
1144end
1145ret true
1146end
1147note matches of sfr in big[base .. base+c): count in res 6, last position in res 7
1148fn scanchnk base ulong c ulong to void
1149for i ulong c
1150if eq get big add base i get sfr 0
1151if matchat add base i
1152put res 6 add get res 6 1
1153put res 7 add base i
1154end
1155end
1156end
1157end
1158note exact-once position of sfr in big; otherwise the match count goes to wlow with gst 47
1159fn findonce to ulong
1160fl = get sb 1
1161n = get bgn 0
1162put res 6 0
1163put res 7 0
1164if ge n fl
1165last = sub n fl
1166base = ulong 0
1167while le base last
1168c = add sub last base 1
1169if gt c 65536
1170c = ulong 65536
1171end
1172scanchnk base c
1173base = add base c
1174end
1175end
1176if ne get res 6 1
1177put wlow 0 get res 6
1178setbad 47
1179end
1180ret get res 7
1181end
1182fn wbig fd int o ulong n ulong to void
1183if ne write fd big o n long n
1184setbad 22
1185end
1186end
1187fn mksrc t ulong to void
1188put bgn 0 0
1189o = get tko t
1190e = add o get tkl t
1191s = o
1192for i ulong get tkl t
1193if eq get lst add o i 43
1194addpart s sub add o i s
1195s = add add o i 1
1196end
1197end
1198addpart s sub e s
1199pfile 16
1200fd = popen 524481
1201if lt fd 0
1202setbad 22
1203put sb 0 0
1204ret
1205end
1206if ne get sb 0 0
1207put sb 0 0
1208p = findonce
1209if eq get gst 0 0
1210say 48
1211num p
1212newline
1213wbig fd 0 p
1214if ne write fd sto 0 get sb 2 long get sb 2
1215setbad 22
1216end
1217q = add p get sb 1
1218wbig fd q sub get bgn 0 q
1219end
1220else
1221wbig fd 0 get bgn 0
1222end
1223fclo fd
1224end
1225note ---- SHA-256 (FIPS 180-4) for compiler identity only ---------------------------------------
1226fn rotr x uint n uint to uint
1227ret or shr x n shl x sub 32 n
1228end
1229fn shasched to void
1230for i ulong 16
1231b = mul i 4
1232v = shl uint get blk b 24
1233v = or v shl uint get blk add b 1 16
1234v = or v shl uint get blk add b 2 8
1235v = or v uint get blk add b 3
1236put ws i v
1237end
1238for j ulong 48
1239q = add j 16
1240x = get ws sub q 15
1241y = get ws sub q 2
1242s0 = xor xor rotr x 7 rotr x 18 shr x 3
1243s1 = xor xor rotr y 17 rotr y 19 shr y 10
1244put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1
1245end
1246end
1247fn shat1 i ulong to uint
1248e = get st 4
1249s1 = xor xor rotr e 6 rotr e 11 rotr e 25
1250ch = xor and e get st 5 and not e get st 6
1251ret add add add add get st 7 s1 ch get kk i get ws i
1252end
1253fn shat2 to uint
1254a = get st 0
1255b = get st 1
1256c = get st 2
1257s0 = xor xor rotr a 2 rotr a 13 rotr a 22
1258mj = xor xor and a b and a c and b c
1259ret add s0 mj
1260end
1261fn shacomp to void
1262shasched
1263for i ulong 8
1264put st i get hv i
1265end
1266for i ulong 64
1267t1 = shat1 i
1268t2 = shat2
1269put st 7 get st 6
1270put st 6 get st 5
1271put st 5 get st 4
1272put st 4 add get st 3 t1
1273put st 3 get st 2
1274put st 2 get st 1
1275put st 1 get st 0
1276put st 0 add t1 t2
1277end
1278for i ulong 8
1279put hv i add get hv i get st i
1280end
1281end
1282fn shabyte b uchar to void
1283n = get bk 0
1284put blk n b
1285n = add n 1
1286if eq n 64
1287shacomp
1288n = ulong 0
1289end
1290put bk 0 n
1291put bk 1 add get bk 1 1
1292end
1293fn hexch v uint to uchar
1294if lt v 10
1295ret uchar add v 48
1296end
1297ret uchar add v 87
1298end
1299fn shafinal to void
1300bits = mul get bk 1 8
1301shabyte 128
1302while ne get bk 0 56 bound 64
1303shabyte 0
1304end
1305for i ulong 8
1306shabyte uchar and shr bits mul sub 7 i 8 255
1307end
1308for i ulong 8
1309v = get hv i
1310for j ulong 8
1311put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15
1312end
1313end
1314end
1315note hash the file named by pb into hexd; false when it cannot be read
1316fn hashfile to bool
1317fd = popen 524288
1318if lt fd 0
1319ret false
1320end
1321for i ulong 8
1322put hv i get ivs i
1323end
1324put bk 0 0
1325put bk 1 0
1326while true
1327r = read fd buf 0 len buf
1328if lt r 0
1329fclo fd
1330ret false
1331end
1332if eq r 0
1333fclo fd
1334shafinal
1335ret true
1336end
1337for i ulong ulong r
1338shabyte get buf i
1339end
1340end
1341ret false
1342end
1343note decimal numbers, one per line, each below 2^32, exactly want of them, into nums
1344fn loadnums id ulong want ulong to bool
1345pclear
1346pword id
1347fd = popen 524288
1348if lt fd 0
1349ret false
1350end
1351r = rfulla fd
1352fclo fd
1353if or le r 0 ge r long len buf
1354ret false
1355end
1356ret parsenum ulong r want
1357end
1358fn parsenum n ulong want ulong to bool
1359m = ulong not uint 0
1360k = ulong 0
1361v = ulong 0
1362nd = ulong 0
1363for i ulong n
1364c = get buf i
1365if and ge c 48 le c 57
1366if ge nd 10
1367ret false
1368end
1369v = add mul v 10 ulong sub c 48
1370nd = add nd 1
1371else
1372if or ne c 10 eq nd 0
1373ret false
1374end
1375if ge k want
1376ret false
1377end
1378if gt v m
1379ret false
1380end
1381put nums k v
1382k = add k 1
1383v = ulong 0
1384nd = ulong 0
1385end
1386end
1387ret and eq nd 0 eq k want
1388end
1389note ---- verdicts ------------------------------------------------------------------------------
1390fn verdict s ulong to void
1391say 1
1392showtok 0
1393say s
1394put cnt sub s 2 add get cnt sub s 2 1
1395end
1396fn invalid to void
1397verdict 4
1398g = get gst 0
1399say g
1400if or or eq g 18 eq g 19 eq g 47
1401num get wlow 0
1402end
1403newline
1404end
1405fn header to void
1406say 43
1407showtok 0
1408say 44
1409num get lno 0
1410newline
1411end
1412fn showexit a ulong id ulong b ulong to void
1413say id
1414num a
1415say 7
1416num b
1417end
1418fn runcase kill bool to void
1419if lt get ntk 0 7
1420setbad 20
1421invalid
1422ret
1423end
1424ex = decat get tko 6 get tkl 6
1425if or gt ex 255 eq ex 127
1426setbad 20
1427end
1428if or or tokpre 4 36 tokpre 5 36 or tokpre 4 37 tokpre 5 37
1429setbad 20
1430end
1431if ne get gst 0 0
1432invalid
1433ret
1434end
1435mksrc 2
1436ce = compile false
1437if ne get gst 0 0
1438invalid
1439ret
1440end
1441if ne ce 0
1442verdict 3
1443showexit ce 6 0
1444newline
1445ret
1446end
1447if not elfok
1448if ne get gst 0 0
1449invalid
1450ret
1451end
1452verdict 3
1453say 15
1454newline
1455ret
1456end
1457geninput 3
1458mkexp 4 21
1459anyerr = tokword 5 15
1460if not anyerr
1461mkexp 5 22
1462end
1463if ne get gst 0 0
1464invalid
1465ret
1466end
1467rx = runprog
1468if ne get gst 0 0
1469invalid
1470ret
1471end
1472put res 0 ex
1473put res 1 rx
1474put res 2 diffat 23 21
1475put res 3 not ulong 0
1476if not anyerr
1477put res 3 diffat 24 22
1478end
1479if ne get gst 0 0
1480invalid
1481ret
1482end
1483judge kill anyerr
1484end
1485fn judge kill bool anyerr bool to void
1486all = not ulong 0
1487ex = get res 0
1488rx = get res 1
1489od = get res 2
1490ed = get res 3
1491ok = and eq rx ex eq ed all
1492if kill
1493ok = and ok ne od all
1494else
1495ok = and ok eq od all
1496end
1497if ok
1498verdict 2
1499else
1500verdict 3
1501end
1502showexit rx 8 ex
1503if eq od all
1504if kill
1505say 13
1506else
1507say 9
1508end
1509else
1510if kill
1511say 14
1512else
1513say 10
1514end
1515num od
1516end
1517if anyerr
1518say 50
1519else
1520if eq ed all
1521say 11
1522else
1523say 12
1524num ed
1525end
1526end
1527if and kill ne rx ex
1528say 58
1529end
1530newline
1531end
1532fn refusecase to void
1533if ne get ntk 0 4
1534setbad 20
1535invalid
1536ret
1537end
1538code = decat get tko 3 get tkl 3
1539if or eq code 0 gt code 255
1540setbad 20
1541end
1542if ne get gst 0 0
1543invalid
1544ret
1545end
1546mksrc 2
1547ce = compile false
1548if ne get gst 0 0
1549invalid
1550ret
1551end
1552quiet = isempty 17
1553named = names code
1554if ne get gst 0 0
1555invalid
1556ret
1557end
1558if and and eq ce code quiet named
1559verdict 2
1560else
1561verdict 3
1562end
1563showexit ce 6 code
1564if not quiet
1565say 16
1566end
1567if named
1568say 24
1569else
1570say 17
1571end
1572newline
1573end
1574note emit: compile only; compiler exit, stdout (-, file:, line:, any, sha:HEX) and stderr (-, file:,
1575note line:, err:LINE:CODE, has:PATH, any) must all equal the expectation
1576fn emitcase to void
1577if ne get ntk 0 6
1578setbad 20
1579invalid
1580ret
1581end
1582ex = decat get tko 5 get tkl 5
1583if or gt ex 255 eq ex 127
1584setbad 20
1585end
1586if tokpre 3 31
1587if not hexok
1588setbad 20
1589end
1590end
1591if ne get gst 0 0
1592invalid
1593ret
1594end
1595put res 0 ex
1596mksrc 2
1597put res 1 compile false
1598if ne get gst 0 0
1599invalid
1600ret
1601end
1602if not or tokword 3 15 tokpre 3 31
1603mkexp 3 21
1604end
1605if not tokword 4 15
1606mkexp 4 22
1607end
1608if ne get gst 0 0
1609invalid
1610ret
1611end
1612put res 2 not ulong 0
1613put res 3 not ulong 0
1614put res 4 1
1615if tokpre 3 31
1616if not shamatch
1617put res 4 0
1618end
1619else
1620if not tokword 3 15
1621put res 2 diffat 17 21
1622end
1623end
1624if not tokword 4 15
1625if or tokpre 4 36 tokpre 4 37
1626put res 3 hasall tokpre 4 37
1627else
1628put res 3 diffat 19 22
1629end
1630end
1631if ne get gst 0 0
1632invalid
1633ret
1634end
1635emitsay
1636end
1637note token 3 after "sha:" is 64 lowercase hex digits
1638fn hexok to bool
1639if ne get tkl 3 68
1640ret false
1641end
1642for i ulong 64
1643c = get lst add add get tko 3 4 i
1644if not or and ge c 48 le c 57 and ge c 97 le c 102
1645ret false
1646end
1647end
1648ret true
1649end
1650note sha256 of SCRATCH/<line>.elf (into hexd) equals the hex of token 3
1651fn shamatch to bool
1652pfile 17
1653if not hashfile
1654setbad 22
1655ret false
1656end
1657for i ulong 64
1658if ne get hexd i get lst add add get tko 3 4 i
1659ret false
1660end
1661end
1662ret true
1663end
1664fn emitsay to void
1665all = not ulong 0
1666od = get res 2
1667ed = get res 3
1668ok = eq get res 1 get res 0
1669ok = and ok eq get res 4 1
1670ok = and ok and eq od all eq ed all
1671if ok
1672verdict 2
1673else
1674verdict 3
1675end
1676showexit get res 1 6 get res 0
1677if tokword 3 15
1678say 66
1679end
1680if tokpre 3 31
1681say 35
1682r = write 1 hexd 0 64
1683if eq get res 4 0
1684say 65
1685r = write 1 lst add get tko 3 4 64
1686end
1687end
1688if not or tokword 3 15 tokpre 3 31
1689if eq od all
1690say 9
1691else
1692say 10
1693num od
1694end
1695end
1696if tokword 4 15
1697say 50
1698else
1699if eq ed all
1700say 11
1701else
1702if or tokpre 4 36 tokpre 4 37
1703say 70
1704else
1705say 12
1706end
1707num ed
1708end
1709end
1710newline
1711end
1712note same: SRC1 and SRC2 both compile with exit 0 to byte-identical outputs (SRC2's files carry .b)
1713fn samecase to void
1714if ne get ntk 0 4
1715setbad 20
1716invalid
1717ret
1718end
1719put sx 0 1
1720mksrc 3
1721c2 = compile false
1722put sx 0 0
1723if ne get gst 0 0
1724invalid
1725ret
1726end
1727mksrc 2
1728c1 = compile false
1729if ne get gst 0 0
1730invalid
1731ret
1732end
1733all = not ulong 0
1734d = all
1735both = and eq c1 0 eq c2 0
1736if both
1737put sx 1 1
1738d = diffat 17 17
1739put sx 1 0
1740if ne get gst 0 0
1741invalid
1742ret
1743end
1744end
1745if and both eq d all
1746verdict 2
1747else
1748verdict 3
1749end
1750showexit c1 6 0
1751say 69
1752num c2
1753if both
1754if eq d all
1755say 67
1756else
1757say 68
1758num d
1759end
1760end
1761newline
1762end
1763fn notruncase to void
1764if lt get ntk 0 3
1765setbad 20
1766invalid
1767ret
1768end
1769verdict 5
1770say 57
1771for i ulong sub get ntk 0 2
1772space
1773showtok add i 2
1774end
1775newline
1776end
1777fn dircc to void
1778if ne get ntk 0 2
1779setbad 20
1780invalid
1781ret
1782end
1783if tokword 1 8
1784for i ulong get omn 0
1785put ccp i get omc i
1786end
1787put ccn 0 get omn 0
1788put ccbad 0 0
1789say 49
1790pomc
1791showpb
1792newline
1793ret
1794end
1795put ccbad 0 1
1796mksrc 1
1797ce = compile true
1798if ne get gst 0 0
1799invalid
1800ret
1801end
1802if ne ce 0
1803verdict 3
1804showexit ce 60 0
1805newline
1806ret
1807end
1808if not elfok
1809if ne get gst 0 0
1810invalid
1811ret
1812end
1813verdict 3
1814say 15
1815newline
1816ret
1817end
1818pfile 17
1819for i ulong get pn 0
1820put ccp i get pb i
1821end
1822put ccn 0 get pn 0
1823if not hashfile
1824setbad 22
1825invalid
1826ret
1827end
1828put ccbad 0 0
1829say 49
1830showpb
1831say 35
1832r = write 1 hexd 0 64
1833say 62
1834num get lno 0
1835newline
1836end
1837fn dirdl to void
1838if ne get ntk 0 2
1839setbad 20
1840invalid
1841ret
1842end
1843s = decat get tko 1 get tkl 1
1844if or eq s 0 gt s 900
1845setbad 20
1846end
1847if ne get gst 0 0
1848invalid
1849ret
1850end
1851put dl 0 mul long s 1000000000
1852say 60
1853num s
1854newline
1855end
1856fn loadsub t ulong to ulong
1857pclear
1858plst get tko t get tkl t
1859fd = popen 524288
1860if lt fd 0
1861setbad 21
1862ret 0
1863end
1864r = rfulla fd
1865if eq r long len buf
1866x = read fd oth 0 1
1867if ne x 0
1868setbad 21
1869end
1870end
1871fclo fd
1872if lt r 0
1873setbad 21
1874ret 0
1875end
1876ret ulong r
1877end
1878fn dirsub to void
1879if or ne get ntk 0 3 ne get sb 0 0
1880put sb 0 0
1881setbad 20
1882invalid
1883ret
1884end
1885n = loadsub 1
1886for i ulong n
1887put sfr i get buf i
1888end
1889m = loadsub 2
1890for i ulong m
1891put sto i get buf i
1892end
1893if eq n 0
1894setbad 20
1895end
1896if ne get gst 0 0
1897invalid
1898ret
1899end
1900put sb 0 1
1901put sb 1 n
1902put sb 2 m
1903say 61
1904showtok 1
1905space
1906showtok 2
1907newline
1908end
1909note one non-comment line, already split into tokens
1910fn docase to void
1911put gst 0 0
1912if tokword 0 5
1913dircc
1914ret
1915end
1916if tokword 0 6
1917dirdl
1918ret
1919end
1920if tokword 0 7
1921dirsub
1922ret
1923end
1924header
1925if lt get ntk 0 2
1926setbad 20
1927invalid
1928ret
1929end
1930mode = ulong 0
1931for k ulong 4
1932if tokword 1 add k 1
1933mode = add k 1
1934end
1935end
1936if tokword 1 29
1937mode = ulong 5
1938end
1939if tokword 1 30
1940mode = ulong 6
1941end
1942if and ne get sb 0 0 or or eq mode 0 eq mode 4 eq mode 6
1943put sb 0 0
1944setbad 51
1945invalid
1946ret
1947end
1948if eq mode 0
1949setbad 20
1950invalid
1951ret
1952end
1953if eq get idok 0 0
1954put sb 0 0
1955verdict 5
1956say 46
1957newline
1958ret
1959end
1960if and ne get ccbad 0 0 ne mode 4
1961put sb 0 0
1962verdict 5
1963say 45
1964newline
1965ret
1966end
1967if eq mode 1
1968runcase false
1969end
1970if eq mode 2
1971runcase true
1972end
1973if eq mode 3
1974refusecase
1975end
1976if eq mode 5
1977emitcase
1978end
1979if eq mode 6
1980samecase
1981end
1982if eq mode 4
1983notruncase
1984end
1985end
1986fn lineend p ulong to ulong
1987n = get lsn 0
1988for i ulong sub n p
1989if eq get lst add p i 10
1990ret add p i
1991end
1992end
1993ret n
1994end
1995fn tokenize p ulong e ulong to bool
1996put ntk 0 0
1997s = p
1998inw = false
1999for i ulong sub e p
2000c = get lst add p i
2001if eq c 32
2002if inw
2003k = get ntk 0
2004put tkl k sub add p i s
2005put ntk 0 add k 1
2006inw = false
2007end
2008else
2009if not inw
2010if ge get ntk 0 len tko
2011ret false
2012end
2013put tko get ntk 0 add p i
2014s = add p i
2015inw = true
2016end
2017end
2018end
2019if inw
2020k = get ntk 0
2021put tkl k sub e s
2022put ntk 0 add k 1
2023end
2024ret true
2025end
2026fn runlist to void
2027p = ulong 0
2028ln = ulong 0
2029while lt p get lsn 0
2030ln = add ln 1
2031put lno 0 ln
2032e = lineend p
2033if tokenize p e
2034if gt get ntk 0 0
2035if ne get lst get tko 0 35
2036docase
2037end
2038end
2039else
2040put ntk 0 1
2041put tkl 0 0
2042put gst 0 20
2043invalid
2044end
2045p = add e 1
2046end
2047if ne get sb 0 0
2048say 1
2049wordat 7
2050r = write 1 words get wpos 0 get wpos 1
2051say 4
2052say 51
2053newline
2054put cnt 2 add get cnt 2 1
2055end
2056end
2057fn summary to int
2058pas = get cnt 0
2059fal = get cnt 1
2060inv = get cnt 2
2061nr = get cnt 3
2062tot = add add add pas fal inv nr
2063rc = int 0
2064s = ulong 25
2065if gt nr 0
2066rc = 2
2067s = ulong 28
2068end
2069if gt fal 0
2070rc = 1
2071s = ulong 26
2072end
2073if or or gt inv 0 eq tot 0 eq get idok 0 0
2074rc = 3
2075s = ulong 27
2076end
2077say s
2078say 29
2079num tot
2080say 30
2081num pas
2082say 31
2083num fal
2084say 32
2085num inv
2086say 33
2087num nr
2088if eq tot 0
2089say 52
2090end
2091newline
2092ret rc
2093end
2094fn identity to void
2095pomc
2096ok = hashfile
2097say 34
2098showpb
2099say 35
2100if ok
2101r = write 1 hexd 0 64
2102end
2103say 36
2104r = write 1 pin 0 64
2105put idok 0 0
2106if ok
2107put idok 0 1
2108for i ulong 64
2109if ne get hexd i get pin i
2110put idok 0 0
2111end
2112end
2113end
2114if eq get idok 0 1
2115say 37
2116else
2117say 38
2118end
2119newline
2120end
2121fn loadlist to bool
2122pclear
2123r = argread 3 pb 0 4095
2124if lt r 1
2125ret false
2126end
2127put pn 0 ulong r
2128fd = popen 524288
2129if lt fd 0
2130ret false
2131end
2132n = ulong 0
2133while lt n len lst
2134x = read fd lst n sub len lst n
2135if le x 0
2136fclo fd
2137put lsn 0 n
2138ret eq x 0
2139end
2140n = add n ulong x
2141end
2142x = read fd buf 0 1
2143fclo fd
2144put lsn 0 n
2145ret eq x 0
2146end
2147fn main to int
2148if ne argcnt 5
2149say 53
2150newline
2151ret 90
2152end
2153put dl 0 30000000000
2154r = argread 1 omc 0 4095
2155if lt r 1
2156say 53
2157newline
2158ret 90
2159end
2160put omn 0 ulong r
2161for i ulong get omn 0
2162put ccp i get omc i
2163end
2164put ccn 0 get omn 0
2165r = argread 2 pin 0 64
2166if ne r 64
2167say 53
2168newline
2169ret 90
2170end
2171r = argread 4 scr 0 4094
2172if lt r 1
2173say 53
2174newline
2175ret 90
2176end
2177n = ulong r
2178if ne makedir scr 0 n 448 0
2179say 54
2180newline
2181ret 91
2182end
2183put scr n 47
2184put scn 0 add n 1
2185say 63
2186r = argread 3 pb 0 4095
2187put pn 0 ulong r
2188showpb
2189say 64
2190r = write 1 scr 0 n
2191newline
2192if not loadnums 26 64
2193say 55
2194newline
2195ret 3
2196end
2197for i ulong 64
2198put kk i uint get nums i
2199end
2200if not loadnums 27 8
2201say 55
2202newline
2203ret 3
2204end
2205for i ulong 8
2206put ivs i uint get nums i
2207end
2208identity
2209if not loadlist
2210say 56
2211newline
2212ret 3
2213end
2214runlist
2215ret summary
2216end