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 / python-u64-export.om

453 lines · 6345 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-or-later
2note Handwritten S1-family upper-to-Python3 exporter (python-explicit-u64-pure-v1, spec/universal/python-u64-v1.md).
3note Prepended unchanged at build: src/source-aware/vendor/sha256.om and src/source-aware/core.om (decode n).
4note Input frame: one byte name length L (0 = calc), L name bytes, then one OMSB envelope to EOF.
5note Output is generated from the OMSA operation records only; the OMSP sidecar is validated by decode, never read.
6global Yn uchar 1
7global Ynm uchar 32
8global Yone uchar 1
9global Yo uchar 4096
10global Yl ulong 1
11global Yni ulong 1
12global Yln ulong 64
13global Ydp ulong 64
14global Ycn ulong 64
15text Ycalc "calc"
16text Ywords "def return False None True and as assert async await break class continue del elif else except finally for from global if import in is lambda nonlocal not or pass raise try while with yield match case type"
17text Ydef "def "
18text Ymid "):\n return "
19text Ymask " & 0xFFFFFFFFFFFFFFFF"
20text YBad "PY_EXPORT_BAD_COMMAND\n"
21text YMal "PY_EXPORT_MALFORMED\n"
22text YLim "PY_EXPORT_LIMIT\n"
23text YProf "PY_EXPORT_PROFILE_MISMATCH\n"
24text YIO "PY_EXPORT_IO\n"
25
26fn ydie code ulong to void
27if eq code 64
28w = write 2 YBad 0 len YBad
29end
30if eq code 65
31w = write 2 YMal 0 len YMal
32end
33if eq code 67
34w = write 2 YLim 0 len YLim
35end
36if eq code 68
37w = write 2 YProf 0 len YProf
38end
39if eq code 77
40w = write 2 YIO 0 len YIO
41end
42exit int code
43end
44
45fn ybyte c ulong to void
46put Yo get Yl 0 uchar c
47put Yl 0 add get Yl 0 1
48end
49
50fn ydigits v ulong to ulong
51d = ulong 1
52x = div v 10
53while gt x 0
54d = add d 1
55x = div x 10
56end
57ret d
58end
59
60fn ydec v ulong to void
61d = new uchar 20 0
62i = ulong 0
63x = v
64put d 0 uchar add rem x 10 48
65x = div x 10
66i = add i 1
67while gt x 0
68put d i uchar add rem x 10 48
69x = div x 10
70i = add i 1
71end
72while gt i 0
73i = sub i 1
74ybyte ulong get d i
75end
76end
77
78fn yidc c ulong to bool
79if and ge c 48 le c 57
80ret true
81end
82if and ge c 65 le c 90
83ret true
84end
85if and ge c 97 le c 122
86ret true
87end
88ret eq c 95
89end
90
91fn ywrd p ulong to bool
92if ge p len Ywords
93ret false
94end
95ret ne get Ywords p 32
96end
97
98fn ysame off ulong count ulong to bool
99if ne count ulong get Yn 0
100ret false
101end
102for i ulong count
103if ne get Ynm i get Ywords add off i
104ret false
105end
106end
107ret true
108end
109
110fn ykeyword to bool
111p = ulong 0
112while lt p len Ywords
113b = p
114while ywrd p
115p = add p 1
116end
117if ysame b sub p b
118ret true
119end
120p = add p 1
121end
122ret false
123end
124
125fn ynameok to bool
126n = ulong get Yn 0
127if eq n 0
128ret true
129end
130c = ulong get Ynm 0
131if or lt c 97 gt c 122
132ret false
133end
134for j ulong n
135if not yidc ulong get Ynm j
136ret false
137end
138end
139ret not ykeyword
140end
141
142fn ykind i ulong obl ulong to ulong
143c = get Oc i
144if or ne get Ot i 1 ne get Oef i 0
145ret 68
146end
147if ne get Oal i 0
148ret 68
149end
150if eq c 9
151if or ne get Oat i 0 ne get Oob i 1
152ret 68
153end
154put Yni 0 add get Yni 0 1
155ret 0
156end
157if eq c 1
158if or ne get Oat i 1 ne get Oob i 0
159ret 68
160end
161ret 0
162end
163if or lt c 2 gt c 4
164ret 68
165end
166if or ne get Oat i 1 ne get Oob i obl
167ret 68
168end
169ret 0
170end
171
172fn yfamily to ulong
173l = get M 0
174p = get M 1
175obl = ulong 0
176if and eq l 1 eq p 1
177obl = 1
178end
179if and eq l 2 eq p 2
180obl = 1
181end
182if and eq l 3 eq p 4
183obl = 5
184end
185if eq obl 0
186ret 68
187end
188if or ne get M 2 0 ne get M 3 1
189ret 68
190end
191put Yni 0 0
192for i ulong get M 4
193if ne ykind i obl 0
194ret 68
195end
196end
197for j ulong get M 4
198if eq get Oc j 9
199if ge get Oi j get Yni 0
200ret 68
201end
202end
203end
204ret 0
205end
206
207fn ysat v ulong to ulong
208if gt v 1048576
209ret 1048576
210end
211ret v
212end
213
214fn ymetric k ulong to void
215c = get Oc k
216put Ydp k 0
217if eq c 9
218put Yln k 2
219put Ycn k 0
220ret
221end
222if eq c 1
223put Yln k ydigits get Oi k
224put Ycn k 1
225ret
226end
227a = get Oa k
228b = get Ob k
229put Yln k ysat add add get Yln a get Yln b 28
230da = get Ydp a
231db = get Ydp b
232if gt da db
233put Ydp k ysat add da 2
234else
235put Ydp k ysat add db 2
236end
237put Ycn k ysat add add get Ycn a get Ycn b 1
238end
239
240fn yemit k ulong top ulong to void
241c = get Oc k
242if eq c 9
243ybyte 105
244ybyte add 48 get Oi k
245ret
246end
247if eq c 1
248ydec get Oi k
249ret
250end
251if eq top 0
252ybyte 40
253end
254ybyte 40
255yemit get Oa k 0
256ybyte 32
257if eq c 2
258ybyte 43
259end
260if eq c 3
261ybyte 45
262end
263if eq c 4
264ybyte 42
265end
266ybyte 32
267yemit get Ob k 0
268ybyte 41
269for i ulong len Ymask
270ybyte ulong get Ymask i
271end
272if eq top 0
273ybyte 41
274end
275end
276
277fn yroot to ulong
278n = get M 4
279if lt n 3
280ret sub n 1
281end
282z = sub n 2
283y = sub n 1
284if or ne get Oc z 1 ne get Oi z 0
285ret y
286end
287if or ne get Oc y 2 ne get Ob y z
288ret y
289end
290if ge get Oa y z
291ret y
292end
293ret get Oa y
294end
295
296fn yparams to ulong
297ni = get Yni 0
298if eq ni 0
299ret 0
300end
301ret sub mul ni 4 2
302end
303
304fn ysignature to void
305for i ulong len Ydef
306ybyte ulong get Ydef i
307end
308if eq ulong get Yn 0 0
309for j ulong len Ycalc
310ybyte ulong get Ycalc j
311end
312else
313for j ulong ulong get Yn 0
314ybyte ulong get Ynm j
315end
316end
317ybyte 40
318for s ulong get Yni 0
319if gt s 0
320ybyte 44
321ybyte 32
322end
323ybyte 105
324ybyte add 48 s
325end
326for u ulong len Ymid
327ybyte ulong get Ymid u
328end
329end
330
331fn yreadname to void
332r = read 0 Yn 0 1
333if lt r 0
334ydie 77
335end
336if eq r 0
337ydie 64
338end
339n = ulong get Yn 0
340if gt n 32
341ydie 64
342end
343got = ulong 0
344while lt got n
345r = read 0 Ynm got sub n got
346if lt r 0
347ydie 77
348end
349if eq r 0
350ydie 64
351end
352got = add got ulong r
353end
354if not ynameok
355ydie 64
356end
357end
358
359fn yreadunit to ulong
360n = ulong 0
361more = ulong 1
362while and eq more 1 lt n 8192
363r = read 0 Ib n sub ulong 8192 n
364if lt r 0
365ydie 77
366end
367if eq r 0
368more = 0
369else
370n = add n ulong r
371end
372end
373if eq n 8192
374r = read 0 Yone 0 1
375if lt r 0
376ydie 77
377end
378if gt r 0
379ydie 65
380end
381end
382ret n
383end
384
385fn ytotal root ulong to ulong
386t = add add len Ydef len Ymid 2
387t = add t yparams
388if eq ulong get Yn 0 0
389t = add t len Ycalc
390else
391t = add t ulong get Yn 0
392end
393if eq get Oc root 2
394ret add t sub get Yln root 2
395end
396if eq get Oc root 3
397ret add t sub get Yln root 2
398end
399if eq get Oc root 4
400ret add t sub get Yln root 2
401end
402ret add t get Yln root
403end
404
405fn main to int
406constants
407yreadname
408n = yreadunit
409code = decode n
410if eq code 68
411ydie 68
412end
413if ne code 0
414ydie 65
415end
416if ne yfamily 0
417ydie 68
418end
419for k ulong get M 4
420ymetric k
421end
422root = yroot
423total = ytotal root
424if gt total 4096
425ydie 67
426end
427if gt get Ydp root 129
428ydie 67
429end
430if gt add add get Yni 0 get Ycn root 2 64
431ydie 67
432end
433put Yl 0 0
434ysignature
435if or or eq get Oc root 2 eq get Oc root 3 eq get Oc root 4
436yemit root 1
437else
438yemit root 0
439end
440ybyte 10
441if ne get Yl 0 total
442ydie 65
443end
444sent = ulong 0
445while lt sent total
446r = write 1 Yo sent sub total sent
447if le r 0
448ydie 77
449end
450sent = add sent ulong r
451end
452ret 0
453end