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 / wgate / wgate.om

4597 lines · 77553 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: AGPL-3.0-only
3note wgate.om (DRA-187, lane wsp): the round40 retention gate runner in seeded Omega. It replaces the
4note Python glue evidence/OMEGALLM/wsp-dra187-20261107/gates.py, which imported round41 lib.py,
5note repair.py, checker.py and check_behavior.py. Composed after wbuild.om (its main renamed wbmain):
6note OMC=omc CORE=0 wbuild OUT/wgate tools/omegallm/wdrive/wbuild.om@wbmain tools/omegallm/wgate/wgate.om
7note Usage (README.md has the full contract):
8note wgate run CANDIDATE.ck OUTDIR
9note wgate replay probe|first|jobs DATA.json RECORDED.json OUTDIR [STRIDE]
10note wgate replaylog probe|first|jobs DATA.json RECORDED.json LOGDIR LABEL OUTDIR [STRIDE]
11note wgate dryrun probe|jobs CK OUTDIR LABEL DATA.json
12note Exits: 0 done (run: every task finished or stopped at a failed gate; replay: no mismatch),
13note 1 replay mismatch, 2 usage, 3 refused (no SPARK_WINDOW), 4 base checkpoint sha256 mismatch,
14note 5 OUTDIR belongs to another candidate, 10 window budget reached, 61 arena or table full,
15note 70 host failure, 71 file operation failed, 72 text decode or encode error, 73 native command
16note exit status not 0, 74 native command timeout, 75 sampler answer count mismatch, 76 compile or
17note test timeout inside compile_test, 77 JSON nesting past the measured Python limit, 78 geval
18note output unparsable, 79 unsupported JSON shape, 80 data or recorded file is not JSON.
19note
20note Every string lives in the arena wga as (offset, length); functions take offsets because a part of
21note a global is refused (error 19). wgr carries extra results. Slots (wgsl) name arena strings.
22
23const WGNO ulong 18446744073709551615
24const WGREC ulong 18446744073709551614
25const WGTMO long -1000000
26const WGABS long -2000000
27const WGMAXA ulong 16777216
28const WGMAXJ ulong 2097152
29const SOUT ulong 0
30const SCAND ulong 1
31const SCK ulong 2
32const SLAB ulong 3
33const SWIN ulong 4
34const SFIX ulong 5
35const SCL ulong 6
36const SJL ulong 7
37const SLOG ulong 8
38const SBLD ulong 9
39const SCB ulong 10
40const SCT ulong 11
41const SJF ulong 12
42const SPL ulong 13
43
44global wga uchar 16777216
45global wgan ulong 1
46global wgr ulong 8
47global wgsl ulong 64
48global wgjt uchar 2097152
49global wgjo ulong 2097152
50global wgjl ulong 2097152
51global wgjc ulong 2097152
52global wgjs ulong 2097152
53global wgjn ulong 1
54global wgks ulong 10000
55global wgkl ulong 10000
56global wgps ulong 8
57global wgnd ulong 68
58global wgsb uchar 128
59global wgpo ulong 1024
60global wgpl ulong 1024
61global wgao ulong 1024
62global wgal ulong 1024
63global wgact ulong 1024
64global wgdr ulong 1024
65global wgrr ulong 1024
66global wgok uchar 1024
67global wgx long 4
68global wgxr long 4
69global wgmd ulong 4
70global wgob uchar 65536
71global wgobn ulong 1
72global wgobf int 1
73global wgg uchar 8
74global wgtm long 4
75global wgmis ulong 1
76global wgjst uchar 1024
77global wgjso ulong 1024
78global wgjsn ulong 1024
79global wgjoo ulong 1024
80global wgjon ulong 1024
81global wgjdn uchar 1024
82global wgjps uchar 1024
83global wgjvf uchar 1024
84global wgjhv uchar 1024
85global wgjer uchar 1024
86global wgjtn ulong 1024
87global wgtro ulong 7168
88global wgtrl ulong 7168
89global wgtst uchar 7168
90global wgtto ulong 7168
91global wgttn ulong 7168
92global wgtth uchar 7168
93
94text wgtomc "/home/drakestapleton/handoffs/omega-llm-20261101/omega-mv/seed/out/omc"
95text wgtgpu "/tmp/gk/r10/ollm-gb10"
96text wgtcpu "/home/drakestapleton/handoffs/weight-tuning-20261104/build/ollm"
97text wgtmrg "/home/drakestapleton/handoffs/omega-llm-20261101/v1-data/merges4096.bin"
98text wgtbs "/home/drakestapleton/handoffs/tool-omega-20261104/build/batch-sample"
99text wgtr40d "/home/drakestapleton/handoffs/tool-omega-20261104/round40/data/"
100text wgtstok "/home/drakestapleton/handoffs/tool-omega-20261104/round40/data/story-final.tok"
101text wgtbase "/home/drakestapleton/.local/share/omega-tool-model/round40/model.ck"
102text wgtbsha "7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346"
103text wgtnull "/dev/null"
104text wgtnl "\n"
105text wgtsp " "
106text wgtfull "wgate: arena or table full\n"
107text wgtfile "wgate: file operation failed: "
108text wgtdec "wgate: text decode or encode error: "
109text wgtnoj "wgate: not JSON: "
110text wgtshp "wgate: unsupported JSON shape\n"
111text wgtrec "wgate: JSON nesting past the Python recursion limit\n"
112text wgthost "wgate: host failure\n"
113text wgtcmdf "wgate: native command failed: "
114text wgtcmdt "wgate: native command timed out: "
115text wgtcnt "wgate: sampler answer count mismatch: "
116text wgtctt "wgate: compile_test timed out\n"
117text wgtgev "wgate: geval output has no single E row for the width\n"
118text wgtuse "usage: wgate run CANDIDATE.ck OUTDIR | replay probe|first|jobs DATA REC OUTDIR [STRIDE] | replaylog probe|first|jobs DATA REC LOGDIR LABEL OUTDIR [STRIDE] | dryrun probe|jobs CK OUTDIR LABEL DATA\n"
119text wgtrefu "REFUSED: SPARK_WINDOW is not set; run inside a spark window\n"
120text wgtbsm "wgate: base checkpoint sha256 mismatch: "
121text wgtcsm "wgate: OUTDIR belongs to another candidate\n"
122text wgtzero "wgate: latency base time is zero\n"
123text wgtsw "SPARK_WINDOW"
124text wgtbud "WSP_BUDGET"
125text wgtbudb "wgate: WSP_BUDGET is not a decimal number\n"
126text wgtdiv "wgate: replay has no recorded answer for this turn\n"
127
128note ---------------------------------------------------------------- basics
129
130fn wgdie t view uchar * c int to void
131wdoflush 1
132w = write 2 t 0 len t
133exit c
134end
135
136fn wgdiep t view uchar * c int to void
137wdoflush 1
138w = write 2 t 0 len t
139w2 = write 2 wdp 0 get wdpn 0
140w3 = write 2 wgtnl 0 1
141exit c
142end
143
144fn wgac c ulong to void
145n = get wgan 0
146if ge n WGMAXA
147wgdie wgtfull 61
148end
149put wga n uchar c
150put wgan 0 add n 1
151end
152
153fn wgat t view uchar * to void
154for i ulong len t
155wgac ulong get t i
156end
157end
158
159fn wgacp o ulong n ulong to void
160i = ulong 0
161while lt i n bound 64
162while lt i n bound 999999
163wgac ulong get wga add o i
164i = add i 1
165end
166end
167end
168
169fn wgad v ulong to void
170k = wddec v
171while gt k 0 bound 25
172k = sub k 1
173wgac ulong get wdt k
174end
175end
176
177fn wgadl v long to void
178if lt v 0
179wgac 45
180wgad ulong neg v
181else
182wgad ulong v
183end
184end
185
186fn wgsset k ulong o ulong n ulong to void
187put wgsl mul k 2 o
188put wgsl add mul k 2 1 n
189end
190
191fn wgso k ulong to ulong
192ret get wgsl mul k 2
193end
194
195fn wgsn k ulong to ulong
196ret get wgsl add mul k 2 1
197end
198
199note append slot k to the arena
200fn wgasl k ulong to void
201wgacp wgso k wgsn k
202end
203
204note slot k = text t
205fn wgsett k ulong t view uchar * to void
206o = get wgan 0
207wgat t
208wgsset k o len t
209end
210
211note slot k = the path builder's bytes
212fn wgsetp k ulong to void
213o = get wgan 0
214for i ulong get wdpn 0
215wgac ulong get wdp i
216end
217wgsset k o get wdpn 0
218end
219
220note slot k = the arena from offset o to the top
221fn wgsetf k ulong o ulong to void
222wgsset k o sub get wgan 0 o
223end
224
225fn wgeqa a ulong b ulong n ulong to bool
226i = ulong 0
227while lt i n bound 999999
228if ne get wga add a i get wga add b i
229ret false
230end
231i = add i 1
232end
233ret true
234end
235
236fn wgeq2 a ulong an ulong b ulong bn ulong to bool
237if ne an bn
238ret false
239end
240ret wgeqa a b an
241end
242
243fn wgeqt o ulong n ulong t view uchar * to bool
244if ne n len t
245ret false
246end
247for i ulong n
248if ne get wga add o i get t i
249ret false
250end
251end
252ret true
253end
254
255fn wgsw o ulong n ulong t view uchar * to bool
256if lt n len t
257ret false
258end
259for i ulong len t
260if ne get wga add o i get t i
261ret false
262end
263end
264ret true
265end
266
267note first index (relative) of arena pattern p in [o, o + n), or WGNO
268fn wgfind o ulong n ulong p ulong pn ulong to ulong
269if gt pn n
270ret WGNO
271end
272lim = sub n pn
273i = ulong 0
274while le i lim bound 999999
275if wgeqa add o i p pn
276ret i
277end
278i = add i 1
279end
280ret WGNO
281end
282
283note as wgfind with a text pattern
284fn wgfindt o ulong n ulong t view uchar * to ulong
285pn = len t
286if gt pn n
287ret WGNO
288end
289lim = sub n pn
290i = ulong 0
291while le i lim bound 999999
292if wgsw add o i sub n i t
293ret i
294end
295i = add i 1
296end
297ret WGNO
298end
299
300note non-overlapping occurrences of arena pattern p (pn > 0), as str.count
301fn wgcnt o ulong n ulong p ulong pn ulong to ulong
302c = ulong 0
303i = ulong 0
304while le add i pn n bound 999999
305if wgeqa add o i p pn
306c = add c 1
307i = add i pn
308else
309i = add i 1
310end
311end
312ret c
313end
314
315fn wgcntt o ulong n ulong t view uchar * to ulong
316c = ulong 0
317i = ulong 0
318pn = len t
319while le add i pn n bound 999999
320if wgsw add o i sub n i t
321c = add c 1
322i = add i pn
323else
324i = add i 1
325end
326end
327ret c
328end
329
330note ---------------------------------------------------------------- results buffer (wgob to fd wgobf)
331
332fn wgofl to void
333n = get wgobn 0
334t = ulong 0
335while lt t n bound 999999
336w = write get wgobf 0 wgob t sub n t
337if le w 0
338wgdie wgthost 70
339end
340t = add t ulong w
341end
342put wgobn 0 0
343end
344
345fn wgoc c ulong to void
346n = get wgobn 0
347if ge n 65536
348wgofl
349n = 0
350end
351put wgob n uchar c
352put wgobn 0 add n 1
353end
354
355fn wgot t view uchar * to void
356for i ulong len t
357wgoc ulong get t i
358end
359end
360
361fn wgoa o ulong n ulong to void
362i = ulong 0
363while lt i n bound 999999
364wgoc ulong get wga add o i
365i = add i 1
366end
367end
368
369fn wgod v ulong to void
370k = wddec v
371while gt k 0 bound 25
372k = sub k 1
373wgoc ulong get wdt k
374end
375end
376
377fn wgodl v long to void
378if lt v 0
379wgoc 45
380wgod ulong neg v
381else
382wgod ulong v
383end
384end
385
386note stdout helpers over wdo: arena range and signed decimal
387fn wgpra o ulong n ulong to void
388i = ulong 0
389while lt i n bound 999999
390wdoc ulong get wga add o i
391i = add i 1
392end
393end
394
395fn wgprl v long to void
396if lt v 0
397wdoc 45
398wdod ulong neg v
399else
400wdod ulong v
401end
402end
403
404note ---------------------------------------------------------------- text (model output is ASCII; wgasc refuses the rest)
405
406note exit 72 unless every byte of [o, o + n) is ASCII
407fn wgasc o ulong n ulong to void
408i = ulong 0
409while lt i n bound 64
410while lt i n bound 999999
411if gt get wga add o i 127
412wgdie wgtdec 72
413end
414i = add i 1
415end
416end
417end
418
419note str.isspace on ASCII: 9..13 and 28..32
420fn wgisws c ulong to bool
421if and ge c 9 le c 13
422ret true
423end
424ret and ge c 28 le c 32
425end
426
427note str.strip(): result in wgr 0, wgr 1
428fn wgstrip o ulong n ulong to void
429a = o
430e = add o n
431while lt a e bound 999999
432if not wgisws ulong get wga a
433break
434end
435a = add a 1
436end
437while gt e a bound 999999
438if not wgisws ulong get wga sub e 1
439break
440end
441e = sub e 1
442end
443put wgr 0 a
444put wgr 1 sub e a
445end
446
447note text(raw) = raw.split('\nDone.')[0].strip(): result in wgr 0, wgr 1
448text wgtdone "\nDone."
449fn wgtext o ulong n ulong to void
450k = wgfindt o n wgtdone
451m = n
452if ne k WGNO
453m = k
454end
455wgstrip o m
456end
457
458note str.splitlines on ASCII: the line [p, result) ends at \n \r \r\n \v \f \x1c \x1d \x1e; next start in wgr 2
459fn wgeol p ulong e ulong to ulong
460q = p
461while lt q e bound 999999
462c = get wga q
463if or or eq c 10 eq c 11 or eq c 12 eq c 28
464put wgr 2 add q 1
465ret q
466end
467if or eq c 29 eq c 30
468put wgr 2 add q 1
469ret q
470end
471if eq c 13
472put wgr 2 add q 1
473if lt add q 1 e
474if eq get wga add q 1 10
475put wgr 2 add q 2
476end
477end
478ret q
479end
480q = add q 1
481end
482put wgr 2 e
483ret e
484end
485
486fn wgdig c ulong to bool
487ret and ge c 48 le c 57
488end
489
490note re.fullmatch of one line against a pattern in the wgate mini-language:
491note @ = \d{1,3}, % = \d{1,2}, ^ = [1-5], ~ = [1-6], $ = [A-Za-z0-9 ]{0,80}. No literal of the
492note patterns is a digit or a class member right after a run, so the greedy run is the regex result.
493fn wgmatch o ulong n ulong t view uchar * to bool
494i = ulong 0
495j = ulong 0
496while lt j len t bound 4096
497pc = ulong get t j
498j = add j 1
499if or eq pc 64 eq pc 37
500k = ulong 0
501while lt add i k n bound 4096
502if not wgdig ulong get wga add o add i k
503break
504end
505k = add k 1
506end
507mx = ulong 3
508if eq pc 37
509mx = 2
510end
511if or eq k 0 gt k mx
512ret false
513end
514i = add i k
515continue
516end
517if or eq pc 94 eq pc 126
518if ge i n
519ret false
520end
521c = ulong get wga add o i
522hi = ulong 53
523if eq pc 126
524hi = 54
525end
526if or lt c 49 gt c hi
527ret false
528end
529i = add i 1
530continue
531end
532if eq pc 36
533k2 = ulong 0
534while lt add i k2 n bound 4096
535if not wgcls ulong get wga add o add i k2
536break
537end
538k2 = add k2 1
539end
540if gt k2 80
541ret false
542end
543i = add i k2
544continue
545end
546if ge i n
547ret false
548end
549if ne ulong get wga add o i pc
550ret false
551end
552i = add i 1
553end
554ret eq i n
555end
556
557fn wgcls c ulong to bool
558if wgdig c
559ret true
560end
561if eq c 32
562ret true
563end
564if and ge c 65 le c 90
565ret true
566end
567ret and ge c 97 le c 122
568end
569
570note checker.patterns (check_behavior.safe_lines + checker additions)
571text wgc00 "fn main to int"
572text wgc01 "end"
573text wgc02 "else"
574text wgc03 "ret @"
575text wgc04 "ret int @"
576text wgc05 "ret add int @ int @"
577text wgc06 "if gt int @ int @"
578text wgc07 "text msg \"$\\n\""
579text wgc08 "n = write int 1 msg ulong 0 len msg"
580text wgc09 "if ne n long len msg"
581text wgc10 "fn inc x int to int"
582text wgc11 "ret add x int %"
583text wgc12 "ret inc int %"
584text wgc13 "s = int %"
585text wgc14 "for i ulong ^"
586text wgc15 "s = add s int ^"
587text wgc16 "ret s"
588
589fn wgckl o ulong n ulong to bool
590if or or wgmatch o n wgc00 wgmatch o n wgc01 or wgmatch o n wgc02 wgmatch o n wgc03
591ret true
592end
593if or or wgmatch o n wgc04 wgmatch o n wgc05 or wgmatch o n wgc06 wgmatch o n wgc07
594ret true
595end
596if or or wgmatch o n wgc08 wgmatch o n wgc09 or wgmatch o n wgc10 wgmatch o n wgc11
597ret true
598end
599if or or wgmatch o n wgc12 wgmatch o n wgc13 or wgmatch o n wgc14 wgmatch o n wgc15
600ret true
601end
602ret wgmatch o n wgc16
603end
604
605note repair.PATTERNS
606text wgr00 "fn calc x int to int"
607text wgr01 "ret add x int ~"
608text wgr02 "ret mul x int ~"
609text wgr03 "ret sub x int ~"
610text wgr04 "ret calc int %"
611text wgr05 "s = x"
612text wgr06 "for i ulong ~"
613text wgr07 "s = add s int ~"
614
615fn wgrpl o ulong n ulong to bool
616if or or wgmatch o n wgr00 wgmatch o n wgc00 or wgmatch o n wgc01 wgmatch o n wgr01
617ret true
618end
619if or or wgmatch o n wgr02 wgmatch o n wgr03 or wgmatch o n wgr04 wgmatch o n wgr05
620ret true
621end
622if or or wgmatch o n wgr06 wgmatch o n wgr07 wgmatch o n wgc16
623ret true
624end
625ret false
626end
627
628note every line of text.splitlines() matches: mode 0 checker, 1 repair, 2 the for-loop line only (any)
629fn wglines o ulong n ulong md ulong to bool
630p = o
631e = add o n
632hit = false
633while lt p e bound 999999
634q = wgeol p e
635ln = sub q p
636nx = get wgr 2
637if eq md 2
638if wgmatch p ln wgc14
639hit = true
640end
641else
642ok = false
643if eq md 0
644ok = wgckl p ln
645else
646ok = wgrpl p ln
647end
648if not ok
649ret false
650end
651end
652p = nx
653end
654if eq md 2
655ret hit
656end
657ret true
658end
659
660note ---------------------------------------------------------------- JSON (CPython 3.12 json.loads on the subset wgate meets)
661note Node kinds in wgjt: 1 null, 2 false, 3 true, 4 number, 5 string, 6 array, 7 object. A string's
662note decoded bytes are (wgjo, wgjl) in the arena; a number keeps its source text there. Containers:
663note first child wgjc, next sibling wgjs, count wgjo. Object children alternate key, value.
664note Refused (exit 79): \u escapes naming surrogates, NaN, Infinity, nesting deeper than 512.
665note A malformed text gives WGNO (the ValueError of json.loads).
666
667fn wgjnew t ulong o ulong n ulong to ulong
668k = get wgjn 0
669if ge k WGMAXJ
670wgdie wgtfull 61
671end
672put wgjt k uchar t
673put wgjo k o
674put wgjl k n
675put wgjc k 0
676put wgjs k 0
677put wgjn 0 add k 1
678ret k
679end
680
681fn wgjws p ulong e ulong to ulong
682q = p
683while lt q e bound 999999
684c = get wga q
685if and and ne c 32 ne c 9 and ne c 10 ne c 13
686ret q
687end
688q = add q 1
689end
690ret q
691end
692
693fn wghex4 p ulong to ulong
694v = ulong 0
695for i ulong 4
696c = ulong get wga add p i
697d = WGNO
698if and ge c 48 le c 57
699d = sub c 48
700end
701if and ge c 97 le c 102
702d = sub c 87
703end
704if and ge c 65 le c 70
705d = sub c 55
706end
707if eq d WGNO
708ret WGNO
709end
710v = or shl v 4 d
711end
712ret v
713end
714
715fn wgenc v ulong to void
716if lt v 128
717wgac v
718ret
719end
720if lt v 2048
721wgac or 192 shr v 6
722wgac or 128 and v 63
723ret
724end
725wgac or 224 shr v 12
726wgac or 128 and shr v 6 63
727wgac or 128 and v 63
728end
729
730note one escape; q is the byte after the backslash. New position or WGNO.
731fn wgjesc q ulong e ulong to ulong
732if ge q e
733ret WGNO
734end
735d = ulong get wga q
736if ne d 117
737c = ulong 0
738if or or eq d 34 eq d 92 eq d 47
739c = d
740end
741if eq d 98
742c = 8
743end
744if eq d 102
745c = 12
746end
747if eq d 110
748c = 10
749end
750if eq d 114
751c = 13
752end
753if eq d 116
754c = 9
755end
756if eq c 0
757ret WGNO
758end
759wgac c
760ret add q 1
761end
762h = add q 1
763if ge add h 4 e
764ret WGNO
765end
766v = wghex4 h
767if eq v WGNO
768ret WGNO
769end
770if and ge v 55296 le v 57343
771wgdie wgtshp 79
772end
773wgenc v
774ret add h 4
775end
776
777note string body from p (after the quote); decoded into the arena top (wgr 3, wgr 4); returns the index after the closing quote
778fn wgjstr p ulong e ulong to ulong
779o = get wgan 0
780q = p
781while lt q e bound 999999
782c = ulong get wga q
783if eq c 34
784put wgr 3 o
785put wgr 4 sub get wgan 0 o
786ret add q 1
787end
788if lt c 32
789ret WGNO
790end
791if eq c 92
792q = wgjesc add q 1 e
793if eq q WGNO
794ret WGNO
795end
796else
797wgac c
798q = add q 1
799end
800end
801ret WGNO
802end
803
804fn wgdgs i ulong e ulong to ulong
805q = i
806while lt q e bound 999999
807if not wgdig ulong get wga q
808ret q
809end
810q = add q 1
811end
812ret q
813end
814
815note _match_number_unicode: returns the end index or WGNO
816fn wgjnum p ulong e ulong to ulong
817ed = sub e 1
818i = p
819if eq get wga i 45
820i = add i 1
821if gt i ed
822ret WGNO
823end
824end
825c = ulong get wga i
826if and ge c 49 le c 57
827i = wgdgs add i 1 e
828else
829if ne c 48
830ret WGNO
831end
832i = add i 1
833end
834nd = sub i p
835if eq get wga p 45
836nd = sub nd 1
837end
838isf = false
839if lt i ed
840if eq get wga i 46
841if wgdig ulong get wga add i 1
842isf = true
843i = wgdgs add i 2 e
844end
845end
846end
847if lt i ed
848c3 = get wga i
849if or eq c3 101 eq c3 69
850es = i
851i = add i 1
852if lt i ed
853c4 = get wga i
854if or eq c4 45 eq c4 43
855i = add i 1
856end
857end
858i = wgdgs i e
859if wgdig ulong get wga sub i 1
860isf = true
861else
862i = es
863end
864end
865end
866if not isf
867if gt nd 4300
868ret WGNO
869end
870end
871ret i
872end
873
874note literal t at p (all of its bytes must exist)
875fn wglit p ulong e ulong t view uchar * to bool
876if gt add p len t e
877ret false
878end
879ret wgsw p sub e p t
880end
881
882note attach node k to the open container (or make it the root)
883fn wgjatt k ulong to void
884d = get wgps 2
885if eq d 0
886put wgps 3 k
887ret
888end
889top = get wgks sub d 1
890last = get wgkl sub d 1
891if eq last 0
892put wgjc top k
893else
894put wgjs last k
895end
896put wgkl sub d 1 k
897put wgjo top add get wgjo top 1
898end
899
900text wgtnul "null"
901text wgttru "true"
902text wgtfal "false"
903
904note scalar value at p: returns the index after it or WGNO
905fn wgjscal p ulong e ulong to ulong
906c = get wga p
907if eq c 34
908q = wgjstr add p 1 e
909if ne q WGNO
910wgjatt wgjnew 5 get wgr 3 get wgr 4
911end
912ret q
913end
914if eq c 110
915if wglit p e wgtnul
916wgjatt wgjnew 1 0 0
917ret add p 4
918end
919end
920if eq c 116
921if wglit p e wgttru
922wgjatt wgjnew 3 0 0
923ret add p 4
924end
925end
926if eq c 102
927if wglit p e wgtfal
928wgjatt wgjnew 2 0 0
929ret add p 5
930end
931end
932if or eq c 78 eq c 73
933wgdie wgtshp 79
934end
935q2 = wgjnum p e
936if ne q2 WGNO
937wgjatt wgjnew 4 p sub q2 p
938end
939ret q2
940end
941
942note state 0: a value is expected at wgps 0. Returns 0 go on (state in wgps 4), 2 error
943fn wgjval to ulong
944p = get wgps 0
945e = get wgps 1
946if ge p e
947ret 2
948end
949c = get wga p
950if or eq c 123 eq c 91
951d = get wgps 2
952if ge d 512
953wgdie wgtrec 77
954end
955kd = ulong 6
956cl = uchar 93
957if eq c 123
958kd = 7
959cl = 125
960end
961k = wgjnew kd 0 0
962wgjatt k
963put wgks d k
964put wgkl d 0
965put wgps 2 add d 1
966p = wgjws add p 1 e
967put wgps 0 p
968if lt p e
969if eq get wga p cl
970put wgps 0 add p 1
971put wgps 2 d
972put wgps 4 1
973ret 0
974end
975end
976put wgps 4 0
977if eq kd 7
978put wgps 4 2
979end
980ret 0
981end
982q = wgjscal p e
983if eq q WGNO
984ret 2
985end
986put wgps 0 q
987put wgps 4 1
988ret 0
989end
990
991note state 1: after a value. Returns 0 go on, 1 done, 2 error
992fn wgjaft to ulong
993e = get wgps 1
994p = wgjws get wgps 0 e
995d = get wgps 2
996if eq d 0
997if ne p e
998ret 2
999end
1000ret 1
1001end
1002top = get wgks sub d 1
1003cl = uchar 93
1004if eq get wgjt top 7
1005cl = 125
1006end
1007if ge p e
1008ret 2
1009end
1010c = get wga p
1011if eq c cl
1012put wgps 0 add p 1
1013put wgps 2 sub d 1
1014ret 0
1015end
1016if ne c 44
1017ret 2
1018end
1019put wgps 0 wgjws add p 1 e
1020put wgps 4 0
1021if eq cl 125
1022put wgps 4 2
1023end
1024ret 0
1025end
1026
1027note state 2: an object key is expected. Returns 0 go on, 2 error
1028fn wgjkey to ulong
1029p = get wgps 0
1030e = get wgps 1
1031if ge p e
1032ret 2
1033end
1034if ne get wga p 34
1035ret 2
1036end
1037q = wgjstr add p 1 e
1038if eq q WGNO
1039ret 2
1040end
1041wgjatt wgjnew 5 get wgr 3 get wgr 4
1042q = wgjws q e
1043if ge q e
1044ret 2
1045end
1046if ne get wga q 58
1047ret 2
1048end
1049put wgps 0 wgjws add q 1 e
1050put wgps 4 0
1051ret 0
1052end
1053
1054note json.loads of [o, o + n): the root node, or WGNO
1055fn wgbom o ulong n ulong to bool
1056if lt n 3
1057ret false
1058end
1059if ne get wga o 239
1060ret false
1061end
1062if ne get wga add o 1 187
1063ret false
1064end
1065ret eq get wga add o 2 191
1066end
1067
1068fn wgjparse o ulong n ulong to ulong
1069e = add o n
1070if wgbom o n
1071ret WGNO
1072end
1073put wgps 0 wgjws o e
1074put wgps 1 e
1075put wgps 2 0
1076put wgps 3 0
1077put wgps 4 0
1078while true bound 64
1079while true bound 999999
1080st = get wgps 4
1081r = ulong 0
1082if eq st 0
1083r = wgjval
1084else
1085if eq st 1
1086r = wgjaft
1087else
1088r = wgjkey
1089end
1090end
1091if eq r 2
1092ret WGNO
1093end
1094if eq r 1
1095ret get wgps 3
1096end
1097end
1098end
1099ret WGNO
1100end
1101
1102note load the file named by wdp into the arena and parse it; exit 80 when it is not JSON
1103fn wgjfile to ulong
1104o = wgload
1105k = wgjparse o sub get wgan 0 o
1106if eq k WGNO
1107wgdiep wgtnoj 80
1108end
1109ret k
1110end
1111
1112note last value under key t in object k, or 0
1113fn wgjget k ulong t view uchar * to ulong
1114c = get wgjc k
1115r = ulong 0
1116while ne c 0 bound 999999
1117v = get wgjs c
1118if wgeqt get wgjo c get wgjl c t
1119r = v
1120end
1121c = get wgjs v
1122end
1123ret r
1124end
1125
1126note last value under the arena key (o, n), or 0
1127fn wgjgeta k ulong o ulong n ulong to ulong
1128c = get wgjc k
1129r = ulong 0
1130while ne c 0 bound 999999
1131v = get wgjs c
1132if wgeq2 get wgjo c get wgjl c o n
1133r = v
1134end
1135c = get wgjs v
1136end
1137ret r
1138end
1139
1140note an integer number node as long (exit 79 for any other node)
1141fn wgjint k ulong to long
1142if ne get wgjt k 4
1143wgdie wgtshp 79
1144end
1145o = get wgjo k
1146n = get wgjl k
1147ng = false
1148i = ulong 0
1149if eq get wga o 45
1150ng = true
1151i = 1
1152end
1153v = long 0
1154if gt sub n i 15
1155wgdie wgtshp 79
1156end
1157while lt i n bound 32
1158c = ulong get wga add o i
1159if not wgdig c
1160wgdie wgtshp 79
1161end
1162v = add mul v 10 long sub c 48
1163i = add i 1
1164end
1165if ng
1166ret neg v
1167end
1168ret v
1169end
1170
1171note the string under key t of object k: (wgr 3, wgr 4); exit 79 when absent or not a string
1172fn wgjsget k ulong t view uchar * to void
1173v = wgjget k t
1174if eq v 0
1175wgdie wgtshp 79
1176end
1177if ne get wgjt v 5
1178wgdie wgtshp 79
1179end
1180put wgr 3 get wgjo v
1181put wgr 4 get wgjl v
1182end
1183
1184note does the string under key t of object k equal text u (absent or non-string: false)
1185fn wgjis k ulong t view uchar * u view uchar * to bool
1186v = wgjget k t
1187if eq v 0
1188ret false
1189end
1190if ne get wgjt v 5
1191ret false
1192end
1193ret wgeqt get wgjo v get wgjl v u
1194end
1195
1196note number of distinct keys of object k
1197fn wgjnkey k ulong to ulong
1198c = get wgjc k
1199r = ulong 0
1200while ne c 0 bound 999999
1201v = get wgjs c
1202if eq wgjgeta k get wgjo c get wgjl c v
1203r = add r 1
1204end
1205c = get wgjs v
1206end
1207ret r
1208end
1209
1210note exit 79 unless k is an object whose values are all strings (the expected answers)
1211fn wgjflat k ulong to void
1212if ne get wgjt k 7
1213wgdie wgtshp 79
1214end
1215c = get wgjc k
1216while ne c 0 bound 999999
1217v = get wgjs c
1218if ne get wgjt v 5
1219wgdie wgtshp 79
1220end
1221c = get wgjs v
1222end
1223end
1224
1225note text of nodes a and b equal
1226fn wgjeqn a ulong b ulong to bool
1227ao = get wgjo a
1228an = get wgjl a
1229ret wgeq2 ao an get wgjo b get wgjl b
1230end
1231
1232note Python ==: model value d against flat expected object x
1233fn wgjeqx d ulong x ulong to bool
1234if ne get wgjt d 7
1235ret false
1236end
1237if ne wgjnkey d wgjnkey x
1238ret false
1239end
1240c = get wgjc x
1241while ne c 0 bound 999999
1242xv = wgjgeta x get wgjo c get wgjl c
1243dv = wgjgeta d get wgjo c get wgjl c
1244if eq dv 0
1245ret false
1246end
1247if ne get wgjt dv 5
1248ret false
1249end
1250if not wgjeqn dv xv
1251ret false
1252end
1253c = get wgjs get wgjs c
1254end
1255ret true
1256end
1257
1258note array k into wgdr (data rows) with a stride; returns the count
1259fn wgjrows k ulong st ulong to ulong
1260if ne get wgjt k 6
1261wgdie wgtshp 79
1262end
1263c = get wgjc k
1264i = ulong 0
1265m = ulong 0
1266while ne c 0 bound 999999
1267if eq rem i st 0
1268if ge m 1024
1269wgdie wgtfull 61
1270end
1271put wgdr m c
1272m = add m 1
1273end
1274i = add i 1
1275c = get wgjs c
1276end
1277ret m
1278end
1279
1280note array k into wgrr (recorded rows); returns the count
1281fn wgjrec k ulong to ulong
1282if ne get wgjt k 6
1283wgdie wgtshp 79
1284end
1285c = get wgjc k
1286m = ulong 0
1287while ne c 0 bound 999999
1288if ge m 1024
1289wgdie wgtfull 61
1290end
1291put wgrr m c
1292m = add m 1
1293c = get wgjs c
1294end
1295ret m
1296end
1297
1298note element i of array k, or 0
1299fn wgjat k ulong i ulong to ulong
1300c = get wgjc k
1301j = ulong 0
1302while ne c 0 bound 999999
1303if eq j i
1304ret c
1305end
1306j = add j 1
1307c = get wgjs c
1308end
1309ret 0
1310end
1311
1312note ---------------------------------------------------------------- paths, files, processes
1313
1314note append slot k / arena range / OUT/t to the path builder
1315fn wgpsl k ulong to void
1316o = wgso k
1317n = wgsn k
1318for j ulong n
1319wdpc ulong get wga add o j
1320end
1321end
1322
1323fn wgpar o ulong n ulong to void
1324for j ulong n
1325wdpc ulong get wga add o j
1326end
1327end
1328
1329fn wgpout t view uchar * to void
1330wdpclr
1331wgpsl SOUT
1332wdpc 47
1333wdpt t
1334end
1335
1336note the whole file named by wdp onto the arena top; returns its offset (exit 71 when unreadable)
1337fn wgload to ulong
1338fd = wdopen 0 0
1339if lt fd 0
1340wgdiep wgtfile 71
1341end
1342o = get wgan 0
1343fin = false
1344while not fin bound 999999
1345t = get wgan 0
1346if ge t WGMAXA
1347wgdie wgtfull 61
1348end
1349r = read fd wga t sub WGMAXA t
1350if lt r 0
1351wgdiep wgtfile 71
1352end
1353if eq r 0
1354fin = true
1355else
1356put wgan 0 add t ulong r
1357end
1358end
1359c = fclose fd
1360ret o
1361end
1362
1363fn wgwr fd int o ulong n ulong to void
1364t = ulong 0
1365while lt t n bound 999999
1366w = write fd wga add o t sub n t
1367if le w 0
1368wgdie wgthost 70
1369end
1370t = add t ulong w
1371end
1372end
1373
1374fn wgwrt fd int t view uchar * to void
1375w = write fd t 0 len t
1376if ne w long len t
1377wgdie wgthost 70
1378end
1379end
1380
1381note open wdp for writing: truncate (ap false) or append (ap true); exit 71 on failure
1382fn wgcreat ap bool to int
1383fl = int 577
1384if ap
1385fl = 1089
1386end
1387fd = wdopen fl 438
1388if lt fd 0
1389wgdiep wgtfile 71
1390end
1391ret fd
1392end
1393
1394note write [o, o + n) to the file wdp (Path.write_text / write_bytes)
1395fn wgwfile o ulong n ulong to void
1396fd = wgcreat false
1397wgwr fd o n
1398c = fclose fd
1399end
1400
1401fn wgisdir to bool
1402r = stat wdp 0 get wdpn 0 wgsb 0 128
1403if ne r 0
1404ret false
1405end
1406m = or ulong get wgsb 16 shl ulong get wgsb 17 8
1407ret eq and m 61440 16384
1408end
1409
1410fn wgexist to bool
1411r = stat wdp 0 get wdpn 0 wgsb 0 128
1412ret eq r 0
1413end
1414
1415note mkdir of the first n bytes of wdp, exist_ok
1416fn wgmk1 n ulong to void
1417r = makedir wdp 0 n 511
1418if eq r 0
1419ret
1420end
1421if ne r -17
1422wgdiep wgtfile 71
1423end
1424s = stat wdp 0 n wgsb 0 128
1425if ne s 0
1426wgdiep wgtfile 71
1427end
1428m = or ulong get wgsb 16 shl ulong get wgsb 17 8
1429if ne and m 61440 16384
1430wgdiep wgtfile 71
1431end
1432end
1433
1434note mkdir -p of the whole path builder (parents=True, exist_ok=True)
1435fn wgmkp to void
1436n = get wdpn 0
1437i = ulong 1
1438while lt i n bound 4096
1439if eq get wdp i 47
1440wgmk1 i
1441end
1442i = add i 1
1443end
1444if gt n 0
1445wgmk1 n
1446end
1447end
1448
1449note fork; the child changes to slot cw (WGNO: stay), takes fi/fo/fe as 0/1/2 when not negative and
1450note runs the packed list wdk with an empty environment. Returns the pid.
1451fn wgspawn fi int fo int fe int cw ulong to long
1452pn = wdkfin
1453pid = fork
1454if lt pid 0
1455wgdie wgthost 70
1456end
1457if eq pid 0
1458if ne cw WGNO
1459o = wgso cw
1460r = chdir wga o wgsn cw
1461if ne r 0
1462exit 127
1463end
1464end
1465if ge fi 0
1466d0 = dupfd fi 0 0
1467end
1468if ge fo 0
1469d1 = dupfd fo 1 0
1470end
1471if ge fe 0
1472d2 = dupfd fe 2 0
1473end
1474x = execprog wdk 0 pn
1475exit 127
1476end
1477ret pid
1478end
1479
1480fn wgstat to long
1481s = or ulong get wdst 0 shl ulong get wdst 1 8
1482if eq and s 127 0
1483ret long and shr s 8 255
1484end
1485ret neg long and s 127
1486end
1487
1488note wait for pid at most ns nanoseconds: its returncode (minus the signal), or WGTMO after a kill
1489fn wgreap pid long ns long to long
1490dl = add monons ns
1491while true bound 999
1492while true bound 999999
1493r = waitpid int pid wdst 0 4 1
1494if eq r pid
1495ret wgstat
1496end
1497if eq r 0
1498if gt monons dl
1499k = killpid int pid 9
1500r2 = waitpid int pid wdst 0 4 0
1501while eq r2 -4 bound 1000
1502r2 = waitpid int pid wdst 0 4 0
1503end
1504ret WGTMO
1505end
1506z = sleepns 200000
1507else
1508if ne r -4
1509wgdie wgthost 70
1510end
1511end
1512end
1513end
1514ret WGTMO
1515end
1516
1517fn wgopen to int
1518fd = wdopen 0 0
1519if lt fd 0
1520wgdiep wgtfile 71
1521end
1522ret fd
1523end
1524
1525fn wgdevn to int
1526wdpclr
1527wdpt wgtnull
1528fd = wdopen 1 0
1529if lt fd 0
1530wgdiep wgtfile 71
1531end
1532ret fd
1533end
1534
1535note omc with stdin from file OUT/build/si, stdout to OUT/build/so, stderr to OUT/build/se (fresh
1536note files); 10 s. Returns the returncode or WGTMO.
1537text wgtbld "build/"
1538fn wgomc si view uchar * so view uchar * se view uchar * to long
1539wgpout wgtbld
1540wdpt si
1541fi = wgopen
1542wgpout wgtbld
1543wdpt so
1544fo = wgcreat false
1545wgpout wgtbld
1546wdpt se
1547fe = wgcreat false
1548wdkclr
1549wdkt wgtomc
1550pid = wgspawn fi fo fe WGNO
1551r = wgreap pid 10000000000
1552c1 = fclose fi
1553c2 = fclose fo
1554c3 = fclose fe
1555ret r
1556end
1557
1558note load OUT/build/t onto the arena: offset in wgr 5, length in wgr 6
1559fn wgbload t view uchar * to void
1560wgpout wgtbld
1561wdpt t
1562o = wgload
1563put wgr 5 o
1564put wgr 6 sub get wgan 0 o
1565end
1566
1567note run the program named by slot SPL in OUT/fixtures, stdout to OUT/build/t, stderr /dev/null, 2 s
1568fn wgrunx t view uchar * to long
1569fe = wgdevn
1570wgpout wgtbld
1571wdpt t
1572fo = wgcreat false
1573wdkclr
1574wdpclr
1575wgpsl SPL
1576wdkp
1577pid = wgspawn -1 fo fe SFIX
1578r = wgreap pid 2000000000
1579c1 = fclose fo
1580c2 = fclose fe
1581ret r
1582end
1583
1584note ---------------------------------------------------------------- checker.py / check_behavior.py / repair.check_answer
1585
1586text wgtrcp "receipts/"
1587text wgtdom ".om"
1588text wgtomo "omc.out"
1589text wgtome "omc.err"
1590text wgtrun "run.out"
1591
1592note rename OUT/build/f to the path in slot SPL and chmod it 0700
1593fn wgplace f view uchar * to void
1594wdkclr
1595wgpout wgtbld
1596wdpt f
1597wdkp
1598wdpclr
1599wgpsl SPL
1600wdkp
1601wdrename
1602wdpclr
1603wgpsl SPL
1604r = chmod wdp 0 get wdpn 0 448
1605if ne r 0
1606wgdiep wgtfile 71
1607end
1608end
1609
1610note checker.execute(text, expected, stdout, label=slot SCL); compile_rc and run_rc into wgx 0, 1
1611fn wgexec o ulong n ulong ex long so ulong sn ulong to bool
1612put wgx 0 WGABS
1613put wgx 1 WGABS
1614if eq n 0
1615ret false
1616end
1617if not wglines o n 0
1618ret false
1619end
1620wgpout wgtrcp
1621wgpsl SCL
1622wdpt wgtdom
1623fd = wgcreat false
1624wgwr fd o n
1625wgwrt fd wgtnl
1626c = fclose fd
1627wgpout wgtrcp
1628wgpsl SCL
1629wdpt wgtdom
1630wgsetp SPL
1631r = wgomcp
1632if eq r WGTMO
1633ret false
1634end
1635if ne r 0
1636put wgx 0 r
1637ret false
1638end
1639wgpout wgtbld
1640wgpsl SCL
1641wgsetp SPL
1642wgplace wgtomo
1643q = wgrunx wgtrun
1644if eq q WGTMO
1645ret false
1646end
1647put wgx 0 0
1648put wgx 1 q
1649wgbload wgtrun
1650wgasc get wgr 5 get wgr 6
1651if ne q ex
1652ret false
1653end
1654ret wgeq2 get wgr 5 get wgr 6 so sn
1655end
1656
1657note omc with stdin from the file in slot SPL, stdout OUT/build/omc.out, stderr OUT/build/omc.err
1658fn wgomcp to long
1659wdpclr
1660wgpsl SPL
1661fi = wgopen
1662wgpout wgtbld
1663wdpt wgtomo
1664fo = wgcreat false
1665wgpout wgtbld
1666wdpt wgtome
1667fe = wgcreat false
1668wdkclr
1669wdkt wgtomc
1670pid = wgspawn fi fo fe WGNO
1671r = wgreap pid 10000000000
1672c1 = fclose fi
1673c2 = fclose fo
1674c3 = fclose fe
1675ret r
1676end
1677
1678text wgtxex "expected_exit"
1679text wgtxso "expected_stdout"
1680text wgtkind "kind"
1681text wgthelp "helper"
1682text wgtloop "loop"
1683text wgtinc "increment"
1684text wgtans "answer"
1685text wgtfinc "fn inc x int to int"
1686text wgtfmain "fn main to int"
1687text wgtrinc "ret inc int "
1688text wgtarg "-arg"
1689text wgtmend "fn main to int\nret inc int "
1690text wgtend "\nend"
1691
1692note checker.check(raw, row, label=slot SCB); compile_rc/run_rc into wgxr 0, 1
1693fn wgcheck ro ulong rn ulong row ulong to bool
1694put wgxr 0 WGABS
1695put wgxr 1 WGABS
1696wgtext ro rn
1697tx = get wgr 0
1698tn = get wgr 1
1699xe = wgjget row wgtxex
1700if eq xe 0
1701ret wgprior tx tn row
1702end
1703hp = wgjis row wgtkind wgthelp
1704if hp
1705if or ne wgcntt tx tn wgtfinc 1 ne wgcntt tx tn wgtfmain 1
1706ret false
1707end
1708if eq wgfindt tx tn wgtrinc WGNO
1709ret false
1710end
1711end
1712if wgjis row wgtkind wgtloop
1713if not wglines tx tn 2
1714ret false
1715end
1716end
1717ex = wgjint xe
1718so = ulong 0
1719sn = ulong 0
1720xs = wgjget row wgtxso
1721if ne xs 0
1722if ne get wgjt xs 5
1723wgdie wgtshp 79
1724end
1725so = get wgjo xs
1726sn = get wgjl xs
1727end
1728o = get wgan 0
1729wgasl SCB
1730wgsetf SCL o
1731ok = wgexec tx tn ex so sn
1732put wgxr 0 get wgx 0
1733put wgxr 1 get wgx 1
1734if and ok hp
1735ret wghelp tx tn row
1736end
1737ret ok
1738end
1739
1740note the three additional inputs of a helper row (every one runs, as the list comprehension does)
1741fn wghelp tx ulong tn ulong row ulong to bool
1742inc = wgjint wgjget row wgtinc
1743k = wgfindt tx tn wgtfmain
1744alp = true
1745a = long 0
1746while le a 10 bound 4
1747po = get wgan 0
1748wgacp tx k
1749wgat wgtmend
1750wgadl a
1751wgat wgtend
1752pn = sub get wgan 0 po
1753o = get wgan 0
1754wgasl SCB
1755wgat wgtarg
1756wgadl a
1757wgsetf SCL o
1758if not wgexec po pn add a inc 0 0
1759alp = false
1760end
1761a = add a 5
1762end
1763ret alp
1764end
1765
1766text wgtread "read"
1767text wgtlist "list"
1768text wgtchk "check"
1769
1770note check_behavior.check for rows without expected_exit
1771fn wgprior tx ulong tn ulong row ulong to bool
1772if or or wgjis row wgtkind wgtread wgjis row wgtkind wgtlist wgjis row wgtkind wgtchk
1773ret wgdisp tx tn row
1774end
1775wgjsget row wgtans
1776ret wgeq2 tx tn get wgr 3 get wgr 4
1777end
1778
1779text wgttool "tool"
1780text wgtpath "path"
1781text wgtrdf "read_file"
1782text wgtlsf "list_files"
1783text wgtomck "omega_check"
1784text wgtfixc "fixture contents\n"
1785text wgtone "/one.txt"
1786text wgtonev "one"
1787text wgtprog "fn main to int\nret 0\nend\n"
1788text wgtfix "fixtures"
1789
1790note check_behavior.dispatch, including its fixture side effects
1791fn wgdisp tx ulong tn ulong row ulong to bool
1792mk = get wgjn 0
1793d = wgjparse tx tn
1794if eq d WGNO
1795ret false
1796end
1797wgjsget row wgtans
1798x = wgjparse get wgr 3 get wgr 4
1799if eq x WGNO
1800wgdie wgtnoj 80
1801end
1802wgjflat x
1803if not wgjeqx d x
1804put wgjn 0 mk
1805ret false
1806end
1807wgjsget x wgtpath
1808po = get wgr 3
1809pn = get wgr 4
1810wdpclr
1811if or eq pn 0 ne get wga po 47
1812wgpsl SOUT
1813wdpc 47
1814wdpt wgtfix
1815wdpc 47
1816end
1817wgpar po pn
1818wgsetp SPL
1819sl = WGNO
1820i = ulong 0
1821while lt i get wdpn 0 bound 4096
1822if eq get wdp i 47
1823sl = i
1824end
1825i = add i 1
1826end
1827if ne sl WGNO
1828put wdpn 0 sl
1829wgmkp
1830end
1831if wgjis x wgttool wgtrdf
1832wdpclr
1833wgpsl SPL
1834fd = wgcreat false
1835wgwrt fd wgtfixc
1836c = fclose fd
1837o = wgload
1838put wgjn 0 mk
1839ret true
1840end
1841if wgjis x wgttool wgtlsf
1842wdpclr
1843wgpsl SPL
1844wgmk1 get wdpn 0
1845wdpt wgtone
1846fd2 = wgcreat false
1847wgwrt fd2 wgtonev
1848c2 = fclose fd2
1849put wgjn 0 mk
1850ret true
1851end
1852if wgjis x wgttool wgtomck
1853wdpclr
1854wgpsl SPL
1855fd3 = wgcreat false
1856wgwrt fd3 wgtprog
1857c3 = fclose fd3
1858r = wgomcp
1859if eq r WGTMO
1860wgdie wgtcmdt 74
1861end
1862if ne r 0
1863wgdie wgtcmdf 73
1864end
1865put wgjn 0 mk
1866ret true
1867end
1868wgdie wgtshp 79
1869ret false
1870end
1871
1872note repair.check_answer
1873fn wgfirst ro ulong rn ulong row ulong to bool
1874wgtext ro rn
1875tx = get wgr 0
1876tn = get wgr 1
1877mk = get wgjn 0
1878wgjsget row wgtans
1879ao = get wgr 3
1880an = get wgr 4
1881d = wgjparse tx tn
1882if eq d WGNO
1883ret wgeq2 tx tn ao an
1884end
1885x = wgjparse ao an
1886if eq x WGNO
1887ret wgeq2 tx tn ao an
1888end
1889wgjflat x
1890r = wgjeqx d x
1891put wgjn 0 mk
1892ret r
1893end
1894text wgy00 "Repair this Omega file and verify it."
1895text wgy01 "Use tools to fix this Omega program, then test it."
1896text wgy02 "Check this Omega file, correct any fault and confirm the result."
1897text wgy03 "Please get this Omega file working according to its goal and check your work."
1898text wgy04 "Investigate this Omega file and make its behavior match the goal."
1899text wgy05 "Diagnose this Omega file, repair it as needed, and verify the result."
1900text wgy06 "Repair the calculation in this Omega file and verify the result."
1901text wgy07 "Find and repair the mistake in this Omega file, then confirm its behavior."
1902text wgy08 "Make this Omega file satisfy its stated goal and verify the repaired result."
1903text wgy09 "Fix this Omega file."
1904text wgy10 "Check and repair the Omega program."
1905text wgy11 "Make the program match its goal and test it."
1906text wgy12 "Use tools to repair the file and check it."
1907text wgy13 "Find the wrong calculation, fix it, and test it."
1908text wgy14 "Inspect this program and fix the error."
1909text wgy15 "Read the file, check it, repair it, and test again."
1910text wgy16 "Please correct the Omega calculation and verify it."
1911text wgy17 "Repair this file to meet the stated goal."
1912text wgy18 "Work through this Omega repair and check the result."
1913text wgy19 "Check this Omega file, find the error, repair it and verify the result."
1914text wgy20 "Please inspect this Omega program to repair the calculation and verify the result."
1915text wgy21 "Use the goal to fix this Omega file and verify the changes."
1916text wgy22 "Please repair this Omega program to do what the goal asks."
1917text wgy23 "Get this Omega file to match the goal, then check the result."
1918text wgy24 "Please carefully repair the calculation using tools and confirm that the tests pass."
1919text wgy25 "Please carefully examine this Omega file and repair any calculation that does not match its goal."
1920text wgy26 "Find the incorrect behavior in this Omega file, fix it, and test the result."
1921text wgy27 "Inspect and repair this Omega file, then verify it."
1922text wgy28 "Correct this Omega program according to its goal."
1923text wgy29 "Fix the error in this Omega program and check the result."
1924text wgy30 "Check this file and repair it to meet its goal."
1925text wgy31 "Please fix this program to match its goal."
1926text wgy32 "Correct the calculation in this Omega file."
1927text wgy33 "Read this program and repair its calculation."
1928text wgy34 "Please check the code and fix the mistake."
1929text wgy35 "Repair the program according to the stated goal."
1930text wgy36 "Use the goal to correct this Omega calculation."
1931text wgy37 "Fix the calculation and test the corrected program."
1932text wgy38 "Please inspect the file and correct the error."
1933text wgy39 "Check the calculation, make the repair, and verify it."
1934text wgy40 "Make this file behave as the goal describes."
1935text wgy41 "Please correct this program and check your work."
1936text wgy42 "Repair this calculation, then confirm the result."
1937text wgy43 "Repair this file and confirm it meets the goal."
1938text wgy44 "Check the Omega program and correct its calculation."
1939text wgy45 "Inspect this file, fix its calculation, and verify it."
1940text wgy46 "Make this Omega program meet the goal, then test it."
1941text wgy47 "Repair the file and verify its goal."
1942text wgy48 "Check the code, repair its fault, and test it."
1943text wgy49 "Fix the error in this file and confirm its goal."
1944text wgy50 "Inspect the code and repair it to satisfy the goal."
1945
1946note STYLES[i] onto the arena (repair.STYLES, 51 entries, copied mechanically)
1947fn wgsty i ulong to void
1948if eq i 0
1949wgat wgy00
1950ret
1951end
1952if eq i 1
1953wgat wgy01
1954ret
1955end
1956if eq i 2
1957wgat wgy02
1958ret
1959end
1960if eq i 3
1961wgat wgy03
1962ret
1963end
1964if eq i 4
1965wgat wgy04
1966ret
1967end
1968if eq i 5
1969wgat wgy05
1970ret
1971end
1972if eq i 6
1973wgat wgy06
1974ret
1975end
1976if eq i 7
1977wgat wgy07
1978ret
1979end
1980if eq i 8
1981wgat wgy08
1982ret
1983end
1984if eq i 9
1985wgat wgy09
1986ret
1987end
1988if eq i 10
1989wgat wgy10
1990ret
1991end
1992if eq i 11
1993wgat wgy11
1994ret
1995end
1996if eq i 12
1997wgat wgy12
1998ret
1999end
2000if eq i 13
2001wgat wgy13
2002ret
2003end
2004if eq i 14
2005wgat wgy14
2006ret
2007end
2008if eq i 15
2009wgat wgy15
2010ret
2011end
2012if eq i 16
2013wgat wgy16
2014ret
2015end
2016if eq i 17
2017wgat wgy17
2018ret
2019end
2020if eq i 18
2021wgat wgy18
2022ret
2023end
2024if eq i 19
2025wgat wgy19
2026ret
2027end
2028if eq i 20
2029wgat wgy20
2030ret
2031end
2032if eq i 21
2033wgat wgy21
2034ret
2035end
2036if eq i 22
2037wgat wgy22
2038ret
2039end
2040if eq i 23
2041wgat wgy23
2042ret
2043end
2044if eq i 24
2045wgat wgy24
2046ret
2047end
2048if eq i 25
2049wgat wgy25
2050ret
2051end
2052if eq i 26
2053wgat wgy26
2054ret
2055end
2056if eq i 27
2057wgat wgy27
2058ret
2059end
2060if eq i 28
2061wgat wgy28
2062ret
2063end
2064if eq i 29
2065wgat wgy29
2066ret
2067end
2068if eq i 30
2069wgat wgy30
2070ret
2071end
2072if eq i 31
2073wgat wgy31
2074ret
2075end
2076if eq i 32
2077wgat wgy32
2078ret
2079end
2080if eq i 33
2081wgat wgy33
2082ret
2083end
2084if eq i 34
2085wgat wgy34
2086ret
2087end
2088if eq i 35
2089wgat wgy35
2090ret
2091end
2092if eq i 36
2093wgat wgy36
2094ret
2095end
2096if eq i 37
2097wgat wgy37
2098ret
2099end
2100if eq i 38
2101wgat wgy38
2102ret
2103end
2104if eq i 39
2105wgat wgy39
2106ret
2107end
2108if eq i 40
2109wgat wgy40
2110ret
2111end
2112if eq i 41
2113wgat wgy41
2114ret
2115end
2116if eq i 42
2117wgat wgy42
2118ret
2119end
2120if eq i 43
2121wgat wgy43
2122ret
2123end
2124if eq i 44
2125wgat wgy44
2126ret
2127end
2128if eq i 45
2129wgat wgy45
2130ret
2131end
2132if eq i 46
2133wgat wgy46
2134ret
2135end
2136if eq i 47
2137wgat wgy47
2138ret
2139end
2140if eq i 48
2141wgat wgy48
2142ret
2143end
2144if eq i 49
2145wgat wgy49
2146ret
2147end
2148if eq i 50
2149wgat wgy50
2150ret
2151end
2152wgdie wgtshp 79
2153end
2154
2155fn wgb b bool to uchar
2156if b
2157ret 1
2158end
2159ret 0
2160end
2161
2162note ---------------------------------------------------------------- repair.jobs_run
2163note job states: 1 unread, 2 read, 3 missing, 4 checked, 5 failed, 6 edited
2164
2165text wgts1 "unread"
2166text wgts2 "read"
2167text wgts3 "missing"
2168text wgts4 "checked"
2169text wgts5 "failed"
2170text wgts6 "edited"
2171
2172fn wgstn s ulong to void
2173if eq s 1
2174wgat wgts1
2175end
2176if eq s 2
2177wgat wgts2
2178end
2179if eq s 3
2180wgat wgts3
2181end
2182if eq s 4
2183wgat wgts4
2184end
2185if eq s 5
2186wgat wgts5
2187end
2188if eq s 6
2189wgat wgts6
2190end
2191end
2192
2193note state name of s equals the arena text (o, n)
2194fn wgsteq s ulong o ulong n ulong to bool
2195m = get wgan 0
2196wgstn s
2197r = wgeq2 m sub get wgan 0 m o n
2198put wgan 0 m
2199ret r
2200end
2201
2202text wgtid "id"
2203text wgtstyl "style"
2204text wgtfault "fault"
2205text wgtbrok "broken"
2206text wgtka "a"
2207text wgtkk "k"
2208text wgtkn "n"
2209text wgtadd "add"
2210text wgtmul "mul"
2211
2212fn wgjv ji ulong t view uchar * to long
2213ret wgjint wgjget get wgdr ji t
2214end
2215
2216note OUT/fixtures/JL/id/program.om into wdp (dir only when pf is false)
2217text wgtfixs "/fixtures/"
2218text wgtprg "/program.om"
2219fn wgpjob ji ulong pf bool to void
2220wdpclr
2221wgpsl SOUT
2222wdpt wgtfixs
2223wgpsl SJL
2224wdpc 47
2225wgjsget get wgdr ji wgtid
2226wgpar get wgr 3 get wgr 4
2227if pf
2228wdpt wgtprg
2229end
2230end
2231
2232text wgtg1 "calc starts with x and adds "
2233text wgtg2 " exactly "
2234text wgtg3 " times in a for loop. main calls calc with "
2235text wgtg4 "calc returns x "
2236text wgtplus "plus "
2237text wgttimes "times "
2238text wgtg5 ". main calls calc with "
2239text wgtp1 "Task: "
2240text wgtp2 "\nFile: "
2241text wgtp3 "\nGoal: "
2242text wgtp4 "\nState: "
2243text wgtp5 "Source:\n"
2244text wgtp6 "Tool result: "
2245text wgtp7 "Answer:\n"
2246text wgtdot "."
2247
2248fn wggoal ji ulong to void
2249j = get wgdr ji
2250if wgjis j wgtkind wgtloop
2251wgat wgtg1
2252wgadl wgjv ji wgtkk
2253wgat wgtg2
2254wgadl wgjv ji wgtkn
2255wgat wgtg3
2256wgadl wgjv ji wgtka
2257wgat wgtdot
2258ret
2259end
2260wgat wgtg4
2261if wgjis j wgtkind wgtadd
2262wgat wgtplus
2263else
2264wgat wgttimes
2265end
2266wgadl wgjv ji wgtkk
2267wgat wgtg5
2268wgadl wgjv ji wgtka
2269wgat wgtdot
2270end
2271
2272note repair.prompt for job ji in its current state, onto the arena; returns the offset
2273fn wgprm ji ulong to ulong
2274j = get wgdr ji
2275o = get wgan 0
2276wgat wgtp1
2277st = wgjv ji wgtstyl
2278if or lt st 0 gt st 50
2279wgdie wgtshp 79
2280end
2281wgsty ulong st
2282wgat wgtp2
2283wgjsget j wgtpath
2284wgacp get wgr 3 get wgr 4
2285wgat wgtp3
2286wggoal ji
2287wgat wgtp4
2288wgstn ulong get wgjst ji
2289wgat wgtnl
2290if gt get wgjsn ji 0
2291wgat wgtp5
2292wgacp get wgjso ji get wgjsn ji
2293end
2294if gt get wgjon ji 0
2295wgat wgtp6
2296wgacp get wgjoo ji get wgjon ji
2297wgat wgtnl
2298end
2299wgat wgtp7
2300ret o
2301end
2302
2303fn wgobs ji ulong t view uchar * to void
2304o = get wgan 0
2305wgat t
2306put wgjoo ji o
2307put wgjon ji len t
2308end
2309
2310text wgtrok "Read succeeded."
2311text wgtfnf "File not found."
2312text wgttp "Tests passed."
2313text wgtes "Edit saved."
2314text wgtref "Refused unsupported source."
2315text wgtrfm "Required functions missing."
2316text wgtmpi "main must preserve the requested input."
2317text wgtrlm "Required loop missing."
2318text wgtfci "fn calc x int to int"
2319text wgtrci "ret calc int "
2320text wgtfiu "for i ulong "
2321text wgttf1 "Test failed: calc("
2322text wgttf2 ") expected "
2323text wgttf3 ", got "
2324text wgtcto "ct.om"
2325text wgtcte "ct.err"
2326text wgtctr "ct.run"
2327text wgtchk2 "check-"
2328
2329note Path.read_text() of the file named by wdp: ASCII (exit 72 otherwise), universal newlines
2330fn wgrtext to ulong
2331o = wgload
2332n = sub get wgan 0 o
2333wgasc o n
2334i = ulong 0
2335w = ulong 0
2336while lt i n bound 999999
2337c = get wga add o i
2338if eq c 13
2339c = 10
2340if lt add i 1 n
2341if eq get wga add o add i 1 10
2342i = add i 1
2343end
2344end
2345end
2346put wga add o w c
2347w = add w 1
2348i = add i 1
2349end
2350put wgan 0 add o w
2351ret o
2352end
2353
2354note the main-preserve check: the stripped lines starting with "ret calc int " are exactly one, "ret calc int {a}"
2355fn wgmainok so ulong sn ulong a long to bool
2356wgstrip so sn
2357p = get wgr 0
2358e = add p get wgr 1
2359want = get wgan 0
2360wgat wgtrci
2361wgadl a
2362wn = sub get wgan 0 want
2363cnt = ulong 0
2364ok = false
2365while lt p e bound 999999
2366q = wgeol p e
2367nx = get wgr 2
2368if wgsw p sub q p wgtrci
2369cnt = add cnt 1
2370ok = wgeq2 p sub q p want wn
2371end
2372p = nx
2373end
2374put wgan 0 want
2375ret and eq cnt 1 ok
2376end
2377
2378note expected(j, x)
2379fn wgwant ji ulong x long to long
2380j = get wgdr ji
2381k = wgjv ji wgtkk
2382if wgjis j wgtkind wgtadd
2383ret add x k
2384end
2385if wgjis j wgtkind wgtmul
2386ret mul x k
2387end
2388ret add x mul k wgjv ji wgtkn
2389end
2390
2391note the stripped lines of [so, so + sn) all match repair.PATTERNS
2392fn wgrgram so ulong sn ulong to bool
2393wgstrip so sn
2394ret wglines get wgr 0 get wgr 1 1
2395end
2396
2397note observation = stripped omc stderr (OUT/build/ct.err); ASCII or exit 72
2398fn wgcterr ji ulong to void
2399wgbload wgtcte
2400wgasc get wgr 5 get wgr 6
2401wgstrip get wgr 5 get wgr 6
2402put wgjoo ji get wgr 0
2403put wgjon ji get wgr 1
2404end
2405
2406note one test of compile_test: 0 pass, 1 fail (observation set)
2407fn wgct1 so ulong sn ulong ji ulong a long to ulong
2408co = get wgan 0
2409i = ulong 0
2410while lt i sn bound 999999
2411if wgsw add so i sub sn i wgtrci
2412d = add i 13
2413if lt d sn
2414if wgdig ulong get wga add so d
2415wgat wgtrci
2416wgadl a
2417d = add d 1
2418if lt d sn
2419if wgdig ulong get wga add so d
2420d = add d 1
2421end
2422end
2423i = d
2424continue
2425end
2426end
2427end
2428wgac ulong get wga add so i
2429i = add i 1
2430end
2431cn = sub get wgan 0 co
2432wgpout wgtbld
2433wdpt wgtcto
2434wgwfile co cn
2435r = wgomc wgtcto wgtomo wgtcte
2436if eq r WGTMO
2437wgdie wgtctt 76
2438end
2439if ne r 0
2440wgcterr ji
2441ret 1
2442end
2443wgpout wgtbld
2444wdpt wgtchk2
2445wghash a
2446wgsetp SPL
2447wgplace wgtomo
2448v = wgrunx wgtctr
2449if eq v WGTMO
2450wgdie wgtctt 76
2451end
2452ret wgct2 ji a v
2453end
2454
2455note compile_test tail: read the run output, compare with the wanted value
2456fn wgct2 ji ulong a long v long to ulong
2457wdpclr
2458wgpsl SPL
2459u = unlink wdp 0 get wdpn 0
2460wgbload wgtctr
2461so2 = get wgr 5
2462sn2 = get wgr 6
2463wgasc so2 sn2
2464want = wgwant ji a
2465if or ne v want gt sn2 0
2466o = get wgan 0
2467wgat wgttf1
2468wgadl a
2469wgat wgttf2
2470wgadl want
2471wgat wgttf3
2472wgadl v
2473wgat wgtdot
2474put wgjoo ji o
2475put wgjon ji sub get wgan 0 o
2476ret 1
2477end
2478ret 0
2479end
2480
2481note sha256(slot SCT + str(a)) hex[:20] onto wdp
2482fn wghash a long to void
2483b = new uchar 4096 0
2484h = new uchar 32 0
2485o = get wgan 0
2486wgasl SCT
2487wgadl a
2488n = sub get wgan 0 o
2489if gt n 4096
2490wgdie wgtfull 61
2491end
2492for i ulong n
2493put b i get wga add o i
2494end
2495put wgan 0 o
2496sha256_hash part b 0 n h
2497for k ulong 10
2498v = ulong get h k
2499wdpc ulong get wdhex shr v 4
2500wdpc ulong get wdhex and v 15
2501end
2502end
2503
2504note repair.compile_test(src, j, label=slot SCT): 0 ok, 1 not ok; observation into the job's obs
2505fn wgct so ulong sn ulong ji ulong to ulong
2506j = get wgdr ji
2507g = and gt sn 0 le sn 600
2508if g
2509g = wgrgram so sn
2510end
2511if not g
2512wgjsget j wgtbrok
2513if not wgeq2 so sn get wgr 3 get wgr 4
2514wgobs ji wgtref
2515ret 1
2516end
2517end
2518wgpout wgtbld
2519wdpt wgtcto
2520wgwfile so sn
2521r = wgomc wgtcto wgtomo wgtcte
2522if eq r WGTMO
2523wgdie wgtctt 76
2524end
2525if ne r 0
2526wgcterr ji
2527ret 1
2528end
2529if not wgrgram so sn
2530wgobs ji wgtref
2531ret 1
2532end
2533if or ne wgcntt so sn wgtfci 1 ne wgcntt so sn wgtfmain 1
2534wgobs ji wgtrfm
2535ret 1
2536end
2537a0 = wgjv ji wgtka
2538if not wgmainok so sn a0
2539wgobs ji wgtmpi
2540ret 1
2541end
2542if wgjis j wgtkind wgtloop
2543if eq wgfindt so sn wgtfiu WGNO
2544wgobs ji wgtrlm
2545ret 1
2546end
2547end
2548if ne wgct1 so sn ji a0 0
2549ret 1
2550end
2551for t ulong 3
2552av = wgtav t
2553if ne av a0
2554if ne wgct1 so sn ji av 0
2555ret 1
2556end
2557end
2558end
2559wgobs ji wgttp
2560ret 0
2561end
2562
2563note the dedup order [a, 0, 3, 7]: test t of 0, 3, 7
2564fn wgtav t ulong to long
2565if eq t 0
2566ret 0
2567end
2568if eq t 1
2569ret 3
2570end
2571ret 7
2572end
2573
2574text wgtold "old"
2575text wgtnew "new"
2576text wgtrpl "replace_text"
2577
2578note repair.patch: the fixed source onto the arena (wgr 5, wgr 6), or false (ValueError)
2579fn wgpatch ji ulong d ulong to bool
2580if ne wgjnkey d 4
2581ret false
2582end
2583ov = wgjget d wgtold
2584nv = wgjget d wgtnew
2585if or eq ov 0 eq nv 0
2586ret false
2587end
2588if or ne get wgjt ov 5 ne get wgjt nv 5
2589ret false
2590end
2591oo = get wgjo ov
2592onn = get wgjl ov
2593if or eq onn 0 or gt wgcpl oo onn 40 gt wgcpl get wgjo nv get wgjl nv 40
2594ret false
2595end
2596so = get wgjso ji
2597sn = get wgjsn ji
2598if ne wgcnt so sn oo onn 1
2599ret false
2600end
2601i = wgfind so sn oo onn
2602r = get wgan 0
2603wgacp so i
2604wgacp get wgjo nv get wgjl nv
2605wgacp add so add i onn sub sn add i onn
2606rn = sub get wgan 0 r
2607if not wgrgram r rn
2608ret false
2609end
2610put wgr 5 r
2611put wgr 6 rn
2612ret true
2613end
2614
2615note code points of UTF-8 text (bytes that are not continuation bytes)
2616fn wgcpl o ulong n ulong to ulong
2617c = ulong 0
2618for i ulong n
2619if ne and get wga add o i 192 128
2620c = add c 1
2621end
2622end
2623ret c
2624end
2625
2626note one action; 0 ok, 1 error (ValueError/TypeError/KeyError)
2627fn wgact1 ji ulong d ulong t ulong to ulong
2628if eq d WGNO
2629ret 1
2630end
2631if ne get wgjt d 7
2632ret 1
2633end
2634j = get wgdr ji
2635pv = wgjget d wgtpath
2636if eq pv 0
2637ret 1
2638end
2639if ne get wgjt pv 5
2640ret 1
2641end
2642wgjsget j wgtpath
2643if not wgeq2 get wgjo pv get wgjl pv get wgr 3 get wgr 4
2644ret 1
2645end
2646st = get wgjst ji
2647nk = wgjnkey d
2648if and and eq nk 2 eq st 1 wgjis d wgttool wgtrdf
2649ret wgactr ji
2650end
2651if and and eq nk 2 or eq st 2 eq st 6 wgjis d wgttool wgtomck
2652ret wgactc ji t
2653end
2654if and eq st 5 wgjis d wgttool wgtrpl
2655ret wgactp ji d
2656end
2657ret 1
2658end
2659
2660note read_file action
2661fn wgactr ji ulong to ulong
2662wgpjob ji true
2663if wgexist
2664o = wgrtext
2665put wgjso ji o
2666put wgjsn ji sub get wgan 0 o
2667put wgjst ji 2
2668wgobs ji wgtrok
2669else
2670put wgjst ji 3
2671wgobs ji wgtfnf
2672end
2673ret 0
2674end
2675
2676note omc_check action
2677fn wgactc ji ulong t ulong to ulong
2678wgpjob ji true
2679o2 = wgrtext
2680n2 = sub get wgan 0 o2
2681o3 = get wgan 0
2682wgasl SJL
2683wgjsget get wgdr ji wgtid
2684wgacp get wgr 3 get wgr 4
2685wgad t
2686wgsetf SCT o3
2687v = wgct o2 n2 ji
2688wgactt ji t v
2689ret 0
2690end
2691
2692note record the compile_test outcome of job ji at turn t
2693fn wgactt ji ulong t ulong v ulong to void
2694k = add mul ji 7 t
2695put wgtth k uchar sub 2 v
2696put wgtto k get wgjoo ji
2697put wgttn k get wgjon ji
2698put wgjst ji uchar add 4 v
2699put wgjvf ji wgb eq v 0
2700put wgjhv ji 1
2701end
2702
2703note replace action
2704fn wgactp ji ulong d ulong to ulong
2705if not wgpatch ji d
2706ret 1
2707end
2708fo = get wgr 5
2709fn2 = get wgr 6
2710wgpjob ji true
2711wgwfile fo fn2
2712put wgjst ji 6
2713put wgjso ji fo
2714put wgjsn ji fn2
2715wgobs ji wgtes
2716put wgjvf ji 0
2717put wgjhv ji 1
2718ret 0
2719end
2720
2721note one answer for job ji at turn t
2722fn wgstep ji ulong ro ulong rn ulong t ulong to void
2723wgasc ro rn
2724wgturn ji ro rn t
2725wgtext ro rn
2726so = get wgr 0
2727sn = get wgr 1
2728if wgeqt so sn wgttp
2729wgjtp ji
2730ret
2731end
2732if wgeqt so sn wgtfnf
2733put wgjps ji wgb eq get wgjst ji 3
2734put wgjdn ji 1
2735ret
2736end
2737wgstp2 ji so sn t
2738end
2739
2740note record turn t of job ji (raw answer and state)
2741fn wgturn ji ulong ro ulong rn ulong t ulong to void
2742k = add mul ji 7 t
2743put wgtro k ro
2744put wgtrl k rn
2745put wgtst k get wgjst ji
2746put wgtth k 0
2747put wgjtn ji add t 1
2748end
2749
2750note TASK_PASSED: pass iff state is verified-done with a passing verification
2751fn wgjtp ji ulong to void
2752st = get wgjst ji
2753hv = eq get wgjhv ji 1
2754put wgjps ji wgb and eq st 4 and hv eq get wgjvf ji 1
2755put wgjdn ji 1
2756end
2757
2758note any other answer: parse and act
2759fn wgstp2 ji ulong so ulong sn ulong t ulong to void
2760mk = get wgjn 0
2761d = wgjparse so sn
2762r = wgact1 ji d t
2763put wgjn 0 mk
2764if ne r 0
2765put wgjdn ji 1
2766put wgjer ji 1
2767end
2768end
2769
2770note set up nj jobs (wgdr) under label slot SJL: fixtures and initial state
2771fn wgjinit nj ulong to void
2772for i ulong nj
2773wgpjob i false
2774wgmkp
2775wgjzero i
2776wgjzer2 i
2777j = get wgdr i
2778if not wgjis j wgtfault wgts3
2779wgpjob i true
2780wgjsget j wgtbrok
2781wgwfile get wgr 3 get wgr 4
2782end
2783end
2784end
2785
2786text wgtturn "-turn"
2787
2788note jobs_run over nj jobs; answers come from wgsamp
2789fn wgjobs nj ulong to void
2790wgjinit nj
2791for t ulong 7
2792na = ulong 0
2793for i ulong nj
2794if eq get wgjdn i 0
2795put wgact na i
2796put wgpo na wgprm i
2797put wgpl na sub get wgan 0 get wgpo na
2798na = add na 1
2799end
2800end
2801if eq na 0
2802break
2803end
2804o = get wgan 0
2805wgasl SJL
2806wgat wgtturn
2807wgad t
2808wgsetf SLAB o
2809put wgmd 1 t
2810wgsamp na
2811for q ulong na
2812wgstep get wgact q get wgao q get wgal q t
2813end
2814end
2815end
2816
2817fn wgjzero i ulong to void
2818put wgjst i 1
2819put wgjso i 0
2820put wgjsn i 0
2821put wgjoo i 0
2822put wgjon i 0
2823put wgjdn i 0
2824end
2825
2826fn wgjzer2 i ulong to void
2827put wgjps i 0
2828put wgjvf i 0
2829put wgjhv i 0
2830put wgjer i 0
2831put wgjtn i 0
2832end
2833
2834note ---------------------------------------------------------------- lib.run / sample / score
2835note wgmd: 0 mode (1 live, 2 replay, 3 replaylog), 1 current turn, 2 kind (0 probe, 1 first, 2 jobs)
2836
2837text wgtrcps "/receipts/"
2838text wgtlog ".log"
2839text wgtcmds "/commands.txt"
2840text wgtrcw " rc="
2841text wgtwin " window="
2842text wgtargv " argv"
2843text wgtdats "/data/s"
2844text wgtdats2 "/data/s/"
2845text wgtbin ".bin"
2846text wgttok ".tok"
2847text wgtenc "-encode"
2848text wgtsmp "-sample"
2849text wgtbat "-batch"
2850text wgtbpe "bpeenc"
2851text wgt4096 "4096"
2852text wgt160 "160"
2853text wgtgev2 "geval"
2854text wgt256 "256"
2855text wgtraw "raw_output"
2856text wgtturns "turns"
2857text wgtprom "prompt"
2858text wgtrawk "raw"
2859text wgtstk "state"
2860
2861note the packed argv list wdk joined by spaces onto the arena
2862fn wgkargs to void
2863c = get wdkn 0
2864p = ulong 2
2865for i ulong c
2866n = or ulong get wdk p shl ulong get wdk add p 1 8
2867if gt i 0
2868wgac 32
2869end
2870for j ulong n
2871wgac ulong get wdk add add p 2 j
2872end
2873p = add add p 2 n
2874end
2875end
2876
2877note lib.run: argv in wdk, label in slot SLOG; stdout and stderr to OUT/receipts/LABEL.log; the
2878note command line goes to OUT/commands.txt after it ends (not on timeout). Returns the log offset
2879note (length in wgr 6) after universal newline translation; exit 73 when rc is not 0, 74 on timeout.
2880fn wgrun ns long to ulong
2881wdpclr
2882wgpsl SOUT
2883wdpt wgtrcps
2884wgpsl SLOG
2885wdpt wgtlog
2886wgsetp SPL
2887fd = wgcreat false
2888pid = wgspawn -1 fd fd WGNO
2889r = wgreap pid ns
2890c = fclose fd
2891if eq r WGTMO
2892wdpclr
2893wgpsl SLOG
2894wgdiep wgtcmdt 74
2895end
2896m = get wgan 0
2897wgasl SLOG
2898wgat wgtrcw
2899wgadl r
2900wgat wgtwin
2901wgasl SWIN
2902wgat wgtargv
2903wgac 32
2904wgkargs
2905wgac 10
2906wdpclr
2907wgpsl SOUT
2908wdpt wgtcmds
2909fd2 = wgcreat true
2910wgwr fd2 m sub get wgan 0 m
2911c2 = fclose fd2
2912put wgan 0 m
2913if ne r 0
2914wdpclr
2915wgpsl SLOG
2916wgdiep wgtcmdf 73
2917end
2918wdpclr
2919wgpsl SPL
2920o = wgrtext
2921put wgr 6 sub get wgan 0 o
2922ret o
2923end
2924
2925note OUT/data/s/SBLD + suffix into wdp
2926fn wgpbld t view uchar * to void
2927wdpclr
2928wgpsl SOUT
2929wdpt wgtdats2
2930wgpsl SBLD
2931wdpt t
2932end
2933
2934note the log (o, n) split on NUL into wgao/wgal from index b0 for cnt answers (exit 75 otherwise)
2935fn wgsplit o ulong n ulong b0 ulong cnt ulong to void
2936k = ulong 0
2937s = o
2938e = add o n
2939i = o
2940while lt i e bound 999999
2941if eq get wga i 0
2942if ge k cnt
2943wgdie wgtcnt 75
2944end
2945put wgao add b0 k s
2946put wgal add b0 k sub i s
2947k = add k 1
2948s = add i 1
2949end
2950i = add i 1
2951end
2952if or ne k cnt ne s e
2953wgdie wgtcnt 75
2954end
2955end
2956
2957note one live batch: prompts [b0, b0 + cnt) of wgpo/wgpl under the batch label in slot SBLD
2958fn wglive b0 ulong cnt ulong to void
2959z = new uchar 1 0
2960wdpclr
2961wgpsl SOUT
2962wdpt wgtdats
2963wgmkp
2964wgpbld wgtbin
2965fd = wgcreat false
2966for q ulong cnt
2967wgwr fd get wgpo add b0 q get wgpl add b0 q
2968w = write fd z 0 1
2969end
2970c = fclose fd
2971m = get wgan 0
2972wgasl SBLD
2973wgat wgtenc
2974wgsetf SLOG m
2975wgkenc
2976lo = wgrun 1800000000000
2977m2 = get wgan 0
2978wgasl SBLD
2979wgat wgtsmp
2980wgsetf SLOG m2
2981wgksmp
2982lo2 = wgrun 900000000000
2983wgsplit lo2 get wgr 6 b0 cnt
2984wgpbld wgtbin
2985u = unlink wdp 0 get wdpn 0
2986wgpbld wgttok
2987u2 = unlink wdp 0 get wdpn 0
2988end
2989
2990note encode argv [CPU, bpeenc, MERGES, 4096, pf, tf] into wdk
2991fn wgkenc to void
2992wdkclr
2993wdkt wgtcpu
2994wdkt wgtbpe
2995wdkt wgtmrg
2996wdkt wgt4096
2997wgpbld wgtbin
2998wdkp
2999wgpbld wgttok
3000wdkp
3001end
3002
3003note sample argv [batch-sample, ck, tf, MERGES, 160] into wdk
3004fn wgksmp to void
3005wdkclr
3006wdkt wgtbs
3007wdpclr
3008wgpsl SCK
3009wdkp
3010wgpbld wgttok
3011wdkp
3012wdkt wgtmrg
3013wdkt wgt160
3014end
3015
3016note geval argv [GPU, geval, ck, story-final.tok, 256, MERGES] into wdk
3017fn wgkgev to void
3018wdkclr
3019wdkt wgtgpu
3020wdkt wgtgev2
3021wdpclr
3022wgpsl SCK
3023wdkp
3024wdkt wgtstok
3025wdkt wgt256
3026wdkt wgtmrg
3027end
3028
3029note one replaylog batch: LOGDIR/SBLD-sample.log
3030fn wglogb b0 ulong cnt ulong to void
3031wdpclr
3032wgpsl SLOG
3033wdpc 47
3034wgpsl SBLD
3035wdpt wgtsmp
3036wdpt wgtlog
3037o = wgrtext
3038wgsplit o sub get wgan 0 o b0 cnt
3039end
3040
3041note the recorded raw for active answer q (probe row q, or turn of job wgact q); 0 when absent
3042fn wgrecraw q ulong to ulong
3043if ne get wgmd 2 2
3044v = wgjget get wgrr q wgtraw
3045ret v
3046end
3047ji = get wgact q
3048ts = wgjget get wgrr ji wgtturns
3049if eq ts 0
3050ret 0
3051end
3052tr = wgjat ts get wgmd 1
3053if eq tr 0
3054ret 0
3055end
3056ret tr
3057end
3058
3059note sample(label=slot SLAB, prompts wgpo/wgpl[0..na)) into wgao/wgal[0..na)
3060fn wgsamp na ulong to void
3061md = get wgmd 0
3062if eq md 2
3063wgsrep na
3064ret
3065end
3066b = ulong 0
3067b0 = ulong 0
3068while lt b0 na bound 1024
3069cnt = sub na b0
3070if gt cnt 128
3071cnt = 128
3072end
3073o = get wgan 0
3074wgasl SLAB
3075wgat wgtbat
3076wgad b
3077wgsetf SBLD o
3078if eq md 1
3079wglive b0 cnt
3080else
3081wglogb b0 cnt
3082end
3083b0 = add b0 cnt
3084b = add b 1
3085end
3086if eq md 3
3087wgsrec na
3088end
3089end
3090
3091note replay: answers are the recorded raws; prompts are compared with the recorded ones (jobs)
3092fn wgsrep na ulong to void
3093for q ulong na
3094r = wgrecraw q
3095if eq r 0
3096wgdie wgtdiv 81
3097end
3098v = r
3099if eq get wgmd 2 2
3100wgcprom q r
3101v = wgjget r wgtrawk
3102end
3103if eq v 0
3104wgdie wgtshp 79
3105end
3106if ne get wgjt v 5
3107wgdie wgtshp 79
3108end
3109put wgao q get wgjo v
3110put wgal q get wgjl v
3111end
3112end
3113
3114note replaylog: the log answers are compared with the recorded raws
3115fn wgsrec na ulong to void
3116for q ulong na
3117r = wgrecraw q
3118if eq r 0
3119wgmism q wgtrawk
3120continue
3121end
3122v = r
3123if eq get wgmd 2 2
3124wgcprom q r
3125v = wgjget r wgtrawk
3126end
3127if eq v 0
3128wgmism q wgtrawk
3129continue
3130end
3131if not wgeq2 get wgao q get wgal q get wgjo v get wgjl v
3132wgmism q wgtrawk
3133end
3134end
3135end
3136
3137note compare prompt q with the recorded turn r
3138fn wgcprom q ulong r ulong to void
3139v = wgjget r wgtprom
3140if eq v 0
3141wgmism q wgtprom
3142ret
3143end
3144if not wgeq2 get wgpo q get wgpl q get wgjo v get wgjl v
3145wgmism q wgtprom
3146end
3147end
3148
3149text wgtmis "MISMATCH row="
3150text wgtfld " field="
3151text wgttrn " turn="
3152
3153fn wgmism q ulong t view uchar * to void
3154put wgmis 0 add get wgmis 0 1
3155wdot wgtmis
3156r = q
3157if eq get wgmd 2 2
3158r = get wgact q
3159end
3160wdod r
3161if eq get wgmd 2 2
3162wdot wgttrn
3163wdod get wgmd 1
3164end
3165wdot wgtfld
3166wdot t
3167wdoc 10
3168end
3169
3170note lib.score: geval on slot SCK with label slot SLOG; the third number of the one E row
3171fn wgscore to ulong
3172wgkgev
3173lo = wgrun 1800000000000
3174n = get wgr 6
3175e = add lo n
3176p = lo
3177found = ulong 0
3178val = ulong 0
3179while lt p e bound 999999
3180q = wgeol p e
3181nx = get wgr 2
3182if wgerow p sub q p
3183found = add found 1
3184val = ulong get wgtm 2
3185if ne get wgtm 1 256
3186found = 99
3187end
3188end
3189p = nx
3190end
3191if ne found 1
3192wgdie wgtgev 78
3193end
3194ret val
3195end
3196
3197note line is "E d+ d+ d+ d+": the four numbers into wgtm
3198fn wgerow o ulong n ulong to bool
3199if lt n 9
3200ret false
3201end
3202if or ne get wga o 69 ne get wga add o 1 32
3203ret false
3204end
3205i = ulong 2
3206for f ulong 4
3207if gt f 0
3208if ge i n
3209ret false
3210end
3211if ne get wga add o i 32
3212ret false
3213end
3214i = add i 1
3215end
3216s = i
3217v = long 0
3218while lt i n bound 4096
3219if not wgdig ulong get wga add o i
3220break
3221end
3222if lt i add s 18
3223v = add mul v 10 long sub ulong get wga add o i 48
3224end
3225i = add i 1
3226end
3227if eq i s
3228ret false
3229end
3230put wgtm f v
3231end
3232ret eq i n
3233end
3234
3235note ---------------------------------------------------------------- probes, results, replay comparison
3236
3237text wgtpass "pass"
3238text wgtcrc "compile_rc"
3239text wgtrrc "run_rc"
3240text wgtPASS "PASS"
3241text wgtFAIL "FAIL"
3242text wgtres "/results/"
3243text wgttxt ".txt"
3244text wgttmp ".tmp"
3245text wgtcr " compile_rc="
3246text wgtrr " run_rc="
3247text wgtsts " state="
3248text wgttns " turns="
3249text wgterr " error"
3250text wgtver "verified"
3251text wgterrk "error"
3252text wgtsrc "src"
3253text wgtobs "obs"
3254text wgttres "tool_result"
3255text wgtobsk "observation"
3256text wgtok "ok"
3257
3258note gates.py probes(): prompts of rows wgdr[0..nr), label slot SLAB; kind wgmd 2 (0 checker, 1 first)
3259fn wgprobes nr ulong to ulong
3260for i ulong nr
3261wgjsget get wgdr i wgtprom
3262put wgpo i get wgr 3
3263put wgpl i get wgr 4
3264end
3265wgsamp nr
3266cnt = ulong 0
3267for q ulong nr
3268ok = false
3269if eq get wgmd 2 1
3270put wgxr 0 WGABS
3271put wgxr 1 WGABS
3272ok = wgfirst get wgao q get wgal q get wgdr q
3273else
3274o = get wgan 0
3275wgasl SLAB
3276wgac 45
3277wgad q
3278wgsetf SCB o
3279ok = wgcheck get wgao q get wgal q get wgdr q
3280end
3281put wgok q wgb ok
3282if ok
3283cnt = add cnt 1
3284end
3285wgrline q
3286if ge get wgmd 0 2
3287wgpcmp q ok
3288end
3289end
3290wgresfin
3291ret cnt
3292end
3293
3294note results buffer to OUT/results/SLAB.txt.tmp, opened by wgresop
3295fn wgresop to void
3296wdpclr
3297wgpsl SOUT
3298wdpt wgtres
3299wgpsl SLAB
3300wdpt wgttxt
3301wdpt wgttmp
3302fd = wgcreat false
3303put wgobf 0 fd
3304put wgobn 0 0
3305end
3306
3307fn wgresfin to void
3308wgofl
3309c = fclose get wgobf 0
3310wdkclr
3311wdpclr
3312wgpsl SOUT
3313wdpt wgtres
3314wgpsl SLAB
3315wdpt wgttxt
3316wdpt wgttmp
3317wdkp
3318put wdpn 0 sub get wdpn 0 4
3319wdkp
3320wdrename
3321end
3322
3323fn wgpf ok bool to void
3324if ok
3325wgot wgtPASS
3326else
3327wgot wgtFAIL
3328end
3329end
3330
3331fn wgrline q ulong to void
3332if eq q 0
3333wgresop
3334end
3335wgod q
3336wgoc 32
3337wgpf eq get wgok q 1
3338if ne get wgxr 0 WGABS
3339wgot wgtcr
3340wgodl get wgxr 0
3341end
3342if ne get wgxr 1 WGABS
3343wgot wgtrr
3344wgodl get wgxr 1
3345end
3346wgoc 10
3347end
3348
3349note recorded boolean under t equals b (absent: mismatch)
3350fn wgcbool q ulong r ulong t view uchar * b bool to void
3351v = wgjget r t
3352if eq v 0
3353wgmism q t
3354ret
3355end
3356ty = get wgjt v
3357if and ne ty 3 ne ty 2
3358wgmism q t
3359ret
3360end
3361if ne wgb eq ty 3 wgb b
3362wgmism q t
3363end
3364end
3365
3366note recorded integer under t (absent when x is WGABS)
3367fn wgcint q ulong r ulong t view uchar * x long to void
3368v = wgjget r t
3369if eq v 0
3370if ne x WGABS
3371wgmism q t
3372end
3373ret
3374end
3375if eq x WGABS
3376wgmism q t
3377ret
3378end
3379if ne wgjint v x
3380wgmism q t
3381end
3382end
3383
3384fn wgpcmp q ulong ok bool to void
3385r = get wgrr q
3386wgcbool q r wgtpass ok
3387if eq get wgmd 2 0
3388wgcint q r wgtcrc get wgxr 0
3389wgcint q r wgtrrc get wgxr 1
3390end
3391end
3392
3393note recorded string under t equals (o, n); absent counts as empty when em is true
3394fn wgcstr q ulong r ulong t view uchar * o ulong n ulong to void
3395v = wgjget r t
3396if eq v 0
3397wgmism q t
3398ret
3399end
3400if ne get wgjt v 5
3401wgmism q t
3402ret
3403end
3404if not wgeq2 get wgjo v get wgjl v o n
3405wgmism q t
3406end
3407end
3408
3409note compare job ji with recorded row wgrr ji (mismatch rows are job indexes)
3410fn wgjcmp ji ulong to void
3411r = get wgrr ji
3412put wgmd 1 0
3413wgcbool ji r wgtpass eq get wgjps ji 1
3414m = get wgan 0
3415wgstn ulong get wgjst ji
3416wgcstr ji r wgtstk m sub get wgan 0 m
3417put wgan 0 m
3418wgcstr ji r wgtsrc get wgjso ji get wgjsn ji
3419wgcstr ji r wgtobs get wgjoo ji get wgjon ji
3420vv = wgjget r wgtver
3421if ne eq vv 0 eq get wgjhv ji 0
3422wgmism ji wgtver
3423else
3424if ne vv 0
3425wgcbool ji r wgtver eq get wgjvf ji 1
3426end
3427end
3428if ne eq wgjget r wgterrk 0 eq get wgjer ji 0
3429wgmism ji wgterrk
3430end
3431ts = wgjget r wgtturns
3432if eq ts 0
3433wgmism ji wgtturns
3434ret
3435end
3436if ne get wgjo ts get wgjtn ji
3437wgmism ji wgtturns
3438ret
3439end
3440for t ulong get wgjtn ji
3441wgtcmp ji wgjat ts t t
3442end
3443end
3444
3445fn wgtcmp ji ulong tr ulong t ulong to void
3446k = add mul ji 7 t
3447m = get wgan 0
3448wgstn ulong get wgtst k
3449wgcstr ji tr wgtstk m sub get wgan 0 m
3450put wgan 0 m
3451tv = wgjget tr wgttres
3452if ne eq tv 0 eq get wgtth k 0
3453wgmism ji wgttres
3454ret
3455end
3456if ne tv 0
3457wgcbool ji tv wgtok eq get wgtth k 2
3458wgcstr ji tv wgtobsk get wgtto k get wgttn k
3459end
3460end
3461
3462note jobs results file: id PASS|FAIL state=S turns=T [error]
3463fn wgjres nj ulong to void
3464wgresop
3465for i ulong nj
3466wgjsget get wgdr i wgtid
3467wgoa get wgr 3 get wgr 4
3468wgoc 32
3469wgpf eq get wgjps i 1
3470wgot wgtsts
3471m = get wgan 0
3472wgstn ulong get wgjst i
3473wgoa m sub get wgan 0 m
3474put wgan 0 m
3475wgot wgttns
3476wgod get wgjtn i
3477if eq get wgjer i 1
3478wgot wgterr
3479end
3480wgoc 10
3481end
3482wgresfin
3483end
3484
3485fn wgjpass nj ulong to ulong
3486c = ulong 0
3487for i ulong nj
3488if eq get wgjps i 1
3489c = add c 1
3490end
3491end
3492ret c
3493end
3494
3495note ---------------------------------------------------------------- paths and arguments
3496
3497note argument i into slot k
3498fn wgargs i ulong k ulong to void
3499n = wdarg i
3500o = get wgan 0
3501for j ulong n
3502wgac ulong get wdab j
3503end
3504wgsset k o n
3505end
3506
3507text wgtpwd "PWD"
3508text wgtnopwd "wgate: relative path and no PWD\n"
3509
3510note Path.resolve() made lexical: argument i, absolute (PWD prefix), with "." and ".." folded; slot k
3511fn wgresolv i ulong k ulong to void
3512n = wdarg i
3513o = get wgan 0
3514if or eq n 0 ne get wdab 0 47
3515if not wdenv wgtpwd
3516wgdie wgtnopwd 2
3517end
3518for j ulong get wdvn 0
3519wgac ulong get wdv j
3520end
3521wgac 47
3522end
3523for j2 ulong n
3524wgac ulong get wdab j2
3525end
3526e = get wgan 0
3527wgnorm o e
3528end
3529
3530note fold the absolute path [o, e) into a fresh slot k copy at the arena top (written by wgnorm)
3531fn wgnorm o ulong e ulong to void
3532r = get wgan 0
3533p = o
3534while lt p e bound 4096
3535while lt p e bound 4096
3536if ne get wga p 47
3537break
3538end
3539p = add p 1
3540end
3541if ge p e
3542break
3543end
3544q = p
3545while lt q e bound 4096
3546if eq get wga q 47
3547break
3548end
3549q = add q 1
3550end
3551wgncmp r p sub q p
3552p = q
3553end
3554if eq get wgan 0 r
3555wgac 47
3556end
3557put wgr 7 r
3558end
3559
3560note one path component [p, p + sl): "." is dropped, ".." pops, others are appended
3561fn wgncmp r ulong p ulong sl ulong to void
3562if wgisdot p sl 1
3563ret
3564end
3565if wgisdot p sl 2
3566wgpop r
3567ret
3568end
3569wgac 47
3570wgacp p sl
3571end
3572
3573note component is k dots
3574fn wgisdot p ulong sl ulong k ulong to bool
3575if ne sl k
3576ret false
3577end
3578for i ulong k
3579if ne get wga add p i 46
3580ret false
3581end
3582end
3583ret true
3584end
3585
3586note drop the last component of the path at r
3587fn wgpop r ulong to void
3588t = get wgan 0
3589while gt t r bound 4096
3590t = sub t 1
3591if eq get wga t 47
3592break
3593end
3594end
3595put wgan 0 t
3596end
3597
3598fn wgresk i ulong k ulong to void
3599wgresolv i k
3600r = get wgr 7
3601wgsetf k r
3602end
3603
3604note OUT subdirectories
3605text wgtsfix "/fixtures"
3606text wgtsrcp "/receipts"
3607text wgtsres "/results"
3608text wgtsdat "/data"
3609text wgtsbld "/build"
3610
3611fn wgmkd t view uchar * to void
3612wdpclr
3613wgpsl SOUT
3614wdpt t
3615wgmkp
3616end
3617
3618fn wgmkout to void
3619wdpclr
3620wgpsl SOUT
3621wgmkp
3622wgmkd wgtsfix
3623wgmkd wgtsrcp
3624wgmkd wgtsres
3625wgmkd wgtsdat
3626wgmkd wgtsbld
3627wdpclr
3628wgpsl SOUT
3629wdpt wgtsfix
3630wgsetp SFIX
3631end
3632
3633note decimal argument i (absent: d)
3634fn wgargn i ulong d ulong to ulong
3635if ge i ulong argcnt
3636ret d
3637end
3638n = wdarg i
3639v = ulong 0
3640if eq n 0
3641wgdie wgtuse 2
3642end
3643for j ulong n
3644c = ulong get wdab j
3645if not wgdig c
3646wgdie wgtuse 2
3647end
3648v = add mul v 10 sub c 48
3649end
3650if eq v 0
3651wgdie wgtuse 2
3652end
3653ret v
3654end
3655
3656note ---------------------------------------------------------------- replay and dryrun
3657
3658text wgtprobe "probe"
3659text wgtfirst "first"
3660text wgtjobs "jobs"
3661text wgtrply "replay"
3662text wgtREP "REPLAY mode="
3663text wgtrows " rows="
3664text wgtpas " pass="
3665text wgtrpas " recorded_pass="
3666text wgtmms " mismatches="
3667
3668note kind argument i: 0 probe, 1 first, 2 jobs
3669fn wgkind i ulong to ulong
3670n = wdarg i
3671o = get wgan 0
3672for j ulong n
3673wgac ulong get wdab j
3674end
3675put wgan 0 o
3676if wgeqt o n wgtprobe
3677ret 0
3678end
3679if wgeqt o n wgtfirst
3680ret 1
3681end
3682if wgeqt o n wgtjobs
3683ret 2
3684end
3685wgdie wgtuse 2
3686ret 0
3687end
3688
3689note recorded passes of wgrr[0..n)
3690fn wgrpass n ulong to ulong
3691c = ulong 0
3692for i ulong n
3693v = wgjget get wgrr i wgtpass
3694if ne v 0
3695if eq get wgjt v 3
3696c = add c 1
3697end
3698end
3699end
3700ret c
3701end
3702
3703note replay or replaylog (lg) with the argument layout of wgtuse
3704fn wgreplay lg bool to int
3705kd = wgkind 2
3706put wgmd 2 kd
3707oi = ulong 5
3708if lg
3709oi = 7
3710end
3711if lt ulong argcnt add oi 1
3712wgdie wgtuse 2
3713end
3714wgresk oi SOUT
3715wgmkout
3716if lg
3717wgresk 5 SLOG
3718wgargs 6 SLAB
3719put wgmd 0 3
3720else
3721wgsett SLAB wgtrply
3722put wgmd 0 2
3723end
3724st = wgargn add oi 1 1
3725wdpclr
3726wdpa 3
3727dk = wgjfile
3728nd = wgjrows dk st
3729wdpclr
3730wdpa 4
3731rk = wgjfile
3732nr = wgjrec rk
3733if ne nd nr
3734wdoclr
3735wdot wgtcnt
3736wdod nd
3737wdoc 32
3738wdod nr
3739wdoc 10
3740wdoflush 1
3741ret 1
3742end
3743p = ulong 0
3744if eq kd 2
3745wgsset SJL wgso SLAB wgsn SLAB
3746wgjobs nd
3747wgsset SLAB wgso SJL wgsn SJL
3748wgjres nd
3749for i ulong nd
3750wgjcmp i
3751end
3752p = wgjpass nd
3753else
3754p = wgprobes nd
3755end
3756wdot wgtREP
3757if eq kd 0
3758wdot wgtprobe
3759end
3760if eq kd 1
3761wdot wgtfirst
3762end
3763if eq kd 2
3764wdot wgtjobs
3765end
3766wdot wgtrows
3767wdod nd
3768wdot wgtpas
3769wdod p
3770wdot wgtrpas
3771wdod wgrpass nr
3772wdot wgtmms
3773wdod get wgmis 0
3774wdoc 10
3775wdoflush 1
3776if gt get wgmis 0 0
3777ret 1
3778end
3779ret 0
3780end
3781
3782text wgtdry "DRYRUN NOT_RUN "
3783text wgtdenc "encode argv: "
3784text wgtdsmp "sample argv: "
3785text wgtdgev "geval argv: "
3786text wgtdpr "prompts="
3787text wgtdbt " batches="
3788text wgtdby " batch0_bytes="
3789text wgtdsh " batch0_sha256="
3790text wgtdnw "DRYRUN nothing was executed or written\n"
3791
3792note SHA-256 of arena [o, o + n) into wdd
3793fn wgsha o ulong n ulong to void
3794b = new uchar 65536 0
3795c = new uchar 104 0
3796d = new uchar 32 0
3797sha256_init c
3798t = ulong 0
3799while lt t n bound 999999
3800k = sub n t
3801if gt k 65536
3802k = 65536
3803end
3804for i ulong k
3805put b i get wga add o add t i
3806end
3807sha256_update c part b 0 k
3808t = add t k
3809end
3810sha256_final c d
3811for j ulong 32
3812put wdd j get d j
3813end
3814end
3815
3816fn wgdline t view uchar * to void
3817wdot wgtdry
3818wdot t
3819o = get wgan 0
3820wgkargs
3821wgpra o sub get wgan 0 o
3822put wgan 0 o
3823wdoc 10
3824end
3825
3826note dryrun probe|jobs CK OUTDIR LABEL DATA: print what live mode would run for batch 0, run nothing
3827fn wgdry to int
3828if ne ulong argcnt 7
3829wgdie wgtuse 2
3830end
3831kd = wgkind 2
3832if eq kd 1
3833kd = 0
3834end
3835wgresk 3 SCK
3836wgresk 4 SOUT
3837wdpclr
3838wdpa 6
3839dk = wgjfile
3840nd = wgjrows dk 1
3841o = get wgan 0
3842for j ulong wdarg 5
3843wgac ulong get wdab j
3844end
3845if eq kd 2
3846wgsetf SJL o
3847o2 = get wgan 0
3848wgasl SJL
3849wgat wgtturn
3850wgac 48
3851wgsetf SLAB o2
3852for i ulong nd
3853put wgjst i 1
3854put wgjsn i 0
3855put wgjon i 0
3856put wgpo i wgprm i
3857put wgpl i sub get wgan 0 get wgpo i
3858end
3859else
3860wgsetf SLAB o
3861for i2 ulong nd
3862wgjsget get wgdr i2 wgtprom
3863put wgpo i2 get wgr 3
3864put wgpl i2 get wgr 4
3865end
3866end
3867o3 = get wgan 0
3868wgasl SLAB
3869wgat wgtbat
3870wgac 48
3871wgsetf SBLD o3
3872cnt = nd
3873if gt cnt 128
3874cnt = 128
3875end
3876bo = get wgan 0
3877for q ulong cnt
3878wgacp get wgpo q get wgpl q
3879wgac 0
3880end
3881bn = sub get wgan 0 bo
3882wgsha bo bn
3883wgkenc
3884wgdline wgtdenc
3885wgksmp
3886wgdline wgtdsmp
3887wdot wgtdry
3888wdot wgtdpr
3889wdod nd
3890wdot wgtdbt
3891wdod div add nd 127 128
3892wdot wgtdby
3893wdod bn
3894wdot wgtdsh
3895wdohex
3896wdoc 10
3897wgkgev
3898wgdline wgtdgev
3899wdot wgtdnw
3900wdoflush 1
3901ret 0
3902end
3903
3904note ---------------------------------------------------------------- run mode (gates.py main)
3905
3906text wgtgst "/gates.txt"
3907text wgtcand "candidate "
3908text wgtcsha "candidate_sha256 "
3909text wgtstart "start "
3910text wgtwinl "window "
3911text wgtaux "aux "
3912text wgtgate "gate "
3913text wgtendl "end "
3914text wgtallp "GATES_PASS"
3915text wgtnall "GATES_NOT_ALL_PASS"
3916text wgtbudr "WINDOW_BUDGET_REACHED "
3917text wgtg0 "latency"
3918text wggn1 "copies"
3919text wggn2 "screen"
3920text wggn3 "dev_jobs"
3921text wggn4 "regression"
3922text wggn5 "story_w256"
3923text wgtg6 "retention"
3924text wgtdcopy "copy-final.json"
3925text wgtdreg "regression.json"
3926text wgtddev "dev-jobs.json"
3927text wgtdret "retention-jobs.json"
3928text wgtdscr "localization-screen.json"
3929text wgtlb "latency-base-copy"
3930text wgtlc "latency-candidate-copy"
3931text wgtlbs "latency_base_s"
3932text wgtlcs "latency_candidate_s"
3933text wgtlbp "latency_base_copy_pass"
3934text wgtlcp "latency_candidate_copy_pass"
3935text wgtlscr "screen"
3936text wgtlreg "regression"
3937text wgtldev "dev-jobs"
3938text wgtlret "retention-jobs"
3939text wgtlsty "story-w256"
3940text wgtvlog "logic="
3941text wgtvctl ",controls="
3942text wgtvpr ",pairs="
3943text wgtlogic "logic"
3944text wgtpair "pair"
3945text wgtfltk "fault"
3946
3947note gate names by index
3948fn wggname g ulong to void
3949if eq g 0
3950wgat wgtg0
3951end
3952if eq g 1
3953wgat wggn1
3954end
3955if eq g 2
3956wgat wggn2
3957end
3958if eq g 3
3959wgat wggn3
3960end
3961if eq g 4
3962wgat wggn4
3963end
3964if eq g 5
3965wgat wggn5
3966end
3967if eq g 6
3968wgat wgtg6
3969end
3970end
3971
3972note two decimal digits of v onto the arena
3973fn wga2 v long to void
3974wgac add 48 ulong div v 10
3975wgac add 48 ulong rem v 10
3976end
3977
3978note days since 1970-01-01 to civil y, m, d in wgtm 0..2 (proleptic Gregorian)
3979fn wgcivil days long to void
3980z = add days 719468
3981era = div z 146097
3982doe = sub z mul era 146097
3983yoe = div sub add sub doe div doe 1460 div doe 36524 div doe 146096 365
3984y = add yoe mul era 400
3985doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100
3986mp = div add mul 5 doy 2 153
3987d = add sub doy div add mul 153 mp 2 5 1
3988m = add mp 3
3989if ge mp 10
3990m = sub mp 9
3991end
3992if le m 2
3993y = add y 1
3994end
3995put wgtm 0 y
3996put wgtm 1 m
3997put wgtm 2 d
3998end
3999
4000note UTC now as YYYY-MM-DDTHH:MM:SSZ onto the arena
4001fn wgutc to void
4002s = div realns 1000000000
4003r = rem s 86400
4004wgcivil div s 86400
4005wgadl get wgtm 0
4006wgac 45
4007wga2 get wgtm 1
4008wgac 45
4009wga2 get wgtm 2
4010wgac 84
4011wga2 div r 3600
4012wgac 58
4013wga2 div rem r 3600 60
4014wgac 58
4015wga2 rem r 60
4016wgac 90
4017end
4018
4019note wdd as lowercase hex onto the arena
4020fn wgahex to void
4021for i ulong 32
4022b = ulong get wdd i
4023h = shr b 4
4024l = and b 15
4025if lt h 10
4026wgac add 48 h
4027else
4028wgac add 87 h
4029end
4030if lt l 10
4031wgac add 48 l
4032else
4033wgac add 87 l
4034end
4035end
4036end
4037
4038note append arena [o, top) to OUT/gates.txt and drop it from the arena
4039fn wgstapp o ulong to void
4040wdpclr
4041wgpsl SOUT
4042wdpt wgtgst
4043fd = wgcreat true
4044wgwr fd o sub get wgan 0 o
4045c = fclose fd
4046put wgan 0 o
4047end
4048
4049note "aux KEY VALUE" with an integer value v
4050fn wgaux t view uchar * v ulong to void
4051o = get wgan 0
4052wgat wgtaux
4053wgat t
4054wgac 32
4055wgad v
4056wgac 10
4057wgstapp o
4058end
4059
4060note centiseconds as Python round(x, 2) repr (X.Y or X.YZ)
4061fn wgacs cs ulong to void
4062wgad div cs 100
4063wgac 46
4064f = rem cs 100
4065wgac add 48 div f 10
4066if ne rem f 10 0
4067wgac add 48 rem f 10
4068end
4069end
4070
4071note "aux KEY X.YZ"
4072fn wgauxs t view uchar * cs ulong to void
4073o = get wgan 0
4074wgat wgtaux
4075wgat t
4076wgac 32
4077wgacs cs
4078wgac 10
4079wgstapp o
4080end
4081
4082note record gate g: value is arena [vo, top); prints "NAME VALUE PASS|FAIL" and appends the gate line
4083fn wggate g ulong vo ulong ok bool to void
4084vn = sub get wgan 0 vo
4085o = get wgan 0
4086wggname g
4087wgac 32
4088wgacp vo vn
4089wgac 32
4090if ok
4091wgat wgtPASS
4092put wgg g 1
4093else
4094wgat wgtFAIL
4095put wgg g 2
4096end
4097wgac 10
4098wdoclr
4099for i ulong sub get wgan 0 o
4100wdoc ulong get wga add o i
4101end
4102wdoflush 1
4103o2 = get wgan 0
4104wgat wgtgate
4105wgacp o sub sub o2 o 1
4106wgac 32
4107wgasl SWIN
4108wgac 32
4109wgutc
4110wgac 10
4111wgstapp o2
4112put wgan 0 vo
4113end
4114
4115note load ROUND40/data/NAME rows (stride 1); returns the row count
4116fn wgdata t view uchar * to ulong
4117wdpclr
4118wdpt wgtr40d
4119wdpt t
4120k = wgjfile
4121n = wgjrows k 1
4122ret n
4123end
4124
4125note one probes() run; returns the pass count
4126fn wgprun lab view uchar * kd ulong n ulong to ulong
4127wgsett SLAB lab
4128put wgmd 2 kd
4129c = wgprobes n
4130ret c
4131end
4132
4133note task 0: latency + copies (both checkpoints sample copy-final)
4134fn wgtlat to void
4135n = wgdata wgtdcopy
4136wgsett SCK wgtbase
4137t0 = monons
4138cb = wgprun wgtlb 0 n
4139bcs = ulong div add sub monons t0 5000000 10000000
4140put wgsl add mul SCK 2 0 wgso SCAND
4141put wgsl add mul SCK 2 1 wgsn SCAND
4142t1 = monons
4143cc = wgprun wgtlc 0 n
4144ccs = ulong div add sub monons t1 5000000 10000000
4145wgauxs wgtlbs bcs
4146wgauxs wgtlcs ccs
4147wgaux wgtlbp cb
4148wgaux wgtlcp cc
4149if eq bcs 0
4150wgdie wgtzero 70
4151end
4152vo = get wgan 0
4153wgratio ccs bcs
4154wggate 0 vo le mul ccs 100 mul bcs 102
4155vo2 = get wgan 0
4156wgad cc
4157wggate 1 vo2 eq cc 64
4158end
4159
4160note round(c / b, 4) in Python float repr onto the arena (half up on the fifth digit)
4161fn wgratio c ulong b ulong to void
4162v = div add mul c 20000 b mul b 2
4163wgad div v 10000
4164wgac 46
4165f = rem v 10000
4166if eq f 0
4167wgac 48
4168ret
4169end
4170k = ulong 1000
4171while gt f 0 bound 8
4172wgac add 48 div f k
4173f = rem f k
4174k = div k 10
4175end
4176end
4177
4178fn wgtscr to void
4179n = wgdata wgtdscr
4180put wgsl add mul SCK 2 0 wgso SCAND
4181put wgsl add mul SCK 2 1 wgsn SCAND
4182c = wgprun wgtlscr 1 n
4183vo = get wgan 0
4184wgad c
4185wggate 2 vo eq c 8
4186end
4187
4188fn wgtreg to void
4189n = wgdata wgtdreg
4190put wgsl add mul SCK 2 0 wgso SCAND
4191put wgsl add mul SCK 2 1 wgsn SCAND
4192c = wgprun wgtlreg 0 n
4193vo = get wgan 0
4194wgad c
4195wggate 4 vo eq c 685
4196end
4197
4198fn wgtsty to void
4199put wgsl add mul SCK 2 0 wgso SCAND
4200put wgsl add mul SCK 2 1 wgsn SCAND
4201wgsett SLOG wgtlsty
4202v = wgscore
4203vo = get wgan 0
4204wgad v
4205wggate 5 vo le mul v 10000 mul ulong 1190843 10025
4206end
4207
4208note jobs over ROUND40/data/NAME under label lab; returns the job count
4209fn wgtjrun t view uchar * lab view uchar * to ulong
4210n = wgdata t
4211put wgsl add mul SCK 2 0 wgso SCAND
4212put wgsl add mul SCK 2 1 wgsn SCAND
4213wgsett SJL lab
4214put wgmd 2 2
4215wgjobs n
4216wgsett SLAB lab
4217wgjres n
4218ret n
4219end
4220
4221note job i passes and its pair value equals job j's (same JSON type and text)
4222fn wgpaireq i ulong j ulong to bool
4223a = wgjget get wgdr i wgtpair
4224b = wgjget get wgdr j wgtpair
4225if or eq a 0 eq b 0
4226ret false
4227end
4228if ne get wgjt a get wgjt b
4229ret false
4230end
4231ret wgeq2 get wgjo a get wgjl a get wgjo b get wgjl b
4232end
4233
4234fn wgtdev to void
4235n = wgtjrun wgtddev wgtldev
4236lg = ulong 0
4237ct = ulong 0
4238for i ulong n
4239if eq get wgjps i 1
4240if wgjis get wgdr i wgtfltk wgtlogic
4241lg = add lg 1
4242else
4243ct = add ct 1
4244end
4245end
4246end
4247pr = wgpairs n
4248vo = get wgan 0
4249wgat wgtvlog
4250wgad lg
4251wgat wgtvctl
4252wgad ct
4253wgat wgtvpr
4254wgad pr
4255wggate 3 vo and ge lg 72 and ge ct 12 ge pr 24
4256end
4257
4258note distinct pair values whose jobs all pass
4259fn wgpairs n ulong to ulong
4260pr = ulong 0
4261for i ulong n
4262if eq wgjget get wgdr i wgtpair 0
4263continue
4264end
4265fst = true
4266alp = true
4267for j ulong n
4268if wgpaireq i j
4269if lt j i
4270fst = false
4271end
4272if ne get wgjps j 1
4273alp = false
4274end
4275end
4276end
4277if and fst alp
4278pr = add pr 1
4279end
4280end
4281ret pr
4282end
4283
4284fn wgtret to void
4285n = wgtjrun wgtdret wgtlret
4286c = wgjpass n
4287vo = get wgan 0
4288wgad c
4289wggate 6 vo eq c 847
4290end
4291
4292note read OUT/gates.txt: gate results into wgg, candidate sha checked against arena [ho, ho + 64)
4293fn wgstread ho ulong to void
4294wdpclr
4295wgpsl SOUT
4296wdpt wgtgst
4297if not wgexist
4298ret
4299end
4300o = wgload
4301e = get wgan 0
4302p = o
4303while lt p e bound 999999
4304q = wgeol p e
4305nx = get wgr 2
4306if wgsw p sub q p wgtcsha
4307if or ne sub q p 81 not wgeqa add p 17 ho 64
4308wgdie wgtcsm 5
4309end
4310end
4311if wgsw p sub q p wgtgate
4312wgstg add p 5 sub q add p 5
4313end
4314p = nx
4315end
4316put wgan 0 o
4317end
4318
4319note "NAME VALUE PASS|FAIL ..." at (o, n): set wgg
4320fn wgstg o ulong n ulong to void
4321s1 = wgfindt o n wgtsp
4322if eq s1 WGNO
4323ret
4324end
4325for g ulong 7
4326m = get wgan 0
4327wggname g
4328gl = sub get wgan 0 m
4329eqn = wgeq2 o s1 m gl
4330put wgan 0 m
4331if eqn
4332r = add add o s1 1
4333rn = sub n add s1 1
4334s2 = wgfindt r rn wgtsp
4335if ne s2 WGNO
4336if wgsw add add r s2 1 sub rn add s2 1 wgtPASS
4337put wgg g 1
4338else
4339put wgg g 2
4340end
4341end
4342end
4343end
4344end
4345
4346note estimate in seconds of task k (gates.py TASKS)
4347fn wgest k ulong to ulong
4348if eq k 0
4349ret 150
4350end
4351if eq k 1
4352ret 60
4353end
4354if eq k 2
4355ret 400
4356end
4357if eq k 3
4358ret 150
4359end
4360if eq k 4
4361ret 40
4362end
4363ret 700
4364end
4365
4366note gate index that marks task k done (latency task records gates 0 and 1)
4367fn wgtg k ulong to ulong
4368if eq k 0
4369ret 1
4370end
4371if eq k 1
4372ret 2
4373end
4374if eq k 2
4375ret 3
4376end
4377if eq k 3
4378ret 4
4379end
4380if eq k 4
4381ret 5
4382end
4383ret 6
4384end
4385
4386fn wgtask k ulong to void
4387if eq k 0
4388wgtlat
4389end
4390if eq k 1
4391wgtscr
4392end
4393if eq k 2
4394wgtdev
4395end
4396if eq k 3
4397wgtreg
4398end
4399if eq k 4
4400wgtsty
4401end
4402if eq k 5
4403wgtret
4404end
4405end
4406
4407fn wganyf to bool
4408for g ulong 7
4409if eq get wgg g 2
4410ret true
4411end
4412end
4413ret false
4414end
4415
4416note WSP_BUDGET seconds (default 1080; digits only)
4417fn wgbudget to ulong
4418if not wdenv wgtbud
4419ret 1080
4420end
4421n = get wdvn 0
4422if eq n 0
4423wgdie wgtbudb 2
4424end
4425v = ulong 0
4426for i ulong n
4427c = ulong get wdv i
4428if not wgdig c
4429wgdie wgtbudb 2
4430end
4431v = add mul v 10 sub c 48
4432end
4433ret v
4434end
4435
4436fn wgrunm to int
4437t0 = monons
4438if ne ulong argcnt 4
4439wgdie wgtuse 2
4440end
4441wgrwin
4442bud = wgbudget
4443wgresk 3 SOUT
4444wgresk 2 SCAND
4445wgmkout
4446put wgmd 0 1
4447wgrhead
4448mk = get wgan 0
4449for k ulong 6
4450if wganyf
4451break
4452end
4453if ne get wgg wgtg k 0
4454continue
4455end
4456el = ulong div sub monons t0 1000000000
4457if gt add el wgest k bud
4458wdoclr
4459wdot wgtbudr
4460wdod el
4461wdoc 10
4462wdoflush 1
4463ret 10
4464end
4465put wgan 0 mk
4466put wgjn 0 0
4467wgtask k
4468end
4469wgrfin
4470ret 0
4471end
4472
4473note SPARK_WINDOW into slot SWIN; exit 3 when it is missing or empty
4474fn wgrwin to void
4475if not wdenv wgtsw
4476wgdie wgtrefu 3
4477end
4478if eq get wdvn 0 0
4479wgdie wgtrefu 3
4480end
4481o = get wgan 0
4482for i ulong get wdvn 0
4483wgac ulong get wdv i
4484end
4485wgsetf SWIN o
4486end
4487
4488note base and candidate sha256, resume state, and the header lines of gates.txt
4489fn wgrhead to void
4490wdpclr
4491wdpt wgtbase
4492if not wdfsha
4493wgdiep wgtfile 71
4494end
4495if not wdhexeq wgtbsha
4496wdpclr
4497wdpt wgtbase
4498wgdiep wgtbsm 4
4499end
4500wdpclr
4501wgpsl SCAND
4502if not wdfsha
4503wgdiep wgtfile 71
4504end
4505ho = get wgan 0
4506wgahex
4507wgstread ho
4508wdpclr
4509wgpsl SOUT
4510wdpt wgtgst
4511frs = not wgexist
4512o2 = get wgan 0
4513if frs
4514wgat wgtcand
4515wgasl SCAND
4516wgac 10
4517wgat wgtcsha
4518wgacp ho 64
4519wgac 10
4520wgat wgtstart
4521wgutc
4522wgac 10
4523end
4524wgat wgtwinl
4525wgasl SWIN
4526wgac 10
4527wgstapp o2
4528end
4529
4530note the end line and the verdict (GATES_PASS when all 7 gates passed)
4531fn wgrfin to void
4532alp = true
4533for g ulong 7
4534if ne get wgg g 1
4535alp = false
4536end
4537end
4538o3 = get wgan 0
4539wgat wgtendl
4540wgutc
4541wgac 32
4542vo = get wgan 0
4543if alp
4544wgat wgtallp
4545else
4546wgat wgtnall
4547end
4548wgac 10
4549wdoclr
4550for j ulong sub get wgan 0 vo
4551wdoc ulong get wga add vo j
4552end
4553wdoflush 1
4554wgstapp o3
4555end
4556
4557note ---------------------------------------------------------------- entry
4558
4559text wgtrunm "run"
4560text wgtrlog "replaylog"
4561text wgtdryr "dryrun"
4562
4563fn main to int
4564put wgan 0 0
4565put wgjn 0 0
4566put wgobf 0 1
4567put wgxr 0 WGABS
4568put wgxr 1 WGABS
4569if lt ulong argcnt 2
4570wgdie wgtuse 2
4571end
4572n = wdarg 1
4573o = get wgan 0
4574for j ulong n
4575wgac ulong get wdab j
4576end
4577put wgan 0 o
4578r = int 2
4579if wgeqt o n wgtrunm
4580r = wgrunm
4581ret r
4582end
4583if wgeqt o n wgtrply
4584r = wgreplay false
4585ret r
4586end
4587if wgeqt o n wgtrlog
4588r = wgreplay true
4589ret r
4590end
4591if wgeqt o n wgtdryr
4592r = wgdry
4593ret r
4594end
4595wgdie wgtuse 2
4596ret r
4597end