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 / tools / max-interop / contract_check.om

1253 lines · 17869 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note contract_check: native Omega checker for the MAX interop op contracts.
3note Protocol: stdin starts with a line mode=id|check|manifest|sha256, then the payload.
4note mode=id / mode=sha256 hash the payload; mode=check validates a canonical
5note omega-op-contract/1 file; mode=manifest validates an omega-input-manifest/1.
6note Output is only written for a decision (OK / REFUSED); exit 0 on OK, 1 on refusal.
7note mode=manifest payload (after the mode line):
8note expect=<hex64>
9note omega-input-manifest/1
10note op=<matmul|gqa-causal-attention>
11note contract=<hex64>
12note fixture=<name>
13note input_sha256=<hex64>
14note seed=<u64>
15note count=<u32>
16note [payload_hex=<even-length lowercase hex>]
17note The payload_hex checksum, when present, must match input_sha256, and the
18note contract must be the frozen id for op and equal the expect id.
19note SHA-256 is adapted from benchmarks-om/build/base/om-sha256.om, itself
20note Apache-2.0 WITH LLVM-exception and checked against Omega seed/atlas/atlas.s2 and src/sha256.c.
21note No heap: all state is in fixed globals and the fixed input pool.
22
23global big uchar 1048576
24global irlen ulong 1
25global pstart ulong 1
26global nline ulong 1
27global pofs ulong 256
28global plen ulong 256
29global sofs ulong 256
30global slen ulong 256
31global nsch ulong 1
32
33global hk uint 64
34global hs uint 8
35global hm uint 64
36global hb uchar 64
37global hd uchar 64
38global hmeta ulong 3
39
40text schm0 "omega-op-contract/1\nop=matmul\nabi=1\ndtype_a=bf16\ndtype_b=bf16\ndtype_c=f32\nlayout_a=row-major\nlayout_b=row-major\nlayout_c=row-major\nstride_a=contiguous\nstride_b=contiguous\nstride_c=contiguous\naccumulation=fp32\nrounding=input-rne-bf16,accumulate-fp32\nalpha=1\nbeta=0\nalias=forbid\nnan=forbid\ninf=forbid\nm_min=1\nm_max=8192\nk_min=1\nk_max=16384\nn_min=1\nn_max=8192\ntail=zero-pad-to-multiple-of-16\ntolerance=abs<=1e-5*max(1,abs(ref))\nreference=fp64-sum-of-exact-bf16-products\n"
41text schm1 "omega-op-contract/1\nop=gqa-causal-attention\nabi=1\ndtype_q=f32\ndtype_k=f32\ndtype_v=f32\ndtype_out=f32\nlayout_q=token-head-dim\nlayout_k=token-head-dim\nlayout_v=token-head-dim\nlayout_out=token-head-dim\nhead_dim=128\nq_heads_min=1\nq_heads_max=64\nkv_heads_min=1\nkv_heads_max=64\nhead_map=h_q/(q_heads/kv_heads)\nscale=1/sqrt(128)\nmask=causal-inclusive\nsoftmax=fp32-max-subtracted\nkv_stride=token-major\nzero_length=zero-output\nalias=forbid\nnan=forbid\ninf=forbid\ntolerance_normal=rel<=2e-4,abs<=2e-5\ntolerance_large_scores=rel<=1e-3,abs<=1e-4\nreference=fp64-softmax-fp64-weighted-sum\n"
42text mhdr "omega-input-manifest/1"
43text omth "matmul"
44text ogqa "gqa-causal-attention"
45text mid "647116fc1ba1e1394982fc8ba181ce565293f160a6b56afc0f02b2128a675704"
46text gid "003696e422bba7274877ba9e01a61076ea0f862f32760cbaa06c60f85a115359"
47text okmsg "OK "
48text refmsg "REFUSED "
49text newln "\n"
50text ehead "E_HEADER\n"
51text eorder "E_ORDER\n"
52text evalue "E_VALUE\n"
53text emiss "E_MISSING\n"
54text eunknown "E_UNKNOWN\n"
55text etol "E_TOLERANCE\n"
56text edtype "E_DTYPE\n"
57text elayout "E_LAYOUT\n"
58text etarget "E_TARGET\n"
59
60note ---- SHA-256, adapted from the proven om-sha256.om ----
61text hconst "428a2f9871374491b5c0fbcfe9b5dba53956c25b59f111f1923f82a4ab1c5ed5d807aa9812835b01243185be550c7dc372be5d7480deb1fe9bdc06a7c19bf174e49b69c1efbe47860fc19dc6240ca1cc2de92c6f4a7484aa5cb0a9dc76f988da983e5152a831c66db00327c8bf597fc7c6e00bf3d5a7914706ca63511429296727b70a852e1b21384d2c6dfc53380d13650a7354766a0abb81c2c92e92722c85a2bfe8a1a81a664bc24b8b70c76c51a3d192e819d6990624f40e3585106aa07019a4c1161e376c082748774c34b0bcb5391c0cb34ed8aa4a5b9cca4f682e6ff3748f82ee78a5636f84c878148cc7020890befffaa4506cebbef9a3f7c67178f2"
62text hseed "6a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19"
63text hhex "0123456789abcdef"
64
65fn hnibble c uchar to uint
66if le c 57
67ret uint sub c 48
68end
69ret uint sub c 87
70end
71
72fn hreset to void
73for i ulong 64
74v = uint 0
75for j ulong 8
76v = or shl v 4 hnibble get hconst add mul i 8 j
77end
78put hk i v
79end
80for i ulong 8
81v = uint 0
82for j ulong 8
83v = or shl v 4 hnibble get hseed add mul i 8 j
84end
85put hs i v
86end
87for i ulong 3
88put hmeta i 0
89end
90end
91
92fn hrot x uint n uint to uint
93ret or shr x n shl x sub 32 n
94end
95
96fn hsmall0 x uint to uint
97ret xor xor hrot x 7 hrot x 18 shr x 3
98end
99
100fn hsmall1 x uint to uint
101ret xor xor hrot x 17 hrot x 19 shr x 10
102end
103
104fn hbig0 x uint to uint
105ret xor xor hrot x 2 hrot x 13 hrot x 22
106end
107
108fn hbig1 x uint to uint
109ret xor xor hrot x 6 hrot x 11 hrot x 25
110end
111
112fn hblock to void
113for i ulong 16
114v = uint 0
115for j ulong 4
116v = or shl v 8 uint get hb add mul i 4 j
117end
118put hm i v
119end
120for j ulong 48
121i = add j 16
122v = add hsmall1 get hm sub i 2 get hm sub i 7
123v = add v hsmall0 get hm sub i 15
124put hm i add v get hm sub i 16
125end
126a = get hs 0
127b = get hs 1
128c = get hs 2
129d = get hs 3
130e = get hs 4
131f = get hs 5
132g = get hs 6
133h = get hs 7
134for i ulong 64
135t1 = add h hbig1 e
136t1 = add t1 xor and e f and not e g
137t1 = add t1 get hk i
138t1 = add t1 get hm i
139t2 = hbig0 a
140t2 = add t2 xor xor and a b and a c and b c
141h = g
142g = f
143f = e
144e = add d t1
145d = c
146c = b
147b = a
148a = add t1 t2
149end
150put hs 0 add get hs 0 a
151put hs 1 add get hs 1 b
152put hs 2 add get hs 2 c
153put hs 3 add get hs 3 d
154put hs 4 add get hs 4 e
155put hs 5 add get hs 5 f
156put hs 6 add get hs 6 g
157put hs 7 add get hs 7 h
158end
159
160fn hraw c uchar to void
161n = get hmeta 0
162put hb n c
163n = add n 1
164if eq n 64
165hblock
166n = ulong 0
167end
168put hmeta 0 n
169end
170
171fn hpush c uchar to bool
172if ne get hmeta 2 0
173ret false
174end
175if eq get hmeta 1 2305843009213693951
176put hmeta 2 2
177ret false
178end
179hraw c
180put hmeta 1 add get hmeta 1 1
181ret true
182end
183
184fn hfinal to bool
185if ne get hmeta 2 0
186ret false
187end
188bits = mul get hmeta 1 8
189hraw 128
190while ne get hmeta 0 56
191hraw 0
192end
193for i ulong 8
194shift = mul sub 7 i 8
195hraw uchar and shr bits shift 255
196end
197for i ulong 8
198v = get hs i
199for j ulong 8
200shift = uint mul sub 7 j 4
201digit = ulong and shr v shift 15
202put hd add mul i 8 j get hhex digit
203end
204end
205put hmeta 2 1
206ret true
207end
208
209note ---- input, mode, lines ----
210
211fn readall to int
212more = true
213while more
214n = read 0 big get irlen 0 sub 1048576 get irlen 0
215if eq n -4
216else
217if lt n 0
218ret 74
219end
220if eq n 0
221more = false
222else
223put irlen 0 add get irlen 0 ulong n
224if ge get irlen 0 1048576
225n2 = read 0 hb 0 1
226while eq n2 -4
227n2 = read 0 hb 0 1
228end
229if gt n2 0
230ret 65
231end
232if lt n2 0
233ret 74
234end
235more = false
236end
237end
238end
239end
240ret 0
241end
242
243fn findnl from ulong to ulong
244i = from
245while lt i get irlen 0
246if eq get big i 10
247ret i
248end
249i = add i 1
250end
251ret get irlen 0
252end
253
254fn modeis o ulong n ulong t ulong to bool
255if eq t 1
256if ne n 2
257ret false
258end
259if ne get big o 105
260ret false
261end
262ret eq get big add o 1 100
263end
264if eq t 2
265if ne n 5
266ret false
267end
268if ne get big o 99
269ret false
270end
271if ne get big add o 1 104
272ret false
273end
274if ne get big add o 2 101
275ret false
276end
277if ne get big add o 3 99
278ret false
279end
280ret eq get big add o 4 107
281end
282if eq t 3
283if ne n 8
284ret false
285end
286if ne get big o 109
287ret false
288end
289if ne get big add o 1 97
290ret false
291end
292if ne get big add o 2 110
293ret false
294end
295if ne get big add o 3 105
296ret false
297end
298if ne get big add o 4 102
299ret false
300end
301if ne get big add o 5 101
302ret false
303end
304if ne get big add o 6 115
305ret false
306end
307ret eq get big add o 7 116
308end
309if eq t 4
310if ne n 6
311ret false
312end
313if ne get big o 115
314ret false
315end
316if ne get big add o 1 104
317ret false
318end
319if ne get big add o 2 97
320ret false
321end
322if ne get big add o 3 50
323ret false
324end
325if ne get big add o 4 53
326ret false
327end
328ret eq get big add o 5 54
329end
330ret false
331end
332
333fn runmode to ulong
334e = findnl 0
335if lt e 5
336ret 0
337end
338if ne get big 0 109
339ret 0
340end
341if ne get big 1 111
342ret 0
343end
344if ne get big 2 100
345ret 0
346end
347if ne get big 3 101
348ret 0
349end
350if ne get big 4 61
351ret 0
352end
353v = ulong 5
354n = sub e v
355if modeis v n 1
356ret 1
357end
358if modeis v n 2
359ret 2
360end
361if modeis v n 3
362ret 3
363end
364if modeis v n 4
365ret 4
366end
367ret 0
368end
369
370fn splp to void
371st = get pstart 0
372n = ulong 0
373i = st
374while lt i get irlen 0
375if eq get big i 10
376if ge n 256
377put nline 0 257
378ret
379end
380put pofs n st
381put plen n sub i st
382n = add n 1
383st = add i 1
384end
385i = add i 1
386end
387if lt st get irlen 0
388if ge n 256
389put nline 0 257
390ret
391end
392put pofs n st
393put plen n sub get irlen 0 st
394n = add n 1
395end
396put nline 0 n
397end
398
399fn schlen s ulong to ulong
400if eq s 0
401ret len schm0
402end
403ret len schm1
404end
405
406fn schbyte s ulong i ulong to uchar
407if eq s 0
408ret get schm0 i
409end
410ret get schm1 i
411end
412
413fn schsplit s ulong to void
414L = schlen s
415st = ulong 0
416n = ulong 0
417i = ulong 0
418while lt i L
419if eq schbyte s i 10
420put sofs n st
421put slen n sub i st
422n = add n 1
423st = add i 1
424end
425i = add i 1
426end
427if lt st L
428put sofs n st
429put slen n sub L st
430n = add n 1
431end
432put nsch 0 n
433end
434
435note ---- payload / schema line helpers ----
436
437fn peq i ulong s ulong to bool
438if ne get plen i get slen i
439ret false
440end
441j = ulong 0
442while lt j get plen i
443if ne get big add get pofs i j schbyte s add get sofs i j
444ret false
445end
446j = add j 1
447end
448ret true
449end
450
451fn klen i ulong to ulong
452j = ulong 0
453while lt j get plen i
454if eq get big add get pofs i j 61
455ret j
456end
457j = add j 1
458end
459ret j
460end
461
462fn haseq i ulong to bool
463ret lt klen i get plen i
464end
465
466fn vlen i ulong to ulong
467n = klen i
468if ge n get plen i
469ret 0
470end
471ret sub get plen i add n 1
472end
473
474fn sklen s ulong j ulong to ulong
475o = get sofs j
476L = get slen j
477q = ulong 0
478while lt q L
479if eq schbyte s add o q 61
480ret q
481end
482q = add q 1
483end
484ret L
485end
486
487fn keysame i ulong s ulong j ulong to bool
488n = klen i
489if ne n sklen s j
490ret false
491end
492q = ulong 0
493while lt q n
494if ne get big add get pofs i q schbyte s add get sofs j q
495ret false
496end
497q = add q 1
498end
499ret true
500end
501
502fn findpk s ulong j ulong to bool
503i = ulong 0
504while lt i get nline 0
505if keysame i s j
506ret true
507end
508i = add i 1
509end
510ret false
511end
512
513fn findpkey s ulong i ulong to bool
514j = ulong 0
515while lt j get nsch 0
516if keysame i s j
517ret true
518end
519j = add j 1
520end
521ret false
522end
523
524fn isdtype s ulong i ulong to bool
525if lt get slen i 2
526ret false
527end
528if ne schbyte s get sofs i 100
529ret false
530end
531ret eq schbyte s add get sofs i 1 116
532end
533
534fn islayout s ulong i ulong to bool
535ret eq schbyte s get sofs i 108
536end
537
538fn isstride s ulong i ulong to bool
539o = get sofs i
540L = get slen i
541if lt L 6
542ret false
543end
544q = ulong 0
545while le add q 6 L
546if eq schbyte s add o q 115
547if eq schbyte s add o add q 1 116
548if eq schbyte s add o add q 2 114
549if eq schbyte s add o add q 3 105
550if eq schbyte s add o add q 4 100
551if eq schbyte s add o add q 5 101
552ret true
553end
554end
555end
556end
557end
558end
559q = add q 1
560end
561ret false
562end
563
564fn istol s ulong i ulong to bool
565if lt get slen i 2
566ret false
567end
568if ne schbyte s get sofs i 116
569ret false
570end
571ret eq schbyte s add get sofs i 1 111
572end
573
574fn vbyte i ulong q ulong to uchar
575ret get big add add get pofs i add klen i 1 q
576end
577
578fn veqt i ulong t ulong to bool
579n = vlen i
580if eq n 0
581ret false
582end
583if eq t 0
584if ne n len mid
585ret false
586end
587j = ulong 0
588while lt j n
589if ne vbyte i j get mid j
590ret false
591end
592j = add j 1
593end
594ret true
595end
596if eq t 1
597if ne n len gid
598ret false
599end
600j = ulong 0
601while lt j n
602if ne vbyte i j get gid j
603ret false
604end
605j = add j 1
606end
607ret true
608end
609if eq t 2
610if ne n len omth
611ret false
612end
613j = ulong 0
614while lt j n
615if ne vbyte i j get omth j
616ret false
617end
618j = add j 1
619end
620ret true
621end
622if eq t 3
623if ne n len ogqa
624ret false
625end
626j = ulong 0
627while lt j n
628if ne vbyte i j get ogqa j
629ret false
630end
631j = add j 1
632end
633ret true
634end
635ret false
636end
637
638fn valcmp i ulong j ulong to bool
639n1 = vlen i
640if eq n1 0
641ret false
642end
643if ne n1 vlen j
644ret false
645end
646q = ulong 0
647while lt q n1
648if ne vbyte i q vbyte j q
649ret false
650end
651q = add q 1
652end
653ret true
654end
655
656fn pclass i ulong s ulong to ulong
657if peq i s
658ret 0
659end
660if eq get plen i 0
661ret 4
662end
663if not haseq i
664ret 2
665end
666if keysame i s i
667if isdtype s i
668ret 7
669end
670if islayout s i
671ret 8
672end
673if isstride s i
674ret 8
675end
676if istol s i
677ret 6
678end
679ret 3
680end
681if findpkey s i
682ret 2
683end
684ret 5
685end
686
687fn docheck to ulong
688schsplit 0
689if gt get nline 0 256
690ret 3
691end
692if lt get nline 0 1
693ret 1
694end
695if eq get irlen 0 get pstart 0
696ret 3
697end
698if ne get big sub get irlen 0 1 10
699ret 2
700end
701if not peq 0 0
702ret 1
703end
704if lt get nline 0 2
705ret 4
706end
707if not keysame 1 0 1
708ret 2
709end
710s = ulong 9
711if veqt 1 2
712s = ulong 0
713else
714if veqt 1 3
715s = ulong 1
716else
717ret 3
718end
719end
720schsplit s
721if lt get nline 0 get nsch 0
722ret 4
723end
724j = ulong 0
725while lt j get nsch 0
726if not findpk s j
727ret 4
728end
729j = add j 1
730end
731i = ulong 0
732while lt i get nsch 0
733c = pclass i s
734if ne c 0
735ret c
736end
737i = add i 1
738end
739while lt i get nline 0
740if eq get plen i 0
741ret 2
742end
743if not haseq i
744ret 2
745end
746if findpkey s i
747ret 2
748end
749ret 5
750end
751ret 0
752end
753
754note ---- manifest ----
755
756fn packn o ulong n ulong to ulong
757v = ulong 0
758j = ulong 0
759while lt j n
760v = or shl v 8 ulong get big add o j
761j = add j 1
762end
763ret v
764end
765
766fn keyis i ulong t ulong to bool
767n = klen i
768o = get pofs i
769if eq t 1
770if ne n 6
771ret false
772end
773ret eq packn o 6 111567956173684
774end
775if eq t 2
776if ne n 2
777ret false
778end
779ret eq packn o 2 28528
780end
781if eq t 3
782if ne n 8
783ret false
784end
785ret eq packn o 8 7165066978583995252
786end
787if eq t 4
788if ne n 7
789ret false
790end
791ret eq packn o 7 28826413695332965
792end
793if eq t 5
794if ne n 12
795ret false
796end
797if ne packn o 8 7597133271186502504
798ret false
799end
800ret eq packn add o 8 4 1630680374
801end
802if eq t 6
803if ne n 4
804ret false
805end
806ret eq packn o 4 1936024932
807end
808if eq t 7
809if ne n 5
810ret false
811end
812ret eq packn o 5 427071729268
813end
814if eq t 8
815if ne n 11
816ret false
817end
818if ne packn o 8 8097887111620944991
819ret false
820end
821ret eq packn add o 8 3 6841720
822end
823ret false
824end
825
826fn hdigit c uchar to bool
827if ge c 48
828if le c 57
829ret true
830end
831end
832if ge c 97
833if le c 102
834ret true
835end
836end
837ret false
838end
839
840fn hval c uchar to uchar
841if le c 57
842ret uchar sub c 48
843end
844ret uchar sub c 87
845end
846
847fn hex64 i ulong to bool
848if not haseq i
849ret false
850end
851if ne vlen i 64
852ret false
853end
854j = ulong 0
855while lt j 64
856if not hdigit vbyte i j
857ret false
858end
859j = add j 1
860end
861ret true
862end
863
864fn decok i ulong lim ulong to bool
865if not haseq i
866ret false
867end
868n = vlen i
869if eq n 0
870ret false
871end
872v = ulong 0
873j = ulong 0
874while lt j n
875c = vbyte i j
876if or lt c 48 gt c 57
877ret false
878end
879d = ulong sub c 48
880if gt v div sub lim d 10
881ret false
882end
883v = add mul v 10 d
884j = add j 1
885end
886ret true
887end
888
889fn nameok i ulong to bool
890if not haseq i
891ret false
892end
893n = vlen i
894if eq n 0
895ret false
896end
897if gt n 64
898ret false
899end
900j = ulong 0
901while lt j n
902c = vbyte i j
903ok = false
904if ge c 65
905if le c 90
906ok = true
907end
908end
909if ge c 97
910if le c 122
911ok = true
912end
913end
914if ge c 48
915if le c 57
916ok = true
917end
918end
919if eq c 46
920ok = true
921end
922if eq c 95
923ok = true
924end
925if eq c 45
926ok = true
927end
928if not ok
929ret false
930end
931j = add j 1
932end
933ret true
934end
935
936fn mfind t ulong to bool
937i = ulong 0
938while lt i get nline 0
939if keyis i t
940ret true
941end
942i = add i 1
943end
944ret false
945end
946
947fn mhdrline to bool
948if ne get plen 1 len mhdr
949ret false
950end
951j = ulong 0
952while lt j len mhdr
953if ne get big add get pofs 1 j get mhdr j
954ret false
955end
956j = add j 1
957end
958ret true
959end
960
961fn hashhexline i ulong to bool
962if not haseq i
963ret false
964end
965n = vlen i
966if eq n 0
967ret false
968end
969if ne and n 1 0
970ret false
971end
972hreset
973j = ulong 0
974while lt j n
975c1 = vbyte i j
976c2 = vbyte i add j 1
977if not hdigit c1
978ret false
979end
980if not hdigit c2
981ret false
982end
983b = uchar add shl hval c1 4 hval c2
984if not hpush b
985ret false
986end
987j = add j 2
988end
989ret hfinal
990end
991
992fn hdeqline i ulong to bool
993if ne vlen i 64
994ret false
995end
996j = ulong 0
997while lt j 64
998if ne get hd j vbyte i j
999ret false
1000end
1001j = add j 1
1002end
1003ret true
1004end
1005
1006fn domain to ulong
1007if lt get nline 0 2
1008ret 1
1009end
1010if eq get irlen 0 get pstart 0
1011ret 1
1012end
1013if ne get big sub get irlen 0 1 10
1014ret 2
1015end
1016if not keyis 0 1
1017ret 1
1018end
1019if not mhdrline
1020ret 1
1021end
1022if lt get nline 0 8
1023ret 4
1024end
1025if gt get nline 0 9
1026ret 5
1027end
1028t = ulong 2
1029while le t 7
1030if not mfind t
1031ret 4
1032end
1033t = add t 1
1034end
1035t = ulong 2
1036while le t 7
1037if not keyis t t
1038ret 2
1039end
1040t = add t 1
1041end
1042if eq get nline 0 9
1043if not keyis 8 8
1044ret 5
1045end
1046end
1047if not hex64 0
1048ret 3
1049end
1050if not hex64 3
1051ret 3
1052end
1053if not hex64 5
1054ret 3
1055end
1056if not veqt 2 2
1057if not veqt 2 3
1058ret 3
1059end
1060end
1061if not veqt 3 0
1062if not veqt 3 1
1063ret 3
1064end
1065end
1066if not valcmp 3 0
1067ret 9
1068end
1069if veqt 2 2
1070if not veqt 3 0
1071ret 9
1072end
1073end
1074if veqt 2 3
1075if not veqt 3 1
1076ret 9
1077end
1078end
1079if not nameok 4
1080ret 3
1081end
1082if not decok 6 18446744073709551615
1083ret 3
1084end
1085if not decok 7 4294967295
1086ret 3
1087end
1088if eq get nline 0 9
1089if not hashhexline 8
1090ret 3
1091end
1092if not hdeqline 5
1093ret 3
1094end
1095end
1096ret 0
1097end
1098
1099note ---- output ----
1100
1101fn wokhex to bool
1102w = write 1 okmsg 0 len okmsg
1103if ne ulong w len okmsg
1104ret false
1105end
1106w = write 1 hd 0 64
1107if ne ulong w 64
1108ret false
1109end
1110w = write 1 newln 0 1
1111ret eq ulong w 1
1112end
1113
1114fn whex to bool
1115w = write 1 hd 0 64
1116if ne ulong w 64
1117ret false
1118end
1119w = write 1 newln 0 1
1120ret eq ulong w 1
1121end
1122
1123fn wslice off ulong n ulong to bool
1124p = off
1125e = add off n
1126while lt p e
1127w = write 1 big p sub e p
1128if le w 0
1129ret false
1130end
1131p = add p ulong w
1132end
1133ret true
1134end
1135
1136fn wmanok to bool
1137w = write 1 okmsg 0 len okmsg
1138if ne ulong w len okmsg
1139ret false
1140end
1141if not wslice add get pofs 3 add klen 3 1 64
1142ret false
1143end
1144w = write 1 newln 0 1
1145ret eq ulong w 1
1146end
1147
1148fn eref c ulong to void
1149w = write 1 refmsg 0 len refmsg
1150if eq c 1
1151w = write 1 ehead 0 len ehead
1152end
1153if eq c 2
1154w = write 1 eorder 0 len eorder
1155end
1156if eq c 3
1157w = write 1 evalue 0 len evalue
1158end
1159if eq c 4
1160w = write 1 emiss 0 len emiss
1161end
1162if eq c 5
1163w = write 1 eunknown 0 len eunknown
1164end
1165if eq c 6
1166w = write 1 etol 0 len etol
1167end
1168if eq c 7
1169w = write 1 edtype 0 len edtype
1170end
1171if eq c 8
1172w = write 1 elayout 0 len elayout
1173end
1174if eq c 9
1175w = write 1 etarget 0 len etarget
1176end
1177end
1178
1179fn hashpay to bool
1180hreset
1181i = get pstart 0
1182while lt i get irlen 0
1183if not hpush get big i
1184ret false
1185end
1186i = add i 1
1187end
1188ret hfinal
1189end
1190
1191fn main to int
1192r = readall
1193if ne r 0
1194ret r
1195end
1196m = runmode
1197if eq m 0
1198eref 1
1199ret 1
1200end
1201e = findnl 0
1202if lt e get irlen 0
1203put pstart 0 add e 1
1204else
1205put pstart 0 get irlen 0
1206end
1207splp
1208if eq m 1
1209if not hashpay
1210ret 65
1211end
1212if not whex
1213ret 74
1214end
1215ret 0
1216end
1217if eq m 4
1218if not hashpay
1219ret 65
1220end
1221if not whex
1222ret 74
1223end
1224ret 0
1225end
1226if eq m 2
1227c = docheck
1228if eq c 0
1229if not hashpay
1230ret 65
1231end
1232if not wokhex
1233ret 74
1234end
1235ret 0
1236end
1237eref c
1238ret 1
1239end
1240if eq m 3
1241c = domain
1242if eq c 0
1243if not wmanok
1244ret 74
1245end
1246ret 0
1247end
1248eref c
1249ret 1
1250end
1251eref 1
1252ret 1
1253end