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 / train / omega-llm / tools / bench / bench.om

1786 lines · 31952 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: AGPL-3.0-only
3note bench.om: the Omega coding benchmark of Omega LLM. One prompt per behaviour, graded by
4note compiling the model's function body and running hidden cases, with no help from the harness:
5note one sample at temperature 0, no example filter, and the model has to end its own function.
6note
7note bench table TASKS OMC WORK print the expectation table of the references
8note bench check TASKS EXPECT OMC WORK the table equals EXPECT and no two tasks agree
9note bench prompts TASKS WORK write WORK/prompt-ID
10note bench sample TASKS WORK OLLM CMD CK [MERGES] WORK/answer-ID = OLLM CMD CK 42 128 0 PROMPT [MERGES]
11note bench score TASKS EXPECT OMC WORK [CORPUS] grade WORK/answer-ID
12note bench seen TASKS CORPUS tasks whose reference occurs in CORPUS
13note
14note TASKS (tasks.om) is Omega source. Its `note in1 X`, `note in2 X Y`, `note in3 X Y Z`, `note arr
15note v0 .. v7` and `note cnt N` lines are the shared inputs; every task is `note task ID FAMILY`,
16note `note say INSTRUCTION` and a reference function `fn tNNN PARAMS` .. `end`. PARAMS is one of
17note five shapes: 1 `a ulong to ulong`, 2 `a ulong b ulong to ulong`, 3 `a ulong b ulong c ulong to
18note ulong`, 4 `a view ulong 8 n ulong to ulong`, 5 `a edit ulong 8 n ulong to void`. Shapes 1 .. 3
19note run on every in1/in2/in3 line, shapes 4 and 5 on every arr with every cnt; shape 5's result is
20note the array afterwards. A row of the table is `ID v v ..`, one row per task in file order.
21note The prompt is `note INSTRUCTION`, newline, `fn solve PARAMS`, newline; the answer is what the
22note model writes after it. Its body runs to the `end` that closes the function (if, while and for
23note open a block). Verdicts: pass (the answer is exactly that body and every case holds), passcut
24note (the body passes but text follows it: the model did not stop), wrong (a case fails, a trap, or
25note a wrong exit), nocompile, noend (no closing end), refused (the body says exit or trap, which
26note could fake the result), missing (no answer file), timeout. The headline counts pass only.
27note Lines: `R ID FAMILY VERDICT`, then per family `F FAMILY tasks pass passcut wrong nocompile noend
28note refused missing timeout seen`, then `SCORE tasks N pass P passcut C seen K`. A task whose
29note reference occurs in CORPUS (same text after renaming its names, `bench seen`) is counted as seen
30note and left out of N, P and C: it measures recall, not coding.
31note Candidate programs run under execpure (OMEGESE section 10: Landlock, seccomp, no new files or
32note processes, CPU and memory ceilings); 127 from it means the sandbox is not available and ends
33note the run with exit 70 instead of a verdict. Compiles have a 60 s deadline, runs 10 s.
34note Exits: 0 done (check: PASS), 1 check failed, 2 usage, 64 a path or packet too long, 65 TASKS
35note malformed (stderr names the byte), 66 EXPECT does not fit TASKS, 70 I/O or sandbox, 71 a
36note sample command failed. Paths are at most 4096 bytes (Linux PATH_MAX); every table grows with
37note its input.
38
39text lin1 "note in1 "
40text lin2 "note in2 "
41text lin3 "note in3 "
42text larr "note arr "
43text lcnt "note cnt "
44text ltask "note task "
45text lsay "note say "
46text lfn "fn "
47text lnote "note"
48text twif "if"
49text twwhile "while"
50text twfor "for"
51text twend "end"
52text twexit "exit"
53text twtrap "trap"
54text tweq "="
55text twto "to"
56text twview "view"
57text twedit "edit"
58text sg1 "a ulong to ulong"
59text sg2 "a ulong b ulong to ulong"
60text sg3 "a ulong b ulong c ulong to ulong"
61text sg4 "a view ulong 8 n ulong to ulong"
62text sg5 "a edit ulong 8 n ulong to void"
63text tnull "/dev/null"
64text fpsrc "bench-p.om"
65text fpbin "bench-p"
66text fpout "bench-out"
67text fpprm "prompt-"
68text fpans "answer-"
69text ctable "table"
70text ccheck "check"
71text cprompts "prompts"
72text csample "sample"
73text cscore "score"
74text cseen "seen"
75text a42 "42"
76text a128 "128"
77text a0 "0"
78text gpre "fn prv v ulong to void\nd = new uchar 24 0\ni = ulong 24\nx = v\nk = true\nwhile k bound 24\ni = sub i 1\nput d i uchar add 48 rem x 10\nx = div x 10\nif eq x 0\nk = false\nend\nend\ni = sub i 1\nput d i 32\nw = write 1 d i sub 24 i\nend\nfn prl to void\nd = new uchar 1 10\nw = write 1 d 0 1\nend\nfn pra a view ulong 8 to void\nfor i ulong 8\nprv get a i\nend\nend\n"
79text gfill0 "fn bench_fill a edit ulong 8 k ulong to void\n"
80text gifk "if eq k "
81text gputa "put a "
82text gend "end\n"
83text gidt "text id"
84text gquo " \""
85text gquoz "\"\n"
86text gfn "fn "
87text growh "fn row"
88text growz " to void\n"
89text garr0 "arr = new ulong 8 0\n"
90text gwid "w = write 1 id"
91text gwid2 " 0 len id"
92text gprl "prl\nend\n"
93text gprv "prv "
94text gsul " ulong "
95text gfillc "bench_fill arr ulong "
96text garrul " arr ulong "
97text gpra "pra arr\n"
98text gmain0 "fn main to int\n"
99text growc "row"
100text gmainz "ret 0\nend\n"
101text gsolve "fn solve "
102text gifne "if ne solve"
103text gifget "if ne get arr "
104text gfail "\nret 83\nend\n"
105text gret77 "ret 77\nend\n"
106text gcall "solve"
107text gnote "note "
108text epath "bench: a path is over 4096 bytes\n"
109text epack "bench: an argument packet is over 65536 bytes\n"
110text eio "bench: I/O failure\n"
111text eargs "bench: usage: bench table|check|prompts|sample|score|seen ... (see the head of bench.om)\n"
112text etask "bench: TASKS malformed at byte "
113text eexp "bench: EXPECT does not fit TASKS at task "
114text esand "bench: the execpure sandbox is not available here (exit 127 from the candidate)\n"
115text ecomp "bench: the references do not compile or run: status "
116text msame "SAME_BEHAVIOUR "
117text mdiff "EXPECT_DIFFERS\n"
118text mpass "CHECK PASS tasks "
119text mfail "CHECK FAIL tasks "
120text mcase " inputs "
121text msep " minsep "
122text msfail "SAMPLE_FAIL "
123text mscore "SCORE tasks "
124text mspass " pass "
125text mscut " passcut "
126text msseen " seen "
127text mseen "SEEN "
128text mseens "SEENSUM tasks "
129text mseenf " functions "
130text v1 "pass"
131text v2 "passcut"
132text v3 "wrong"
133text v4 "nocompile"
134text v5 "noend"
135text v6 "refused"
136text v7 "missing"
137text v8 "timeout"
138text v9 "seen"
139
140note mem holds every file read (tasks, expectations, an answer, a corpus, a table) one after the
141note other; st[6] is the fill. prog is the program or prompt being generated (st[2] bytes).
142note tk has 16 words per task: 0 id, 1 its length, 2 family, 3 length, 4 instruction, 5 length,
143note 6 params, 7 length, 8 body, 9 length (through the closing end, no newline), 10 shape, 11 the
144note reference's name, 12 length, 13 normal form in nrm, 14 length, 15 verdict or seen mark.
145note inp has 3 words per input line: kind (1 .. 3 scalar shapes, 4 arr, 5 cnt), text, length.
146note nrm holds normal forms (st[24] bytes), nmt the (offset, length) names of the function being
147note normalised (st[25] names).
148note st: 0 tasks, 1 input lines, 2 prog bytes, 3 path bytes, 4 packet bytes, 5 stdout bytes, 6 mem
149note fill, 7 packet records, 8 9 pending instruction, 10 11 pending id, 12 13 pending family, 14
150note task pending, 15 arr lines, 16 cnt lines, 17 18 19 in1 in2 in3 lines, 26 WORK argument, 27 OMC
151note argument, 28 29 the expectation cursor and its row end.
152global mem uchar *
153global prog uchar *
154global tk ulong *
155global inp ulong *
156global nrm uchar *
157global nmt ulong *
158global st ulong 32
159global pth uchar 4096
160global pk uchar 65536
161global wst uchar 4
162global ob uchar 65536
163global dg uchar 24
164
165note ======== stdout, stderr
166
167fn oflush to void
168n = get st 5
169if gt n 0
170w = write 1 ob 0 n
171put st 5 0
172end
173end
174
175fn oc c ulong to void
176n = get st 5
177if ge n 65536
178oflush
179n = 0
180end
181put ob n uchar c
182put st 5 add n 1
183end
184
185fn ot t view uchar * to void
186for i ulong len t bound 9223372036854775807
187oc ulong get t i
188end
189end
190
191fn omem o ulong n ulong to void
192for i ulong n bound 9223372036854775807
193oc ulong get mem add o i
194end
195end
196
197note v in decimal into dg; the index of its first digit (digits end at 24)
198fn udec v ulong to ulong
199i = ulong 24
200x = v
201k = true
202while k bound 24
203i = sub i 1
204put dg i uchar add 48 rem x 10
205x = div x 10
206if eq x 0
207k = false
208end
209end
210ret i
211end
212
213fn ou v ulong to void
214i = udec v
215while lt i 24 bound 24
216oc ulong get dg i
217i = add i 1
218end
219end
220
221note message t on stderr, then exit c
222fn die t view uchar * c int to void
223oflush
224w = write 2 t 0 len t
225exit c
226end
227
228note message t, the number v and a newline on stderr, then exit c
229fn dien t view uchar * v ulong c int to void
230oflush
231w = write 2 t 0 len t
232i = udec v
233w = write 2 dg i sub 24 i
234put dg 0 10
235w = write 2 dg 0 1
236exit c
237end
238
239note ======== paths and files
240
241fn pclr to void
242put st 3 0
243end
244
245fn pch c ulong to void
246n = get st 3
247if ge n 4096
248die epath 64
249end
250put pth n uchar c
251put st 3 add n 1
252end
253
254fn ptx t view uchar * to void
255for i ulong len t
256pch ulong get t i
257end
258end
259
260note argument i onto the path
261fn parg i ulong to void
262n = get st 3
263r = argread i pth n sub 4096 n
264if lt r 0
265die eargs 2
266end
267put st 3 add n ulong r
268end
269
270note the path WORK/t
271fn wpath t view uchar * to void
272pclr
273parg get st 26
274pch 47
275ptx t
276end
277
278note the path WORK/t followed by task i's id
279fn wpid t view uchar * i ulong to void
280wpath t
281o = tfd i 0
282for j ulong tfd i 1 bound 4096
283pch ulong get mem add o j
284end
285end
286
287note the file at the path into mem at the fill; its length, or 2^64 - 1 when it cannot be opened
288fn fload to ulong
289fd = fopen pth 0 get st 3 0 0
290if lt fd 0
291ret 18446744073709551615
292end
293sz = fseek int fd 0 2
294if lt sz 0
295die eio 70
296end
297z = fseek int fd 0 0
298b = get st 6
299e = add b ulong sz
300r = enlarge mem add e 1
301if lt r 0
302die eio 70
303end
304o = b
305while lt o e bound 9223372036854775807
306k = read int fd mem o sub e o
307if le k 0
308die eio 70
309end
310o = add o ulong k
311end
312z = fclose int fd
313put st 6 e
314ret ulong sz
315end
316
317note argument i's file into mem; its offset (the length is the new fill minus it)
318fn aload i ulong to ulong
319pclr
320parg i
321b = get st 6
322if eq fload 18446744073709551615
323die eio 70
324end
325ret b
326end
327
328note the path opened for reading, or created and emptied with mode md when wr
329fn popen wr bool md int to int
330r = long 0
331if wr
332r = fopen pth 0 get st 3 577 md
333else
334r = fopen pth 0 get st 3 0 0
335end
336if lt r 0
337die eio 70
338end
339ret int r
340end
341
342note prog[0, st2) into the path, created with mode md
343fn fsave md int to void
344fd = popen true md
345n = get st 2
346o = ulong 0
347while lt o n bound 9223372036854775807
348k = write fd prog o sub n o
349if le k 0
350die eio 70
351end
352o = add o ulong k
353end
354z = fclose fd
355end
356
357note ======== the generated text
358
359fn gc c ulong to void
360n = get st 2
361if ge n len prog
362r = enlarge prog add mul n 2 4096
363if lt r 0
364die eio 70
365end
366end
367put prog n uchar c
368put st 2 add n 1
369end
370
371fn gtx t view uchar * to void
372for i ulong len t bound 9223372036854775807
373gc ulong get t i
374end
375end
376
377fn gmem o ulong n ulong to void
378for i ulong n bound 9223372036854775807
379gc ulong get mem add o i
380end
381end
382
383fn gu v ulong to void
384i = udec v
385while lt i 24 bound 24
386gc ulong get dg i
387i = add i 1
388end
389end
390
391note ======== processes
392
393fn kclr to void
394put st 4 2
395put st 7 0
396end
397
398fn kb c ulong to void
399n = get st 4
400if ge n 65536
401die epack 64
402end
403put pk n uchar c
404put st 4 add n 1
405end
406
407note start a record of n bytes
408fn krec n ulong to void
409if gt n 65535
410die epack 64
411end
412kb and n 255
413kb shr n 8
414put st 7 add get st 7 1
415end
416
417note the path as the next record
418fn kpath to void
419n = get st 3
420krec n
421for i ulong n bound 4096
422kb ulong get pth i
423end
424end
425
426fn ktx t view uchar * to void
427krec len t
428for i ulong len t
429kb ulong get t i
430end
431end
432
433note argument i as the next record
434fn karg i ulong to void
435pclr
436parg i
437kpath
438end
439
440note prog[0, st2) as the next record
441fn kprog to void
442n = get st 2
443krec n
444for i ulong n bound 65536
445kb ulong get prog i
446end
447end
448
449fn kfin to void
450n = get st 7
451put pk 0 uchar and n 255
452put pk 1 uchar shr n 8
453end
454
455note the child: fi is stdin, fo stdout, stderr /dev/null; pure runs the packet under execpure
456fn child fi int fo int pure bool to void
457r = dupfd fi 0 0
458r = dupfd fo 1 0
459fd = fopen tnull 0 len tnull 1 0
460if ge fd 0
461r = dupfd int fd 2 0
462end
463if pure
464r = execpure pk 0 get st 4
465else
466r = execprog pk 0 get st 4
467end
468exit 127
469end
470
471fn spawn fi int fo int pure bool to long
472kfin
473pid = fork
474if lt pid 0
475die eio 70
476end
477if eq pid 0
478child fi fo pure
479end
480ret pid
481end
482
483note wait for pid at most ms milliseconds: its exit status, 256 + the signal that ended it, or
484note 1000 when the deadline passed and it was killed
485fn waitp pid long ms ulong to long
486dl = add ulong monons mul ms 1000000
487w = long 0
488while eq w 0 bound 9223372036854775807
489w = waitpid int pid wst 0 4 1
490if eq w 0
491if ge ulong monons dl
492r = killpid int pid 9
493w = waitpid int pid wst 0 4 0
494ret 1000
495end
496r = sleepns 500000
497end
498end
499if lt w 0
500die eio 70
501end
502sig = and ulong get wst 0 127
503if ne sig 0
504ret long add 256 sig
505end
506ret long get wst 1
507end
508
509note compile WORK/bench-p.om (prog, saved here) into WORK/bench-p; the compiler's status
510fn compile to long
511wpath fpsrc
512fsave 420
513fi = popen false 0
514wpath fpbin
515fo = popen true 493
516kclr
517karg get st 27
518pid = spawn fi fo false
519z = fclose fi
520z = fclose fo
521ret waitp pid 60000
522end
523
524note run WORK/bench-p under execpure, stdout into WORK/bench-out when tofile; its status
525fn runp tofile bool to long
526pclr
527ptx tnull
528fi = popen false 0
529fo = int 0
530if tofile
531wpath fpout
532fo = popen true 420
533else
534r = fopen pth 0 get st 3 1 0
535if lt r 0
536die eio 70
537end
538fo = int r
539end
540wpath fpbin
541kclr
542kpath
543pid = spawn fi fo true
544z = fclose fi
545z = fclose fo
546s = waitp pid 10000
547if eq s 127
548die esand 70
549end
550ret s
551end
552
553note ======== reading TASKS
554
555note the newline that ends the line at p, or e
556fn lend p ulong e ulong to ulong
557q = p
558while lt q e bound 9223372036854775807
559if eq get mem q 10
560ret q
561end
562q = add q 1
563end
564ret e
565end
566
567note the end of the word at p: the next space, tab or e
568fn wordend p ulong e ulong to ulong
569q = p
570while lt q e bound 9223372036854775807
571c = get mem q
572if or eq c 32 eq c 9
573ret q
574end
575q = add q 1
576end
577ret e
578end
579
580note p moved over spaces and tabs, not past e
581fn skipsp p ulong e ulong to ulong
582q = p
583while lt q e bound 9223372036854775807
584c = get mem q
585if and ne c 32 ne c 9
586ret q
587end
588q = add q 1
589end
590ret e
591end
592
593note whether mem[p, e) starts with t
594fn sw p ulong e ulong t view uchar * to bool
595n = len t
596if gt add p n e
597ret false
598end
599for i ulong n
600if ne get mem add p i get t i
601ret false
602end
603end
604ret true
605end
606
607note whether mem[p, e) is exactly t
608fn meq p ulong e ulong t view uchar * to bool
609if ne sub e p len t
610ret false
611end
612ret sw p e t
613end
614
615note whether mem[a, a + n) equals mem[b, b + m)
616fn mm a ulong n ulong b ulong m ulong to bool
617if ne n m
618ret false
619end
620for i ulong n bound 9223372036854775807
621if ne get mem add a i get mem add b i
622ret false
623end
624end
625ret true
626end
627
628fn bad p ulong to void
629dien etask p 65
630end
631
632note the decimal number mem[p, e) (1 to 20 digits)
633fn dec p ulong e ulong to ulong
634if or ge p e gt sub e p 20
635bad p
636end
637v = ulong 0
638q = p
639while lt q e bound 20
640c = ulong get mem q
641if or lt c 48 gt c 57
642bad p
643end
644v = add mul v 10 sub c 48
645q = add q 1
646end
647ret v
648end
649
650note the number of words in mem[p, e), each a decimal number
651fn nwords p ulong e ulong to ulong
652n = ulong 0
653q = skipsp p e
654while lt q e bound 9223372036854775807
655w = wordend q e
656x = dec q w
657n = add n 1
658q = skipsp w e
659end
660ret n
661end
662
663fn tfd i ulong k ulong to ulong
664ret get tk add mul i 16 k
665end
666
667fn tput i ulong k ulong v ulong to void
668put tk add mul i 16 k v
669end
670
671fn ifd r ulong k ulong to ulong
672ret get inp add mul r 3 k
673end
674
675note an input line of kind k with text mem[o, e): its word count must fit the kind
676fn addinp k ulong o ulong e ulong to void
677want = k
678if eq k 4
679want = 8
680end
681if eq k 5
682want = 1
683end
684if ne nwords o e want
685bad o
686end
687n = get st 1
688r = enlarge inp mul add n 1 3
689if lt r 0
690die eio 70
691end
692b = mul n 3
693put inp b k
694put inp add b 1 o
695put inp add b 2 sub e o
696put st 1 add n 1
697if le k 3
698put st add 16 k add get st add 16 k 1
699end
700if eq k 4
701put st 15 add get st 15 1
702end
703if eq k 5
704put st 16 add get st 16 1
705end
706end
707
708note the record of the j-th input line of kind k
709fn inth k ulong j ulong to ulong
710c = ulong 0
711for r ulong get st 1 bound 9223372036854775807
712if eq ifd r 0 k
713if eq c j
714ret r
715end
716c = add c 1
717end
718end
719die eio 70
720ret 0
721end
722
723note the kind of the line mem[p, q): 1 .. 5 an input, 6 task, 7 say, 8 a function, 0 other
724fn lkind p ulong q ulong to ulong
725if sw p q lin1
726ret 1
727end
728if sw p q lin2
729ret 2
730end
731if sw p q lin3
732ret 3
733end
734if sw p q larr
735ret 4
736end
737if sw p q lcnt
738ret 5
739end
740if sw p q ltask
741ret 6
742end
743if sw p q lsay
744ret 7
745end
746if sw p q lfn
747ret 8
748end
749ret 0
750end
751
752note whether the first word of the line mem[p, q) is t
753fn fw p ulong q ulong t view uchar * to bool
754a = skipsp p q
755ret meq a wordend a q t
756end
757
758note one past the line end of the `end` that closes the function whose body starts at b (so the
759note result minus 1 is that line's newline, or e), 0 when it is not closed before e
760fn bodyend b ulong e ulong to ulong
761d = ulong 1
762p = b
763while lt p e bound 9223372036854775807
764q = lend p e
765if or fw p q twif or fw p q twwhile fw p q twfor
766d = add d 1
767end
768if fw p q twend
769d = sub d 1
770if eq d 0
771ret add q 1
772end
773end
774p = add q 1
775end
776ret 0
777end
778
779note the shape of the params mem[o, q)
780fn shapeof o ulong q ulong to ulong
781if meq o q sg1
782ret 1
783end
784if meq o q sg2
785ret 2
786end
787if meq o q sg3
788ret 3
789end
790if meq o q sg4
791ret 4
792end
793if meq o q sg5
794ret 5
795end
796bad o
797ret 0
798end
799
800note `note task ID FAMILY` at mem[p, q)
801fn ptask p ulong q ulong to void
802w = wordend p q
803if or eq w p ge add w 1 q
804bad p
805end
806put st 10 p
807put st 11 sub w p
808put st 12 add w 1
809put st 13 sub q add w 1
810put st 14 1
811put st 9 0
812end
813
814note the reference function whose `fn ` is at p, its line ending at q: a task; the newline (or
815note e) that ends its closing end
816fn pfn p ulong q ulong e ulong to ulong
817if or eq get st 14 0 eq get st 9 0
818bad p
819end
820nm = add p 3
821w = wordend nm q
822if or ge w q ne get mem nm 116
823bad p
824end
825z = bodyend add q 1 e
826if eq z 0
827bad p
828end
829n = get st 0
830r = enlarge tk mul add n 1 16
831if lt r 0
832die eio 70
833end
834pfn2 n nm w q
835tput n 9 sub sub z 1 add q 1
836put st 0 add n 1
837put st 14 0
838ret sub z 1
839end
840
841fn pfn2 n ulong nm ulong w ulong q ulong to void
842tput n 0 get st 10
843tput n 1 get st 11
844tput n 2 get st 12
845tput n 3 get st 13
846tput n 4 get st 8
847tput n 5 get st 9
848tput n 6 add w 1
849tput n 7 sub q add w 1
850tput n 8 add q 1
851tput n 10 shapeof add w 1 q
852tput n 11 nm
853tput n 12 sub w nm
854tput n 15 0
855end
856
857note TASKS at mem[b, e) into tk and inp
858fn parse b ulong e ulong to void
859p = b
860while lt p e bound 9223372036854775807
861q = lend p e
862k = lkind p q
863if and ge k 1 le k 5
864addinp k add p 9 q
865end
866if eq k 6
867ptask add p 10 q
868end
869if eq k 7
870put st 8 add p 9
871put st 9 sub q add p 9
872end
873if eq k 8
874q = pfn p q e
875end
876p = add q 1
877end
878if or eq get st 0 0 eq get st 14 1
879bad e
880end
881end
882
883note argument i as TASKS
884fn ltasks i ulong to void
885b = aload i
886parse b get st 6
887end
888
889note the cases of shape sh
890fn ncases sh ulong to ulong
891if le sh 3
892ret get st add 16 sh
893end
894ret mul get st 15 get st 16
895end
896
897note ======== generated programs
898
899note ` ulong X` for every word X of mem[o, o + n)
900fn gargs o ulong n ulong to void
901e = add o n
902p = skipsp o e
903while lt p e bound 9223372036854775807
904w = wordend p e
905gtx gsul
906gmem p sub w p
907p = skipsp w e
908end
909end
910
911note the eight puts of arr line mem[o, o + n)
912fn gfillr o ulong n ulong to void
913e = add o n
914p = skipsp o e
915for i ulong 8
916w = wordend p e
917gtx gputa
918gu i
919gc 32
920gmem p sub w p
921gc 10
922p = skipsp w e
923end
924end
925
926note bench_fill: array k of the arr lines into a
927fn gfill to void
928gtx gfill0
929for j ulong get st 15 bound 9223372036854775807
930r = inth 4 j
931gtx gifk
932gu j
933gc 10
934gfillr ifd r 1 ifd r 2
935gtx gend
936end
937gtx gend
938end
939
940note the scalar rows of task i (shape sh) for the table
941fn growsc i ulong sh ulong to void
942for j ulong ncases sh bound 9223372036854775807
943r = inth sh j
944gtx gprv
945gmem tfd i 11 tfd i 12
946gargs ifd r 1 ifd r 2
947gc 10
948end
949end
950
951note one array case of task i for the table: arr line a, cnt record rc
952fn growa1 i ulong sh ulong a ulong rc ulong to void
953gtx gfillc
954gu a
955gc 10
956if eq sh 4
957gtx gprv
958end
959gmem tfd i 11 tfd i 12
960gtx garrul
961gmem ifd rc 1 ifd rc 2
962gc 10
963if eq sh 5
964gtx gpra
965end
966end
967
968fn growar i ulong sh ulong to void
969for a ulong get st 15 bound 9223372036854775807
970for c ulong get st 16 bound 9223372036854775807
971growa1 i sh a inth 5 c
972end
973end
974end
975
976note `fn rowN to void`: task i's row of the table
977fn growfn i ulong to void
978sh = tfd i 10
979gtx growh
980gu i
981gtx growz
982if ge sh 4
983gtx garr0
984end
985gtx gwid
986gu i
987gtx gwid2
988gu i
989gc 10
990if le sh 3
991growsc i sh
992else
993growar i sh
994end
995gtx gprl
996end
997
998note the table program: every reference, one row function each, main calls them in order
999fn gtable to void
1000put st 2 0
1001gtx gpre
1002gfill
1003nt = get st 0
1004for i ulong nt bound 9223372036854775807
1005gtx gidt
1006gu i
1007gtx gquo
1008gmem tfd i 0 tfd i 1
1009gtx gquoz
1010end
1011for j ulong nt bound 9223372036854775807
1012gtx gfn
1013gmem tfd j 11 add add tfd j 12 1 tfd j 7
1014gc 10
1015gmem tfd j 8 tfd j 9
1016gc 10
1017growfn j
1018end
1019gtx gmain0
1020for k ulong nt bound 9223372036854775807
1021gtx growc
1022gu k
1023gc 10
1024end
1025gtx gmainz
1026end
1027
1028note the next expected value of the row at the cursor
1029fn gexp i ulong to void
1030p = get st 28
1031e = get st 29
1032if ge p e
1033dien eexp i 66
1034end
1035w = wordend p e
1036gmem p sub w p
1037put st 28 skipsp w e
1038end
1039
1040note the scalar cases of task i for the score program
1041fn gscsc i ulong sh ulong to void
1042for j ulong ncases sh bound 9223372036854775807
1043r = inth sh j
1044gtx gifne
1045gargs ifd r 1 ifd r 2
1046gtx gsul
1047gexp i
1048gtx gfail
1049end
1050end
1051
1052note one array case of task i for the score program
1053fn gsca1 i ulong sh ulong a ulong rc ulong to void
1054gtx gfillc
1055gu a
1056gc 10
1057if eq sh 4
1058gtx gifne
1059gtx garrul
1060gmem ifd rc 1 ifd rc 2
1061gtx gsul
1062gexp i
1063gtx gfail
1064ret
1065end
1066gtx gcall
1067gtx garrul
1068gmem ifd rc 1 ifd rc 2
1069gc 10
1070for x ulong 8
1071gtx gifget
1072gu x
1073gtx gsul
1074gexp i
1075gtx gfail
1076end
1077end
1078
1079fn gscar i ulong sh ulong to void
1080for a ulong get st 15 bound 9223372036854775807
1081for c ulong get st 16 bound 9223372036854775807
1082gsca1 i sh a inth 5 c
1083end
1084end
1085end
1086
1087note the score program of task i with the answer body mem[bo, bo + bn); the expectation cursor is
1088note on the task's row
1089fn gscore i ulong bo ulong bn ulong to void
1090put st 2 0
1091sh = tfd i 10
1092if ge sh 4
1093gfill
1094end
1095gtx gsolve
1096gmem tfd i 6 tfd i 7
1097gc 10
1098gmem bo bn
1099gc 10
1100gtx gmain0
1101if ge sh 4
1102gtx garr0
1103end
1104if le sh 3
1105gscsc i sh
1106else
1107gscar i sh
1108end
1109if ne get st 28 get st 29
1110dien eexp i 66
1111end
1112gtx gret77
1113end
1114
1115note the prompt of task i into prog
1116fn gprompt i ulong to void
1117put st 2 0
1118gtx gnote
1119gmem tfd i 4 tfd i 5
1120gc 10
1121gtx gsolve
1122gmem tfd i 6 tfd i 7
1123gc 10
1124end
1125
1126note ======== table and check
1127
1128note build and run the table program; the table's offset in mem (it ends at the fill)
1129fn mktable to ulong
1130gtable
1131s = compile
1132if ne s 0
1133dien ecomp ulong s 1
1134end
1135s = runp true
1136if ne s 0
1137dien ecomp ulong s 1
1138end
1139wpath fpout
1140b = get st 6
1141if eq fload 18446744073709551615
1142die eio 70
1143end
1144ret b
1145end
1146
1147fn cmdtable to void
1148if ne argcnt 5
1149die eargs 2
1150end
1151put st 27 3
1152put st 26 4
1153ltasks 2
1154b = mktable
1155omem b sub get st 6 b
1156oflush
1157end
1158
1159note the fields in which the rows mem[a, ae) and mem[b, be) differ (both start after their id)
1160fn rowdiff a ulong ae ulong b ulong be ulong to ulong
1161n = ulong 0
1162p = skipsp a ae
1163q = skipsp b be
1164while and lt p ae lt q be bound 9223372036854775807
1165w = wordend p ae
1166x = wordend q be
1167if not mm p sub w p q sub x q
1168n = add n 1
1169end
1170p = skipsp w ae
1171q = skipsp x be
1172end
1173ret n
1174end
1175
1176note the start of row i of the table at mem[b, e) (rows are lines), checking that it carries task
1177note i's id; the row's values start after the id
1178fn rowat b ulong e ulong i ulong to ulong
1179p = b
1180for j ulong i bound 9223372036854775807
1181p = add lend p e 1
1182end
1183if ge p e
1184dien eexp i 66
1185end
1186w = wordend p lend p e
1187if not mm p sub w p tfd i 0 tfd i 1
1188dien eexp i 66
1189end
1190ret w
1191end
1192
1193note the smallest number of differing fields over every pair of tasks of one shape in the table at
1194note mem[b, e); each pair that does not differ at all is printed
1195fn minsep b ulong e ulong to ulong
1196m = ulong 18446744073709551615
1197nt = get st 0
1198for i ulong nt bound 9223372036854775807
1199a = rowat b e i
1200for j ulong i bound 9223372036854775807
1201if eq tfd i 10 tfd j 10
1202c = rowat b e j
1203d = rowdiff a lend a e c lend c e
1204if eq d 0
1205ot msame
1206omem tfd j 0 tfd j 1
1207oc 32
1208omem tfd i 0 tfd i 1
1209oc 10
1210end
1211if lt d m
1212m = d
1213end
1214end
1215end
1216end
1217ret m
1218end
1219
1220fn cmdcheck to void
1221if ne argcnt 6
1222die eargs 2
1223end
1224put st 27 4
1225put st 26 5
1226ltasks 2
1227xb = aload 3
1228xe = get st 6
1229b = mktable
1230e = get st 6
1231ok = mm xb sub xe xb b sub e b
1232if not ok
1233ot mdiff
1234end
1235m = minsep b e
1236if eq m 0
1237ok = false
1238end
1239if ok
1240ot mpass
1241else
1242ot mfail
1243end
1244ou get st 0
1245ot mcase
1246ou get st 1
1247ot msep
1248ou m
1249oc 10
1250oflush
1251if not ok
1252exit 1
1253end
1254end
1255
1256note ======== prompts and samples
1257
1258fn cmdprompts to void
1259if ne argcnt 4
1260die eargs 2
1261end
1262put st 26 3
1263ltasks 2
1264for i ulong get st 0 bound 9223372036854775807
1265gprompt i
1266wpid fpprm i
1267fsave 420
1268end
1269end
1270
1271note sample TASKS WORK OLLM CMD CK [MERGES]: one answer file per task
1272fn cmdsample to void
1273na = ulong argcnt
1274if and ne na 7 ne na 8
1275die eargs 2
1276end
1277put st 26 3
1278ltasks 2
1279for i ulong get st 0 bound 9223372036854775807
1280s = sample1 i na
1281if ne s 0
1282ot msfail
1283omem tfd i 0 tfd i 1
1284oc 32
1285ou ulong s
1286oc 10
1287oflush
1288exit 71
1289end
1290end
1291end
1292
1293fn sample1 i ulong na ulong to long
1294gprompt i
1295pclr
1296ptx tnull
1297fi = popen false 0
1298wpid fpans i
1299fo = popen true 420
1300kclr
1301karg 4
1302karg 5
1303karg 6
1304ktx a42
1305ktx a128
1306ktx a0
1307kprog
1308if eq na 8
1309karg 7
1310end
1311pid = spawn fi fo false
1312z = fclose fi
1313z = fclose fo
1314ret waitp pid 3600000
1315end
1316
1317note ======== normal forms (seen)
1318
1319note the index of the name mem[o, o + n) in nmt, or st25 when it is not there
1320fn nmfind o ulong n ulong to ulong
1321c = get st 25
1322for i ulong c bound 9223372036854775807
1323if mm o n get nmt mul i 2 get nmt add mul i 2 1
1324ret i
1325end
1326end
1327ret c
1328end
1329
1330fn nmadd o ulong n ulong to void
1331c = get st 25
1332if lt nmfind o n c
1333ret
1334end
1335r = enlarge nmt mul add c 1 2
1336if lt r 0
1337die eio 70
1338end
1339put nmt mul c 2 o
1340put nmt add mul c 2 1 n
1341put st 25 add c 1
1342end
1343
1344fn nc c ulong to void
1345n = get st 24
1346if ge n len nrm
1347r = enlarge nrm add mul n 2 4096
1348if lt r 0
1349die eio 70
1350end
1351end
1352put nrm n uchar c
1353put st 24 add n 1
1354end
1355
1356note the names the fn line mem[p, q) declares: the function, then each parameter
1357fn nmsig p ulong q ulong to void
1358a = skipsp add p 3 q
1359w = wordend a q
1360nmadd a sub w a
1361a = skipsp w q
1362while lt a q bound 9223372036854775807
1363w = wordend a q
1364if meq a w twto
1365ret
1366end
1367nmadd a sub w a
1368a = skipsp w q
1369w = wordend a q
1370if or meq a w twview meq a w twedit
1371a = skipsp w q
1372w = wordend a q
1373a = skipsp w q
1374w = wordend a q
1375end
1376a = skipsp w q
1377end
1378end
1379
1380note the names the body line mem[p, q) declares: `NAME = ..` and `for NAME ..`
1381fn nmline p ulong q ulong to void
1382a = skipsp p q
1383w = wordend a q
1384b = skipsp w q
1385x = wordend b q
1386if ge b q
1387ret
1388end
1389if meq a w twfor
1390nmadd b sub x b
1391ret
1392end
1393if meq b x tweq
1394nmadd a sub w a
1395end
1396end
1397
1398note the line mem[p, q) in normal form onto nrm: words joined by one space, declared names as
1399note v and their index, a newline; blank and note lines add nothing
1400fn nline p ulong q ulong to void
1401a = skipsp p q
1402if or ge a q meq a wordend a q lnote
1403ret
1404end
1405first = true
1406while lt a q bound 9223372036854775807
1407w = wordend a q
1408if not first
1409nc 32
1410end
1411first = false
1412nword a sub w a
1413a = skipsp w q
1414end
1415nc 10
1416end
1417
1418fn nword a ulong n ulong to void
1419i = nmfind a n
1420if lt i get st 25
1421nc 118
1422d = udec i
1423while lt d 24 bound 24
1424nc ulong get dg d
1425d = add d 1
1426end
1427ret
1428end
1429for j ulong n bound 9223372036854775807
1430nc ulong get mem add a j
1431end
1432end
1433
1434note the function at mem[p ..) (its fn line ends at q, its closing end line at z) in normal form
1435note onto nrm
1436fn nfn p ulong q ulong z ulong to void
1437put st 25 0
1438nmsig p q
1439a = add q 1
1440while lt a z bound 9223372036854775807
1441b = lend a z
1442nmline a b
1443a = add b 1
1444end
1445a = p
1446while lt a z bound 9223372036854775807
1447b = lend a z
1448nline a b
1449a = add b 1
1450end
1451end
1452
1453note every task's reference in normal form (tk 13, 14)
1454fn ntasks to void
1455for i ulong get st 0 bound 9223372036854775807
1456p = sub tfd i 11 3
1457q = sub tfd i 8 1
1458z = add tfd i 8 tfd i 9
1459b = get st 24
1460nfn p q z
1461tput i 13 b
1462tput i 14 sub get st 24 b
1463end
1464end
1465
1466note whether nrm[a, a + n) equals nrm[b, b + n)
1467fn nsame a ulong b ulong n ulong to bool
1468for i ulong n bound 9223372036854775807
1469if ne get nrm add a i get nrm add b i
1470ret false
1471end
1472end
1473ret true
1474end
1475
1476note mark (tk 15 = 9) every task whose normal form equals nrm[b, fill)
1477fn nmark b ulong to void
1478n = sub get st 24 b
1479for i ulong get st 0 bound 9223372036854775807
1480if eq tfd i 14 n
1481if nsame tfd i 13 b n
1482tput i 15 9
1483end
1484end
1485end
1486end
1487
1488note mark the tasks whose reference is a function of the corpus at mem[b, e); the functions read
1489fn nscan b ulong e ulong to ulong
1490f = ulong 0
1491p = b
1492while lt p e bound 9223372036854775807
1493q = lend p e
1494if sw p q lfn
1495z = bodyend add q 1 e
1496if ne z 0
1497m = get st 24
1498nfn p q sub z 1
1499nmark m
1500put st 24 m
1501f = add f 1
1502q = sub z 1
1503end
1504end
1505p = add q 1
1506end
1507ret f
1508end
1509
1510fn cmdseen to void
1511if ne argcnt 4
1512die eargs 2
1513end
1514ltasks 2
1515ntasks
1516b = aload 3
1517f = nscan b get st 6
1518k = ulong 0
1519for i ulong get st 0 bound 9223372036854775807
1520if eq tfd i 15 9
1521ot mseen
1522omem tfd i 0 tfd i 1
1523oc 10
1524k = add k 1
1525end
1526end
1527ot mseens
1528ou get st 0
1529ot msseen
1530ou k
1531ot mseenf
1532ou f
1533oc 10
1534oflush
1535end
1536
1537note ======== score
1538
1539note whether the body mem[b, e) says exit or trap
1540fn banned b ulong e ulong to bool
1541p = b
1542while lt p e bound 9223372036854775807
1543q = lend p e
1544a = skipsp p q
1545while lt a q bound 9223372036854775807
1546w = wordend a q
1547if or meq a w twexit meq a w twtrap
1548ret true
1549end
1550a = skipsp w q
1551end
1552p = add q 1
1553end
1554ret false
1555end
1556
1557note whether mem[p, e) holds anything but spaces, tabs, newlines and carriage returns
1558fn more p ulong e ulong to bool
1559for i ulong sub e p bound 9223372036854775807
1560c = get mem add p i
1561if and and ne c 32 ne c 9 and ne c 10 ne c 13
1562ret true
1563end
1564end
1565ret false
1566end
1567
1568note the verdict of task i from the answer at mem[ao, ae), the expectation cursor on its row
1569fn judge i ulong ao ulong ae ulong to ulong
1570z = bodyend ao ae
1571if eq z 0
1572ret 5
1573end
1574q = sub z 1
1575if banned ao q
1576ret 6
1577end
1578gscore i ao sub q ao
1579s = compile
1580if eq s 1000
1581ret 8
1582end
1583if ne s 0
1584ret 4
1585end
1586s = runp false
1587if eq s 1000
1588ret 8
1589end
1590if ne s 77
1591ret 3
1592end
1593if more q ae
1594ret 2
1595end
1596ret 1
1597end
1598
1599fn vname v ulong to void
1600if eq v 1
1601ot v1
1602end
1603if eq v 2
1604ot v2
1605end
1606if eq v 3
1607ot v3
1608end
1609if eq v 4
1610ot v4
1611end
1612if eq v 5
1613ot v5
1614end
1615if eq v 6
1616ot v6
1617end
1618if eq v 7
1619ot v7
1620end
1621if eq v 8
1622ot v8
1623end
1624if eq v 9
1625ot v9
1626end
1627end
1628
1629note grade task i: load its answer, judge it, print its R line, keep the verdict in tk 15
1630fn score1 i ulong xb ulong xe ulong mark ulong to void
1631v = tfd i 15
1632if ne v 9
1633a = rowat xb xe i
1634put st 28 skipsp a lend a xe
1635put st 29 lend a xe
1636put st 6 mark
1637wpid fpans i
1638n = fload
1639v = 7
1640if ne n 18446744073709551615
1641v = judge i mark add mark n
1642end
1643tput i 15 v
1644end
1645oc 82
1646oc 32
1647omem tfd i 0 tfd i 1
1648oc 32
1649omem tfd i 2 tfd i 3
1650oc 32
1651vname v
1652oc 10
1653oflush
1654end
1655
1656note the tasks of task i's family with verdict v
1657fn famcnt i ulong v ulong to ulong
1658n = ulong 0
1659for j ulong get st 0 bound 9223372036854775807
1660if mm tfd i 2 tfd i 3 tfd j 2 tfd j 3
1661if or eq v 0 eq tfd j 15 v
1662n = add n 1
1663end
1664end
1665end
1666ret n
1667end
1668
1669note whether an earlier task has task i's family
1670fn famold i ulong to bool
1671for j ulong i bound 9223372036854775807
1672if mm tfd i 2 tfd i 3 tfd j 2 tfd j 3
1673ret true
1674end
1675end
1676ret false
1677end
1678
1679note the tasks with verdict v
1680fn vcnt v ulong to ulong
1681n = ulong 0
1682for j ulong get st 0 bound 9223372036854775807
1683if eq tfd j 15 v
1684n = add n 1
1685end
1686end
1687ret n
1688end
1689
1690fn summary to void
1691for i ulong get st 0 bound 9223372036854775807
1692if not famold i
1693oc 70
1694oc 32
1695omem tfd i 2 tfd i 3
1696oc 32
1697ou famcnt i 0
1698for v ulong 9
1699oc 32
1700ou famcnt i add v 1
1701end
1702oc 10
1703end
1704end
1705k = vcnt 9
1706ot mscore
1707ou sub get st 0 k
1708ot mspass
1709ou vcnt 1
1710ot mscut
1711ou vcnt 2
1712ot msseen
1713ou k
1714oc 10
1715oflush
1716end
1717
1718note score TASKS EXPECT OMC WORK [CORPUS]
1719fn cmdscore to void
1720na = ulong argcnt
1721if and ne na 6 ne na 7
1722die eargs 2
1723end
1724put st 27 4
1725put st 26 5
1726ltasks 2
1727xb = aload 3
1728xe = get st 6
1729if eq na 7
1730ntasks
1731b = aload 6
1732f = nscan b get st 6
1733end
1734mark = get st 6
1735for i ulong get st 0 bound 9223372036854775807
1736score1 i xb xe mark
1737end
1738summary
1739end
1740
1741fn iscmd t view uchar * to bool
1742pclr
1743parg 1
1744n = get st 3
1745if ne n len t
1746ret false
1747end
1748for i ulong n
1749if ne get pth i get t i
1750ret false
1751end
1752end
1753ret true
1754end
1755
1756fn main to int
1757if lt argcnt 2
1758die eargs 2
1759end
1760if iscmd ctable
1761cmdtable
1762ret 0
1763end
1764if iscmd ccheck
1765cmdcheck
1766ret 0
1767end
1768if iscmd cprompts
1769cmdprompts
1770ret 0
1771end
1772if iscmd csample
1773cmdsample
1774ret 0
1775end
1776if iscmd cscore
1777cmdscore
1778ret 0
1779end
1780if iscmd cseen
1781cmdseen
1782ret 0
1783end
1784die eargs 2
1785ret 2
1786end