interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / text / tests / gen.om

1424 lines · 20145 bytes Raw Blame History
1om2
2note seed/text/tests/gen.om: the cases and their expected answers for seed/text/text.om, in seeded Omega.
3note Usage: gen OUTDIR. Writes OUTDIR/cases-K.bin and OUTDIR/want-K.txt, K = 0, 1, ..., then prints
4note "cases files=N". It replaces tests/gen.py (Python) and writes the same bytes for the same rows.
5note The answers are computed here by separate plain code (byte loops, digit-string comparison against
6note the range limits, the Unicode table 3-7 of well-formed UTF-8), never by text.om, so a rule that
7note text.om gets wrong shows as a mismatch. The random cases come from MT19937 seeded with 20261108
8note the way CPython seeds random.Random(20261108), drawn the way CPython 3.12 draws them
9note (getrandbits by 32-bit words, _randbelow by rejection, random() from two words), so the rows are
10note the ones gen.py wrote. Record layout (txdrv.om): op byte; byte strings as u32 little-endian
11note length + bytes; numbers u64 little-endian. Every write is checked: a failure exits 80.
12
13const LIMIT ulong 2900000
14const NONE ulong 18446744073709551615
15note random() < p is a53 * 2^-53 < p, with a53 = (w1 >> 5) * 2^26 + (w2 >> 6): exactly a53 < ceil(p * 2^53)
16note for the binary64 p (WolframLanguageEvaluator Ceiling[SetPrecision[p, Infinity]*2^53]).
17const T30 ulong 2702159776422298
18const T05 ulong 450359962737050
19const T50 ulong 4503599627370496
20const T20 ulong 1801439850948199
21
22text tcase "/cases-"
23text twant "/want-"
24text tbin ".bin"
25text ttxt ".txt"
26text tfiles "cases files="
27text terr "err "
28text tok "ok "
29text tneedle "needle"
30text tneedlx "needlex"
31text t25 "0123456789abcdefABCDEF-+ "
32text tu64 "18446744073709551615"
33text ti63p "9223372036854775807"
34text ti63n "9223372036854775808"
35text tedge "|0|00|1|18446744073709551615|18446744073709551616|18446744073709551619|18446744073709551620|99999999999999999999|000000000000000000000018446744073709551615|1x|x| 1|1 |+1|-|-0|-1|9223372036854775807|9223372036854775808|-9223372036854775808|-9223372036854775809|--1|1-|ffffffffffffffff|FFFFFFFFFFFFFFFF|10000000000000000|0fffffffffffffffF|g|0x10|99999999999999999999x"
36
37global cb uchar 2900000
38global cn ulong 1
39global wb uchar 1048576
40global wn ulong 1
41global wfd long 1
42global nf ulong 1
43global od uchar 4096
44global odn ulong 1
45global pb uchar 4200
46global pn ulong 1
47global nb uchar 24
48global ft uchar 72
49global ftn ulong 1
50global eb uchar 4
51global mt uint 624
52global mi ulong 1
53global ga uchar 262144
54global gb uchar 262144
55global gl ulong 2
56
57fn ck yes bool to void
58if not yes
59exit 80
60end
61end
62
63note ======== MT19937, seeded as CPython's init_by_array with the one key word 20261108
64fn mtseed to void
65put mt 0 uint 19650218
66for i ulong 623
67p = get mt i
68put mt add i 1 add mul 1812433253 xor p shr p 30 uint add i 1
69end
70i = ulong 1
71for c1 ulong 624
72p = get mt sub i 1
73put mt i add xor get mt i mul xor p shr p 30 1664525 uint 20261108
74i = add i 1
75if ge i 624
76put mt 0 get mt 623
77i = 1
78end
79end
80for c2 ulong 623
81p = get mt sub i 1
82put mt i sub xor get mt i mul xor p shr p 30 1566083941 uint i
83i = add i 1
84if ge i 624
85put mt 0 get mt 623
86i = 1
87end
88end
89put mt 0 0x80000000
90put mi 0 624
91end
92
93fn mtgen to void
94for k ulong 624
95y = or and get mt k 0x80000000 and get mt rem add k 1 624 0x7fffffff
96v = xor get mt rem add k 397 624 shr y 1
97if ne and y 1 0
98v = xor v 0x9908b0df
99end
100put mt k v
101end
102put mi 0 0
103end
104
105fn rnd32 to uint
106if ge get mi 0 624
107mtgen
108end
109i = get mi 0
110y = get mt i
111put mi 0 add i 1
112y = xor y shr y 11
113y = xor y and shl y 7 0x9d2c5680
114y = xor y and shl y 15 0xefc60000
115y = xor y shr y 18
116ret y
117end
118
119note getrandbits(k) for k 1..32
120fn rbits k ulong to ulong
121ret ulong shr rnd32 sub 32 k
122end
123
124fn blen n ulong to ulong
125k = ulong 0
126x = n
127while gt x 0 bound 65
128x = shr x 1
129k = add k 1
130end
131ret k
132end
133
134note _randbelow(n), n 1 .. 2^32 - 1: getrandbits(bit_length n) until below n
135fn rbelow n ulong to ulong
136k = blen n
137r = rbits k
138while ge r n bound 1000000
139r = rbits k
140end
141ret r
142end
143
144note _randbelow(2^64): getrandbits(65) is three words, low first, the third shifted right by 31
145fn r64 to ulong
146w0 = ulong rnd32
147w1 = ulong rnd32
148w2 = shr rnd32 31
149while ne w2 0 bound 1000000
150w0 = ulong rnd32
151w1 = ulong rnd32
152w2 = shr rnd32 31
153end
154ret or w0 shl w1 32
155end
156
157note random() as the 53-bit integer a53 (see T30)
158fn rrand to ulong
159a = ulong shr rnd32 5
160b = ulong shr rnd32 6
161ret add mul a 67108864 b
162end
163
164note ======== output: want lines go through wb to the open want file, records into cb
165fn dig v ulong to ulong
166x = v
167i = ulong 0
168put nb i uchar add rem x 10 48
169x = div x 10
170i = add i 1
171while gt x 0 bound 20
172put nb i uchar add rem x 10 48
173x = div x 10
174i = add i 1
175end
176ret i
177end
178
179fn wb1 c uchar to void
180n = get wn 0
181put wb n c
182put wn 0 add n 1
183end
184
185fn wtx t view uchar * to void
186for i ulong len t
187wb1 get t i
188end
189end
190
191fn wnum v ulong to void
192i = dig v
193while gt i 0 bound 20
194i = sub i 1
195wb1 get nb i
196end
197end
198
199fn wop c uchar to void
200wb1 c
201wb1 32
202end
203
204fn wflush to void
205fd = int sub get wfd 0 1
206n = get wn 0
207off = ulong 0
208while lt off n bound 1000000
209w = write fd wb off sub n off
210ck gt w 0
211off = add off ulong w
212end
213put wn 0 0
214end
215
216fn wend to void
217wb1 10
218if gt get wn 0 1040000
219wflush
220end
221end
222
223fn cb1 c uchar to void
224n = get cn 0
225put cb n c
226put cn 0 add n 1
227end
228
229fn cbn v ulong k ulong to void
230for i ulong k
231cb1 uchar and shr v mul i 8 255
232end
233end
234
235fn cbga n ulong to void
236for i ulong n
237cb1 get ga i
238end
239end
240
241fn cbgb n ulong to void
242for i ulong n
243cb1 get gb i
244end
245end
246
247fn pb1 c uchar to void
248n = get pn 0
249put pb n c
250put pn 0 add n 1
251end
252
253fn pbtx t view uchar * to void
254for i ulong len t
255pb1 get t i
256end
257end
258
259note mkpath kind: OUTDIR/cases-K.bin (kind 0) or OUTDIR/want-K.txt (kind 1) into pb; its length
260fn mkpath kind ulong to ulong
261put pn 0 0
262for i ulong get odn 0
263pb1 get od i
264end
265if eq kind 0
266pbtx tcase
267else
268pbtx twant
269end
270j = dig get nf 0
271while gt j 0 bound 20
272j = sub j 1
273pb1 get nb j
274end
275if eq kind 0
276pbtx tbin
277else
278pbtx ttxt
279end
280ret get pn 0
281end
282
283fn openw to void
284n = mkpath 1
285fd = fopen pb 0 n 577 420
286ck ge fd 0
287put wfd 0 add fd 1
288end
289
290fn flush to void
291n = get cn 0
292if eq n 0
293ret
294end
295p = mkpath 0
296fd = int fopen pb 0 p 577 420
297ck ge fd 0
298off = ulong 0
299while lt off n bound 1000000
300w = write fd cb off sub n off
301ck gt w 0
302off = add off ulong w
303end
304ck eq fclose fd 0
305put cn 0 0
306wflush
307ck eq fclose int sub get wfd 0 1 0
308put wfd 0 0
309put nf 0 add get nf 0 1
310end
311
312note reserve L: start a new cases file first when this record of L bytes would pass LIMIT
313fn reserve l ulong to void
314if gt add get cn 0 l LIMIT
315flush
316end
317if eq get wfd 0 0
318openw
319end
320end
321
322note ======== bytes: equality and order
323fn cmpab la ulong lb ulong to ulong
324m = la
325if lt lb m
326m = lb
327end
328for i ulong m
329x = get ga i
330y = get gb i
331if ne x y
332if lt x y
333ret 0
334end
335ret 2
336end
337end
338if lt la lb
339ret 0
340end
341if gt la lb
342ret 2
343end
344ret 1
345end
346
347fn cmpcase to void
348la = get gl 0
349lb = get gl 1
350reserve add add 9 la lb
351cb1 69
352cbn la 4
353cbga la
354cbn lb 4
355cbgb lb
356c = cmpab la lb
357wop 69
358if eq c 1
359wb1 49
360else
361wb1 48
362end
363wb1 32
364if eq c 0
365wb1 45
366wb1 49
367else
368if eq c 1
369wb1 48
370else
371wb1 49
372end
373end
374wend
375end
376
377note ======== search
378fn same i ulong lb ulong to bool
379for j ulong lb
380if ne get ga add i j get gb j
381ret false
382end
383end
384ret true
385end
386
387fn findat la ulong lb ulong frm ulong to ulong
388if gt frm la
389ret NONE
390end
391if gt lb sub la frm
392ret NONE
393end
394stop = sub la lb
395i = frm
396while le i stop bound 1000000
397if same i lb
398ret i
399end
400i = add i 1
401end
402ret NONE
403end
404
405fn findcase frm ulong to void
406la = get gl 0
407lb = get gl 1
408reserve add add 17 la lb
409cb1 70
410cbn la 4
411cbga la
412cbn lb 4
413cbgb lb
414cbn frm 8
415r = findat la lb frm
416wop 70
417if eq r NONE
418wb1 110
419else
420wnum r
421end
422wend
423end
424
425note ======== fields
426fn splcase sep uchar to void
427la = get gl 0
428reserve add 6 la
429cb1 83
430cbn la 4
431cbga la
432cb1 sep
433wop 83
434cnt = ulong 1
435for i ulong la
436if eq get ga i sep
437cnt = add cnt 1
438end
439end
440wnum cnt
441p = ulong 0
442for j ulong la
443if eq get ga j sep
444wb1 32
445wnum sub j p
446p = add j 1
447end
448end
449wb1 32
450wnum sub la p
451wend
452end
453
454note ======== integer text
455fn isdig c uchar to bool
456ret and ge c 48 le c 57
457end
458
459fn ishex c uchar to bool
460ret or isdig c or and ge c 97 le c 102 and ge c 65 le c 70
461end
462
463fn hexval c uchar to ulong
464if le c 57
465ret ulong sub c 48
466end
467if ge c 97
468ret ulong sub c 87
469end
470ret ulong sub c 55
471end
472
473note digover z nd t: the digits ga[z .. z+nd), no leading zero, are a number above the digits of t
474fn digover z ulong nd ulong t view uchar * to bool
475if ne nd len t
476ret gt nd len t
477end
478for i ulong nd
479x = get ga add z i
480y = get t i
481if ne x y
482ret gt x y
483end
484end
485ret false
486end
487
488note pform op s: every byte of ga[s ..) has the form of op (decimal digits, or hex digits for H), and
489note there is at least one
490fn pform op uchar s ulong to bool
491la = get gl 0
492ok = gt la s
493i = s
494while lt i la bound 1000000
495g = isdig get ga i
496if eq op 72
497g = ishex get ga i
498end
499if not g
500ok = false
501end
502i = add i 1
503end
504ret ok
505end
506
507note pover op ng z: the digits ga[z ..), no leading zero, are out of range for op (ng: after a '-')
508fn pover op uchar ng bool z ulong to bool
509nd = sub get gl 0 z
510if eq op 72
511ret gt nd 16
512end
513if eq op 68
514ret digover z nd tu64
515end
516if ng
517ret digover z nd ti63n
518end
519ret digover z nd ti63p
520end
521
522fn pvalue base ulong z ulong to ulong
523la = get gl 0
524v = ulong 0
525j = z
526while lt j la bound 1000000
527v = add mul v base hexval get ga j
528j = add j 1
529end
530ret v
531end
532
533note pres op: the answer after "D ", "H " or "I ": err 1 empty, err 2 a byte outside the form, err 3 out
534note of range, else ok and the value
535fn pres op uchar to void
536la = get gl 0
537if eq la 0
538wtx terr
539wb1 49
540ret
541end
542s = ulong 0
543ng = false
544if and eq op 73 eq get ga 0 45
545ng = true
546s = 1
547end
548if not pform op s
549wtx terr
550wb1 50
551ret
552end
553z = s
554while and lt z la eq get ga z 48 bound 1000000
555z = add z 1
556end
557if pover op ng z
558wtx terr
559wb1 51
560ret
561end
562base = ulong 10
563if eq op 72
564base = 16
565end
566v = pvalue base z
567wtx tok
568if and ng ne v 0
569wb1 45
570end
571wnum v
572end
573
574fn parcase op uchar to void
575la = get gl 0
576reserve add 5 la
577cb1 op
578cbn la 4
579cbga la
580wop op
581pres op
582wend
583end
584
585fn par3 to void
586parcase 68
587parcase 72
588parcase 73
589end
590
591note ======== number text: ft gets the text, ftn its length
592fn fdec v ulong to void
593n = dig v
594for i ulong n
595put ft i get nb sub sub n i 1
596end
597put ftn 0 n
598end
599
600fn fsig u ulong to void
601if lt u 0x8000000000000000
602fdec u
603ret
604end
605m = sub 0 u
606n = dig m
607put ft 0 45
608for i ulong n
609put ft add i 1 get nb sub sub n i 1
610end
611put ftn 0 add n 1
612end
613
614fn fhex v ulong w ulong to void
615n = ulong 1
616x = shr v 4
617while gt x 0 bound 16
618n = add n 1
619x = shr x 4
620end
621if lt n w
622n = w
623end
624x = v
625j = n
626while gt j 0 bound 64
627j = sub j 1
628d = uchar and x 15
629c = add d 48
630if gt d 9
631c = add d 87
632end
633put ft j c
634x = shr x 4
635end
636put ftn 0 n
637end
638
639fn fmtcase op uchar v ulong w ulong cap ulong to void
640reserve 25
641cb1 op
642cbn v 8
643cbn w 8
644cbn cap 8
645if eq op 102
646fdec v
647end
648if eq op 120
649fhex v w
650end
651if eq op 103
652fsig v
653end
654wop op
655n = get ftn 0
656if gt n cap
657wb1 69
658else
659for i ulong n
660wb1 get ft i
661end
662end
663wend
664end
665
666fn fmtx v ulong w ulong to void
667fhex v w
668l = get ftn 0
669fmtcase 120 v w sub l 1
670fmtcase 120 v w 16
671fmtcase 120 v w 64
672end
673
674fn fmtv v ulong to void
675fdec v
676l = get ftn 0
677fmtcase 102 v 0 0
678fmtcase 102 v 0 1
679fmtcase 102 v 0 sub l 1
680fmtcase 102 v 0 l
681fmtcase 102 v 0 20
682fmtcase 102 v 0 64
683fmtx v 0
684fmtx v 1
685fmtx v 8
686fmtx v 16
687end
688
689fn fmtg u ulong to void
690fsig u
691l = get ftn 0
692fmtcase 103 u 0 sub l 1
693fmtcase 103 u 0 l
694fmtcase 103 u 0 64
695end
696
697note ======== UTF-8 (Unicode table 3-7): sequence length by lead byte (0: never a lead), second-byte range
698fn u8need c uchar to ulong
699if lt c 0x80
700ret 1
701end
702if lt c 0xc2
703ret 0
704end
705if lt c 0xe0
706ret 2
707end
708if lt c 0xf0
709ret 3
710end
711if lt c 0xf5
712ret 4
713end
714ret 0
715end
716
717fn u8lo c uchar to uchar
718if eq c 0xe0
719ret 0xa0
720end
721if eq c 0xf0
722ret 0x90
723end
724ret 0x80
725end
726
727fn u8hi c uchar to uchar
728if eq c 0xed
729ret 0x9f
730end
731if eq c 0xf4
732ret 0x8f
733end
734ret 0xbf
735end
736
737note u8bad i k: the k-byte sequence led at ga[i] has a byte outside its range (all k bytes present)
738fn u8bad i ulong k ulong to bool
739c = get ga i
740s = get ga add i 1
741if or lt s u8lo c gt s u8hi c
742ret true
743end
744j = ulong 2
745while lt j k bound 4
746t = get ga add i j
747if or lt t 0x80 gt t 0xbf
748ret true
749end
750j = add j 1
751end
752ret false
753end
754
755note u8val: the length when ga is well-formed, else the index of the lead of the first sequence that is
756note ill-formed or cut off by the end
757fn u8val to ulong
758la = get gl 0
759i = ulong 0
760while lt i la bound 1000000
761k = u8need get ga i
762if eq k 0
763ret i
764end
765if gt k 1
766if gt add i k la
767ret i
768end
769if u8bad i k
770ret i
771end
772end
773i = add i k
774end
775ret la
776end
777
778fn u8case to void
779la = get gl 0
780reserve add 5 la
781cb1 85
782cbn la 4
783cbga la
784wop 85
785wnum u8val
786wend
787end
788
789note u8enc cp: the UTF-8 bytes of cp (below 0x110000) into eb; their count
790fn u8enc cp ulong to ulong
791if lt cp 0x80
792put eb 0 uchar cp
793ret 1
794end
795if lt cp 0x800
796put eb 0 uchar or 0xc0 shr cp 6
797put eb 1 uchar or 0x80 and cp 0x3f
798ret 2
799end
800if lt cp 0x10000
801put eb 0 uchar or 0xe0 shr cp 12
802put eb 1 uchar or 0x80 and shr cp 6 0x3f
803put eb 2 uchar or 0x80 and cp 0x3f
804ret 3
805end
806put eb 0 uchar or 0xf0 shr cp 18
807put eb 1 uchar or 0x80 and shr cp 12 0x3f
808put eb 2 uchar or 0x80 and shr cp 6 0x3f
809put eb 3 uchar or 0x80 and cp 0x3f
810ret 4
811end
812
813fn u8app cp ulong to void
814n = u8enc cp
815la = get gl 0
816for i ulong n
817put ga add la i get eb i
818end
819put gl 0 add la n
820end
821
822note decres: the answer after "P ": the first code point and its length, or n
823fn decres to void
824la = get gl 0
825c = get ga 0
826k = u8need c
827if eq k 0
828wb1 110
829ret
830end
831if eq k 1
832wnum ulong c
833wb1 32
834wb1 49
835ret
836end
837if lt la k
838wb1 110
839ret
840end
841if u8bad 0 k
842wb1 110
843ret
844end
845cp = ulong and c 0x1f
846if eq k 3
847cp = ulong and c 0x0f
848end
849if eq k 4
850cp = ulong and c 0x07
851end
852for j ulong sub k 1
853cp = or shl cp 6 ulong and get ga add j 1 0x3f
854end
855wnum cp
856wb1 32
857wnum k
858end
859
860fn deccase to void
861la = get gl 0
862reserve add 5 la
863cb1 80
864cbn la 4
865cbga la
866wop 80
867decres
868wend
869end
870
871fn enccase cp ulong cap ulong to void
872reserve 17
873cb1 81
874cbn cp 8
875cbn cap 8
876wop 81
877if or gt cp 0x10ffff and ge cp 0xd800 le cp 0xdfff
878wb1 82
879wend
880ret
881end
882n = u8enc cp
883if gt n cap
884wb1 69
885wend
886ret
887end
888for i ulong n
889e = get eb i
890wb1 hexc shr e 4
891wb1 hexc and e 15
892end
893wend
894end
895
896fn hexc d uchar to uchar
897if lt d 10
898ret add d 48
899end
900ret add d 87
901end
902
903note ======== the case sections, in gen.py's order
904fn rab5 to uchar
905i = rbelow 5
906if eq i 0
907ret 97
908end
909if eq i 1
910ret 98
911end
912if eq i 2
913ret 127
914end
915if eq i 3
916ret 128
917end
918ret 255
919end
920
921fn seccmp to void
922for t ulong 3000
923la = rbelow 9
924for i1 ulong la
925put ga i1 rab5
926end
927put gl 0 la
928if lt rrand T30
929for i2 ulong la
930put gb i2 get ga i2
931end
932put gl 1 la
933else
934lb = rbelow 9
935for i3 ulong lb
936put gb i3 rab5
937end
938put gl 1 lb
939end
940cmpcase
941end
942end
943
944fn cpab n ulong to void
945for i ulong n
946put gb i get ga i
947end
948put gl 1 n
949end
950
951fn flipcmp ix ulong to void
952cpab 200000
953put gb ix xor get gb ix 0x80
954cmpcase
955end
956
957fn secbig to void
958for i ulong 200000
959put ga i uchar rbelow 256
960end
961put gl 0 200000
962cpab 200000
963cmpcase
964flipcmp 0
965flipcmp 65535
966flipcmp 65536
967flipcmp 65537
968flipcmp 131072
969flipcmp 199999
970cpab 199999
971cmpcase
972cpab 200000
973put gl 0 199999
974cmpcase
975put gl 0 0
976put gl 1 0
977cmpcase
978end
979
980fn secfind to void
981for t ulong 3000
982lh = rbelow 12
983for i1 ulong lh
984put ga i1 uchar add 97 rbelow 2
985end
986put gl 0 lh
987ln = rbelow 4
988for i2 ulong ln
989put gb i2 uchar add 97 rbelow 2
990end
991put gl 1 ln
992findcase rbelow 14
993end
994end
995
996fn gbtx t view uchar * to void
997for i ulong len t
998put gb i get t i
999end
1000put gl 1 len t
1001end
1002
1003fn sechay to void
1004for i ulong 250000
1005put ga i uchar add 97 rbelow 2
1006end
1007for j ulong 6
1008put ga add 250000 j get tneedle j
1009end
1010for k ulong 10
1011put ga add 250006 k 97
1012end
1013la = ulong 250016
1014put gl 0 la
1015gbtx tneedle
1016findcase 0
1017findcase 65536
1018findcase 250000
1019findcase 250001
1020findcase sub la 6
1021findcase la
1022findcase add la 1
1023put gl 1 0
1024findcase la
1025put gl 0 0
1026findcase 0
1027findcase 1
1028put gl 0 la
1029gbtx tneedlx
1030findcase 0
1031end
1032
1033fn secsplit to void
1034for t ulong 2000
1035l = rbelow 12
1036for i ulong l
1037c = uchar 97
1038if eq rbelow 2 1
1039c = 44
1040end
1041put ga i c
1042end
1043put gl 0 l
1044splcase 44
1045end
1046for j ulong 140000
1047put ga j 97
1048end
1049put ga 140000 44
1050put ga 140001 98
1051put ga 140002 98
1052put ga 140003 98
1053put gl 0 140004
1054splcase 44
1055end
1056
1057fn secedge to void
1058p = ulong 0
1059for i ulong add len tedge 1
1060cut = false
1061if eq i len tedge
1062cut = true
1063else
1064if eq get tedge i 124
1065cut = true
1066end
1067end
1068if cut
1069for j ulong sub i p
1070put ga j get tedge add p j
1071end
1072put gl 0 sub i p
1073par3
1074p = add i 1
1075end
1076end
1077for k ulong 100000
1078put ga k 48
1079end
1080put ga 100000 55
1081put gl 0 100001
1082par3
1083end
1084
1085fn secbyte to void
1086for a ulong 256
1087put ga 0 uchar a
1088put ga 1 49
1089put gl 0 1
1090parcase 68
1091put gl 0 2
1092parcase 68
1093put gl 0 1
1094parcase 72
1095put gl 0 2
1096parcase 72
1097put gl 0 1
1098parcase 73
1099put gl 0 2
1100parcase 73
1101end
1102end
1103
1104fn secprnd to void
1105for t ulong 4000
1106k = add 1 rbelow 22
1107for i ulong k
1108c = uchar 0
1109if lt rrand T05
1110c = get t25 rbelow 25
1111else
1112c = uchar add 48 rbelow 10
1113end
1114put ga i c
1115end
1116put gl 0 k
1117par3
1118end
1119end
1120
1121fn secfmt to void
1122fmtv 0
1123fmtv 1
1124fmtv 9
1125fmtv 10
1126fmtv 99
1127fmtv 100
1128fmtv 0xffffffffffffffff
1129fmtv 0xfffffffffffffffe
1130fmtv 0x8000000000000000
1131fmtv 0x7fffffffffffffff
1132for t ulong 2000
1133fmtv r64
1134end
1135fmtg 0
1136fmtg 0xffffffffffffffff
1137fmtg 1
1138fmtg 0x8000000000000000
1139fmtg 0x7fffffffffffffff
1140fmtg 0x8000000000000001
1141for u ulong 2000
1142fmtg xor r64 0x8000000000000000
1143end
1144end
1145
1146fn third i ulong to uchar
1147if eq i 0
1148ret 0x00
1149end
1150if eq i 1
1151ret 0x7f
1152end
1153if eq i 2
1154ret 0x80
1155end
1156if eq i 3
1157ret 0x8f
1158end
1159if eq i 4
1160ret 0x90
1161end
1162if eq i 5
1163ret 0xa0
1164end
1165if eq i 6
1166ret 0xbf
1167end
1168if eq i 7
1169ret 0xc0
1170end
1171ret 0xff
1172end
1173
1174fn secu8 to void
1175for a ulong 256
1176put ga 0 uchar a
1177put gl 0 1
1178u8case
1179end
1180put gl 0 2
1181for a2 ulong 256
1182for b2 ulong 256
1183put ga 0 uchar a2
1184put ga 1 uchar b2
1185u8case
1186end
1187end
1188put gl 0 3
1189for a3 ulong 16
1190for b3 ulong 256
1191for c3 ulong 256
1192put ga 0 uchar add 0xe0 a3
1193put ga 1 uchar b3
1194put ga 2 uchar c3
1195u8case
1196end
1197end
1198end
1199put gl 0 4
1200for a4 ulong 5
1201for b4 ulong 64
1202for c4 ulong 9
1203for e4 ulong 9
1204put ga 0 uchar add 0xf0 a4
1205put ga 1 uchar add 0x80 b4
1206put ga 2 third c4
1207put ga 3 third e4
1208u8case
1209end
1210end
1211end
1212end
1213end
1214
1215fn pick5 p ulong c0 ulong c1 ulong c2 ulong c3 ulong c4 ulong to ulong
1216if eq p 0
1217ret c0
1218end
1219if eq p 1
1220ret c1
1221end
1222if eq p 2
1223ret c2
1224end
1225if eq p 3
1226ret c3
1227end
1228ret c4
1229end
1230
1231fn u8mix to void
1232put gl 0 0
1233cnt = rbelow 6
1234for j ulong cnt
1235c0 = rbelow 0x80
1236c1 = add 0x80 rbelow sub ulong 0x800 0x80
1237c2 = add 0x800 rbelow sub ulong 0xd800 0x800
1238c3 = add 0xe000 rbelow sub ulong 0x10000 0xe000
1239c4 = add 0x10000 rbelow sub ulong 0x110000 0x10000
1240u8app pick5 rbelow 5 c0 c1 c2 c3 c4
1241end
1242la = get gl 0
1243if gt la 0
1244if lt rrand T50
1245v = uchar rbelow 256
1246put ga rbelow la v
1247end
1248end
1249la = get gl 0
1250if gt la 0
1251if lt rrand T20
1252put gl 0 rbelow la
1253end
1254end
1255u8case
1256end
1257
1258fn secu8r to void
1259for t ulong 20000
1260u8mix
1261end
1262for i ulong 100000
1263put ga mul i 2 0xc3
1264put ga add mul i 2 1 0xa9
1265end
1266put ga 200000 0xed
1267put ga 200001 0xa0
1268put ga 200002 0x80
1269put gl 0 200003
1270u8case
1271end
1272
1273fn secdec to void
1274for a ulong 256
1275put ga 0 uchar a
1276put gl 0 1
1277deccase
1278put gl 0 2
1279for b ulong 256
1280put ga 1 uchar b
1281deccase
1282end
1283end
1284put gl 0 3
1285for i ulong 5
1286lead = uchar 0xe0
1287if eq i 1
1288lead = 0xe1
1289end
1290if eq i 2
1291lead = 0xe8
1292end
1293if eq i 3
1294lead = 0xed
1295end
1296if eq i 4
1297lead = 0xef
1298end
1299for b3 ulong 256
1300for c3 ulong 256
1301put ga 0 lead
1302put ga 1 uchar b3
1303put ga 2 uchar c3
1304deccase
1305end
1306end
1307end
1308put gl 0 5
1309for a4 ulong 8
1310for b4 ulong 64
1311for c4 ulong 9
1312for e4 ulong 9
1313put ga 0 uchar add 0xf0 a4
1314put ga 1 uchar add 0x80 b4
1315put ga 2 third c4
1316put ga 3 third e4
1317put ga 4 120
1318deccase
1319end
1320end
1321end
1322end
1323end
1324
1325fn secdecr to void
1326for t ulong 20000
1327put gl 0 0
1328n = add 1 rbelow 2
1329for i ulong n
1330cp = rbelow 0x110000
1331if or lt cp 0xd800 gt cp 0xdfff
1332u8app cp
1333end
1334end
1335if eq get gl 0 0
1336put ga 0 97
1337put gl 0 1
1338end
1339put gl 0 add 1 rbelow get gl 0
1340deccase
1341end
1342end
1343
1344fn edgecp i ulong to ulong
1345if eq i 0
1346ret 0
1347end
1348if eq i 1
1349ret 0x7f
1350end
1351if eq i 2
1352ret 0x80
1353end
1354if eq i 3
1355ret 0x7ff
1356end
1357if eq i 4
1358ret 0x800
1359end
1360if eq i 5
1361ret 0xffff
1362end
1363if eq i 6
1364ret 0x10000
1365end
1366if eq i 7
1367ret 0x10ffff
1368end
1369if eq i 8
1370ret 0x110000
1371end
1372if eq i 9
1373ret 0x100000000
1374end
1375ret 0xffffffffffffffff
1376end
1377
1378fn secenc to void
1379for i ulong 11
1380enccase edgecp i 4
1381end
1382for j ulong sub ulong 0xe100 0xd700
1383enccase add 0xd700 j 4
1384end
1385cp = ulong 0
1386while lt cp 0x110000 bound 1000000
1387enccase cp 4
1388cp = add cp 7
1389end
1390for k ulong 11
1391for cap ulong 5
1392enccase edgecp k cap
1393end
1394end
1395end
1396
1397fn main to int
1398ck eq argcnt 2
1399n = argread 1 od 0 4000
1400ck gt n 0
1401put odn 0 ulong n
1402mtseed
1403seccmp
1404secbig
1405secfind
1406sechay
1407secsplit
1408secedge
1409secbyte
1410secprnd
1411secfmt
1412secu8
1413secu8r
1414secdec
1415secdecr
1416secenc
1417flush
1418put wfd 0 2
1419wtx tfiles
1420wnum get nf 0
1421wb1 10
1422wflush
1423ret 0
1424end