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 / src / adapters / go-u64-import.om

984 lines · 14527 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-or-later
2note Handwritten bounded Go 1.27 uint64 expression importer, profile go-u64-pure-v1 (source-aware v2).
3note No Go compiler, parser library or host fallback. Spec: spec/universal/go-u64-v1.md.
4note SHA256 definitions are the unchanged, pinned source-aware vendor core prepended at build.
5global Src uchar 4096
6global Extra uchar 1
7global Out uchar 8192
8global Slen ulong 1
9global Cur ulong 1
10global Tk ulong 1
11global Ts ulong 1
12global Te ulong 1
13global Tv ulong 1
14global Ins ulong 1
15global Nl ulong 1
16global Npar ulong 1
17global Poff ulong 6
18global Plen ulong 6
19global Nop ulong 1
20global Beg ulong 64
21global Ends ulong 64
22global Kc ulong 64
23global Kv ulong 64
24text Fixed "package main func return uint64 +build"
25text Keys "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var true false iota nil append cap clear close complex copy delete imag len make max min new panic print println real recover main init"
26text Types "any bool byte comparable complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr"
27text Entry "calc omega_"
28text ESyn "GO_IMPORT_SYNTAX\n"
29text EType "GO_IMPORT_UNSUPPORTED_TYPE\n"
30text ECap "GO_IMPORT_LIMIT\n"
31text EArith "GO_IMPORT_UNSUPPORTED_ARITHMETIC\n"
32text EForm "GO_IMPORT_UNSUPPORTED_CONSTRUCT\n"
33text EName "GO_IMPORT_UNKNOWN_IDENTIFIER\n"
34text ESig "GO_IMPORT_UNSUPPORTED_SIGNATURE\n"
35text ELex "GO_IMPORT_UNSUPPORTED_SOURCE_FORM\n"
36text EIO "GO_IMPORT_IO\n"
37
38fn die code ulong to void
39if eq code 65
40w = write 2 ESyn 0 len ESyn
41end
42if eq code 66
43w = write 2 EType 0 len EType
44end
45if eq code 67
46w = write 2 ECap 0 len ECap
47end
48if eq code 68
49w = write 2 EArith 0 len EArith
50end
51if eq code 69
52w = write 2 EForm 0 len EForm
53end
54if eq code 70
55w = write 2 EName 0 len EName
56end
57if eq code 71
58w = write 2 ESig 0 len ESig
59end
60if eq code 72
61w = write 2 ELex 0 len ELex
62end
63if eq code 77
64w = write 2 EIO 0 len EIO
65end
66exit int code
67end
68
69fn alpha c uchar to bool
70ret or or and ge c 65 le c 90 and ge c 97 le c 122 eq c 95
71end
72
73fn digit c uchar to bool
74ret and ge c 48 le c 57
75end
76
77fn ident c uchar to bool
78ret or alpha c digit c
79end
80
81fn srcdig p ulong to bool
82if ge p get Slen 0
83ret false
84end
85ret digit get Src p
86end
87
88fn srcid p ulong to bool
89if ge p get Slen 0
90ret false
91end
92ret ident get Src p
93end
94
95fn srcis p ulong c ulong to bool
96if ge p get Slen 0
97ret false
98end
99ret eq ulong get Src p c
100end
101
102fn notnl p ulong to bool
103if ge p get Slen 0
104ret false
105end
106ret ne get Src p 10
107end
108
109note Strict UTF-8 (no overlong, surrogate or above U+10FFFF) over the whole source.
110fn utf8 to bool
111n = get Slen 0
112pos = ulong 0
113while lt pos n
114c = ulong get Src pos
115pos = add pos 1
116if ge c 128
117extra = ulong 0
118v = ulong 0
119low = ulong 0
120if and ge c 194 le c 223
121extra = 1
122v = and c 31
123low = 128
124end
125if and ge c 224 le c 239
126extra = 2
127v = and c 15
128low = 2048
129end
130if and ge c 240 le c 244
131extra = 3
132v = and c 7
133low = 65536
134end
135if eq extra 0
136ret false
137end
138if gt extra sub n pos
139ret false
140end
141for j ulong extra
142c = ulong get Src pos
143if or lt c 128 gt c 191
144ret false
145end
146v = or shl v 6 and c 63
147pos = add pos 1
148end
149if lt v low
150ret false
151end
152if gt v 1114111
153ret false
154end
155if and ge v 55296 le v 57343
156ret false
157end
158end
159end
160ret true
161end
162
163fn blank p ulong to bool
164if ge p get Slen 0
165ret true
166end
167c = get Src p
168ret or or eq c 32 eq c 9 or eq c 10 eq c 13
169end
170
171note Line comment; acts like a newline. Compiler directives (//go:..., //line, //export, // +build)
172note are not ordinary comments: the byte after // must be blank, and the text may not start with +build.
173fn linecom to void
174p = add get Cur 0 2
175if not blank p
176die 72
177end
178q = p
179while or srcis q 32 srcis q 9
180q = add q 1
181end
182hit = ulong 1
183for i ulong 6
184if not srcis add q i ulong get Fixed add 32 i
185hit = 0
186end
187end
188if eq hit 1
189die 72
190end
191while notnl p
192p = add p 1
193end
194put Nl 0 1
195put Cur 0 p
196end
197
198note General comment; Go general comments do not nest. One containing a newline acts like a newline.
199note The byte after /* must be blank or *, which excludes the /*line directive.
200fn blockcom to void
201p = add get Cur 0 2
202if not or blank p srcis p 42
203die 72
204end
205while lt add p 1 get Slen 0
206a = get Src p
207b = get Src add p 1
208if and eq a 42 eq b 47
209put Cur 0 add p 2
210ret
211end
212if eq a 10
213put Nl 0 1
214end
215p = add p 1
216end
217die 65
218end
219
220fn spaces to void
221more = ulong 1
222while eq more 1
223if ge get Cur 0 get Slen 0
224ret
225end
226p = get Cur 0
227c = get Src p
228if or or eq c 32 eq c 9 or eq c 10 eq c 13
229if eq c 10
230put Nl 0 1
231end
232put Cur 0 add p 1
233else
234if and eq c 47 lt add p 1 get Slen 0
235d = get Src add p 1
236if eq d 47
237linecom
238else
239if eq d 42
240blockcom
241else
242more = 0
243end
244end
245else
246more = 0
247end
248end
249end
250end
251
252fn word off ulong n ulong to bool
253if or ne get Tk 0 256 ne sub get Te 0 get Ts 0 n
254ret false
255end
256for i ulong n
257if ne get Src add get Ts 0 i get Fixed add off i
258ret false
259end
260end
261ret true
262end
263
264note An identifier ends a line with an automatic semicolon, except the keywords of this grammar that
265note do not (package, func). Every other keyword refuses wherever it appears.
266fn idlex to void
267p = add get Cur 0 1
268while srcid p
269p = add p 1
270end
271put Tk 0 256
272put Cur 0 p
273put Te 0 p
274put Ins 0 1
275if or word 0 7 word 13 4
276put Ins 0 0
277end
278end
279
280note Decimal literal 0 or [1-9][0-9]*; no 0x/0o/0b, no legacy octal 0nn, no _, no float or imaginary form.
281fn numlex to void
282p = get Cur 0
283if eq get Src p 48
284if srcdig add p 1
285die 68
286end
287end
288v = ulong 0
289while srcdig p
290d = sub ulong get Src p 48
291if gt v 1844674407370955161
292die 67
293end
294if and eq v 1844674407370955161 gt d 5
295die 67
296end
297v = add mul v 10 d
298p = add p 1
299end
300if srcid p
301die 68
302end
303if srcis p 46
304die 68
305end
306put Tk 0 257
307put Tv 0 v
308put Cur 0 p
309put Te 0 p
310put Ins 0 1
311end
312
313note Go automatic semicolon insertion: a newline (or the end of input) after an identifier, literal,
314note ) ] or } is a ; token. Token 59 is both the explicit and the inserted semicolon.
315fn lexnext to void
316put Nl 0 0
317spaces
318p = get Cur 0
319if and eq get Ins 0 1 or eq get Nl 0 1 ge p get Slen 0
320put Ins 0 0
321put Tk 0 59
322put Ts 0 p
323put Te 0 p
324ret
325end
326put Ins 0 0
327put Ts 0 p
328if ge p get Slen 0
329put Tk 0 0
330put Te 0 p
331ret
332end
333c = get Src p
334if alpha c
335idlex
336else
337if digit c
338numlex
339else
340if gt c 127
341die 69
342end
343put Tk 0 ulong c
344put Cur 0 add p 1
345put Te 0 add p 1
346if or or eq c 41 eq c 93 eq c 125
347put Ins 0 1
348end
349end
350end
351end
352
353fn keyeq txt ulong off ulong n ulong to bool
354if ne sub get Te 0 get Ts 0 n
355ret false
356end
357for i ulong n
358c = get Src add get Ts 0 i
359if eq txt 0
360if ne c get Keys add off i
361ret false
362end
363else
364if ne c get Types add off i
365ret false
366end
367end
368end
369ret true
370end
371
372fn keychar p ulong to bool
373if ge p len Keys
374ret false
375end
376ret ne get Keys p 32
377end
378
379fn typechar p ulong to bool
380if ge p len Types
381ret false
382end
383ret ne get Types p 32
384end
385
386note Keywords, predeclared constants and functions, main and init.
387fn iskey to bool
388if ne get Tk 0 256
389ret false
390end
391p = ulong 0
392while lt p len Keys
393b = p
394while keychar p
395p = add p 1
396end
397if keyeq 0 b sub p b
398ret true
399end
400p = add p 1
401end
402ret false
403end
404
405note Predeclared type names.
406fn istype to bool
407if ne get Tk 0 256
408ret false
409end
410p = ulong 0
411while lt p len Types
412b = p
413while typechar p
414p = add p 1
415end
416if keyeq 1 b sub p b
417ret true
418end
419p = add p 1
420end
421ret false
422end
423
424fn entryok to bool
425n = sub get Te 0 get Ts 0
426if eq n 4
427for i ulong 4
428if ne get Src add get Ts 0 i get Entry i
429ret false
430end
431end
432ret true
433end
434if le n 6
435ret false
436end
437for i ulong 6
438if ne get Src add get Ts 0 i get Entry add i 5
439ret false
440end
441end
442ret true
443end
444
445fn nameok to void
446if ne get Tk 0 256
447die 69
448end
449if gt sub get Te 0 get Ts 0 32
450die 71
451end
452c = get Src get Ts 0
453if or lt c 97 gt c 122
454die 71
455end
456if iskey
457die 71
458end
459if istype
460die 71
461end
462end
463
464fn need k ulong to void
465if ne get Tk 0 k
466die 65
467end
468lexnext
469end
470
471fn same off ulong count ulong to bool
472if ne count sub get Te 0 get Ts 0
473ret false
474end
475for i ulong count
476if ne get Src add off i get Src add get Ts 0 i
477ret false
478end
479end
480ret true
481end
482
483fn leput off ulong v ulong n ulong to void
484for i ulong n
485put Out add off i uchar and shr v mul i 8 255
486end
487end
488
489note One OMSA v2 operation record of the Go member: dialect 7, version 1, type 1.
490fn emitop op ulong a ulong b ulong imm ulong lo ulong hi ulong to ulong
491i = get Nop 0
492if ge i 64
493die 67
494end
495p = add 57 mul i 20
496for j ulong 20
497put Out add p j 0
498end
499put Out p 7
500put Out add p 1 1
501put Out add p 2 uchar op
502put Out add p 3 1
503if ne op 9
504put Out add p 4 1
505end
506if ne op 1
507put Out add p 7 1
508end
509leput add p 8 a 2
510leput add p 10 b 2
511leput add p 12 imm 8
512put Beg i lo
513put Ends i hi
514put Kc i 0
515put Kv i imm
516if eq op 1
517put Kc i 1
518end
519put Nop 0 add i 1
520ret i
521end
522
523note Untyped constants: a source operation whose operands are both constant-only is a Go constant
524note expression, evaluated exactly. It must lie in 0..2^64-1, so that the exact value equals the
525note modulo-2^64 tree and the conversion to uint64 compiles; otherwise refuse 68.
526fn mkop code ulong a ulong b ulong lo ulong hi ulong to ulong
527k = emitop code a b 0 lo hi
528if and eq get Kc a 1 eq get Kc b 1
529x = get Kv a
530y = get Kv b
531v = ulong 0
532if eq code 2
533v = add x y
534if lt v x
535die 68
536end
537end
538if eq code 3
539if lt x y
540die 68
541end
542v = sub x y
543end
544if eq code 4
545v = mul x y
546if ne x 0
547if ne div v x y
548die 68
549end
550end
551end
552put Kc k 1
553put Kv k v
554end
555ret k
556end
557
558fn badarith to bool
559k = get Tk 0
560if or or eq k 47 eq k 37 eq k 38
561ret true
562end
563if or or eq k 124 eq k 94 eq k 60
564ret true
565end
566if or eq k 62 eq k 33
567ret true
568end
569if eq k 61
570ret srcis get Te 0 61
571end
572ret false
573end
574
575fn closer to void
576t = get Tk 0
577if eq t 41
578lexnext
579ret
580end
581if badarith
582die 68
583end
584if or or eq t 0 eq t 59 or eq t 125 eq t 44
585die 65
586end
587if or eq t 256 eq t 257
588die 65
589end
590die 69
591end
592
593fn identprim to ulong
594for j ulong get Npar 0
595if same get Poff j get Plen j
596lexnext
597ret j
598end
599end
600if istype
601die 66
602end
603if iskey
604die 69
605end
606die 70
607ret 0
608end
609
610fn primary depth ulong to ulong
611if gt depth 16
612die 67
613end
614t = get Tk 0
615if eq t 257
616node = emitop 1 65535 65535 get Tv 0 get Ts 0 get Te 0
617lexnext
618ret node
619end
620if eq t 256
621ret identprim
622end
623if eq t 40
624lexnext
625node = expr add depth 1
626closer
627ret node
628end
629if or or eq t 43 eq t 45 or eq t 94 eq t 42
630die 68
631end
632if or or eq t 38 eq t 33 or eq t 60 eq t 126
633die 68
634end
635if or eq t 39 eq t 46
636die 68
637end
638if or or eq t 0 eq t 41 or eq t 59 or eq t 44 eq t 125
639die 65
640end
641die 69
642ret 0
643end
644
645fn term depth ulong to ulong
646left = primary depth
647while eq get Tk 0 42
648lo = get Ts 0
649hi = get Te 0
650lexnext
651right = primary depth
652left = mkop 4 left right lo hi
653end
654ret left
655end
656
657fn expr depth ulong to ulong
658left = term depth
659while or eq get Tk 0 43 eq get Tk 0 45
660code = ulong 2
661if eq get Tk 0 45
662code = 3
663end
664lo = get Ts 0
665hi = get Te 0
666lexnext
667right = term depth
668left = mkop code left right lo hi
669end
670ret left
671end
672
673fn pname to void
674nameok
675j = get Npar 0
676if ge j 6
677die 67
678end
679for k ulong j
680if same get Poff k get Plen k
681die 71
682end
683end
684put Poff j get Ts 0
685put Plen j sub get Te 0 get Ts 0
686x = emitop 9 65535 65535 j get Ts 0 get Te 0
687put Npar 0 add j 1
688lexnext
689end
690
691fn ptype to void
692if word 25 6
693lexnext
694ret
695end
696t = get Tk 0
697if eq t 46
698die 69
699end
700if or or eq t 256 eq t 42 or eq t 91 eq t 40
701die 66
702end
703die 65
704end
705
706note Named parameters, optionally grouped (a, b uint64); every group has type uint64.
707fn params to void
708if eq get Tk 0 41
709lexnext
710ret
711end
712more = ulong 1
713while eq more 1
714pname
715if eq get Tk 0 44
716lexnext
717if eq get Tk 0 41
718die 65
719end
720else
721ptype
722if eq get Tk 0 44
723lexnext
724if eq get Tk 0 41
725die 65
726end
727else
728more = 0
729end
730end
731end
732need 41
733end
734
735fn result to void
736t = get Tk 0
737if eq t 40
738die 69
739end
740if eq t 123
741die 71
742end
743if word 25 6
744lexnext
745ret
746end
747if or or eq t 256 eq t 42 eq t 91
748die 66
749end
750die 65
751end
752
753fn header to void
754lexnext
755if not word 0 7
756if eq get Tk 0 0
757die 65
758end
759die 69
760end
761lexnext
762if ne get Tk 0 256
763die 65
764end
765if not word 8 4
766die 71
767end
768lexnext
769need 59
770if not word 13 4
771if eq get Tk 0 0
772die 65
773end
774die 69
775end
776lexnext
777if eq get Tk 0 40
778die 69
779end
780nameok
781if not entryok
782die 71
783end
784lexnext
785if eq get Tk 0 91
786die 69
787end
788need 40
789params
790result
791need 123
792if not word 18 6
793if eq get Tk 0 125
794die 65
795end
796die 69
797end
798lexnext
799end
800
801fn bodyend to void
802if badarith
803die 68
804end
805if eq get Tk 0 59
806lexnext
807if ne get Tk 0 125
808die 69
809end
810end
811t = get Tk 0
812if eq t 125
813lexnext
814ret
815end
816if or eq t 0 eq t 41
817die 65
818end
819if or eq t 256 eq t 257
820die 65
821end
822die 69
823end
824
825fn parse to void
826put Cur 0 0
827header
828if eq get Tk 0 59
829die 65
830end
831root = expr 0
832bodyend
833if eq get Tk 0 59
834lexnext
835end
836if ne get Tk 0 0
837die 69
838end
839z = emitop 1 65535 65535 0 0 0
840root = emitop 2 root z 0 0 0
841end
842
843fn parent to void
844put Out 25 212
845put Out 26 237
846put Out 27 97
847put Out 28 72
848put Out 29 191
849put Out 30 169
850put Out 31 124
851put Out 32 198
852put Out 33 147
853put Out 34 211
854put Out 35 250
855put Out 36 68
856put Out 37 149
857put Out 38 226
858put Out 39 215
859put Out 40 226
860put Out 41 230
861put Out 42 138
862put Out 43 186
863put Out 44 4
864put Out 45 96
865put Out 46 122
866put Out 47 126
867put Out 48 150
868put Out 49 221
869put Out 50 154
870put Out 51 156
871put Out 52 84
872put Out 53 191
873put Out 54 144
874put Out 55 115
875put Out 56 168
876end
877
878note OMSB v1 envelope, OMSA semantic header version 2, language 7 (Go 1.27), profile 9, runtime 0, ABI 1.
879fn envelope to ulong
880n = get Nop 0
881sem = add 44 mul 20 n
882prov = add add 74 mul 8 n get Slen 0
883put Out 0 79
884put Out 1 77
885put Out 2 83
886put Out 3 66
887put Out 4 1
888leput 5 sem 4
889leput 9 prov 4
890put Out 13 79
891put Out 14 77
892put Out 15 83
893put Out 16 65
894put Out 17 2
895put Out 18 7
896put Out 19 9
897put Out 20 1
898put Out 21 0
899put Out 22 1
900leput 23 n 2
901parent
902s = add 13 sem
903put Out s 79
904put Out add s 1 77
905put Out add s 2 83
906put Out add s 3 80
907put Out add s 4 1
908put Out add s 5 1
909leput add s 6 get Slen 0 4
910hinit
911for i ulong sem
912hbyte get Out add 13 i
913end
914finish
915for i ulong 32
916put Out add add s 10 i get Hash i
917end
918hinit
919for i ulong get Slen 0
920hbyte get Src i
921end
922finish
923for i ulong 32
924put Out add add s 42 i get Hash i
925end
926for i ulong n
927leput add add s 74 mul i 8 get Beg i 4
928leput add add s 78 mul i 8 get Ends i 4
929end
930b = add add s 74 mul n 8
931for i ulong get Slen 0
932put Out add b i get Src i
933end
934ret add add 13 sem prov
935end
936
937fn main to int
938n = ulong 0
939more = ulong 1
940while and eq more 1 lt n 4096
941r = read 0 Src n sub 4096 n
942if lt r 0
943die 77
944end
945if eq r 0
946more = 0
947else
948n = add n ulong r
949end
950end
951if eq n 4096
952r = read 0 Extra 0 1
953if lt r 0
954die 77
955end
956if gt r 0
957die 67
958end
959end
960put Slen 0 n
961for i ulong n
962if eq get Src i 0
963die 65
964end
965end
966if not utf8
967die 72
968end
969if and srcis 0 239 and srcis 1 187 srcis 2 191
970die 72
971end
972constants
973parse
974n = envelope
975sent = ulong 0
976while lt sent n
977r = write 1 Out sent sub n sent
978if le r 0
979die 77
980end
981sent = add sent ulong r
982end
983ret 0
984end