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 / upper-retarget.om

294 lines · 5012 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-or-later
2note Handwritten extended-S1 family retarget R(U, M) (translation-compose-v2 section 2). No host compute.
3note Build prepends the unchanged pinned vendor sha256.om and the #621 v2 codec core-v2.om; its `decode`
4note is the full source-aware v1/v2 validation. One envelope per process: the codec is not reentrant.
5note Members m 0..5 = c rust python cpp zig go; columns: OMSA version, language, profile, arithmetic
6note obligations (compose-v2 section 1).
7note Refusals: 64 bad argv; input over 8192 bytes 67 (source-aware-v2 decode order step 1); any nonzero
8note decoder status 65..78 passes through; a decoded unit outside the family (runtime/ABI, member row,
9note op not 1/2/3/4/9, type/attribute/effects/alias/obligations, input slots not a permutation of
10note 0..n-1 as in translation-v1 section 2) 68. Output only after acceptance; R is a semantic-only
11note envelope (sidecar length 0) with the parent-semantics hash, operands and immediates unchanged.
12global Rone uchar 1
13global Rarg uchar 16
14global Rout uchar 1400
15global Rlen ulong 1
16text Rnames "c rust python cpp zig go"
17text Rver "111222"
18text Rlang "123567"
19text Rprof "124789"
20text Robl "115111"
21text R64 "RETARGET_BAD_COMMAND\n"
22text R65 "RETARGET_MALFORMED\n"
23text R66 "RETARGET_UNKNOWN_VERSION\n"
24text R67 "RETARGET_LIMIT\n"
25text R68 "RETARGET_PROFILE_MISMATCH\n"
26text R69 "RETARGET_UNKNOWN_OPERATION\n"
27text R70 "RETARGET_TYPE_MISMATCH\n"
28text R71 "RETARGET_EFFECT_ALIAS_MISMATCH\n"
29text R72 "RETARGET_OBLIGATION_MISMATCH\n"
30text R73 "RETARGET_PROVENANCE_MISSING\n"
31text R74 "RETARGET_PROVENANCE_MISMATCH\n"
32text R75 "RETARGET_SOURCE_SPAN\n"
33text R76 "RETARGET_SOURCE_ENCODING\n"
34text R77 "RETARGET_IO\n"
35text R78 "RETARGET_CONTRACT_MISMATCH\n"
36
37fn rdie code ulong to void
38if eq code 64
39w = write 2 R64 0 len R64
40end
41if eq code 65
42w = write 2 R65 0 len R65
43end
44if eq code 66
45w = write 2 R66 0 len R66
46end
47if eq code 67
48w = write 2 R67 0 len R67
49end
50if eq code 68
51w = write 2 R68 0 len R68
52end
53if eq code 69
54w = write 2 R69 0 len R69
55end
56if eq code 70
57w = write 2 R70 0 len R70
58end
59if eq code 71
60w = write 2 R71 0 len R71
61end
62if eq code 72
63w = write 2 R72 0 len R72
64end
65if eq code 73
66w = write 2 R73 0 len R73
67end
68if eq code 74
69w = write 2 R74 0 len R74
70end
71if eq code 75
72w = write 2 R75 0 len R75
73end
74if eq code 76
75w = write 2 R76 0 len R76
76end
77if eq code 77
78w = write 2 R77 0 len R77
79end
80if eq code 78
81w = write 2 R78 0 len R78
82end
83exit int code
84end
85
86fn mcol t ulong m ulong to ulong
87if eq t 0
88ret sub ulong get Rver m 48
89end
90if eq t 1
91ret sub ulong get Rlang m 48
92end
93if eq t 2
94ret sub ulong get Rprof m 48
95end
96ret sub ulong get Robl m 48
97end
98
99fn rnamechar p ulong to bool
100if ge p len Rnames
101ret false
102end
103ret ne get Rnames p 32
104end
105
106fn rsame b ulong e ulong n ulong to bool
107if ne sub e b n
108ret false
109end
110for i ulong n
111if ne get Rnames add b i get Rarg i
112ret false
113end
114end
115ret true
116end
117
118fn rtarget to ulong
119if ne argcnt 2
120rdie 64
121end
122r = argread 1 Rarg 0 16
123if lt r 1
124rdie 64
125end
126n = ulong r
127p = ulong 0
128m = ulong 0
129while lt p len Rnames
130b = p
131while rnamechar p
132p = add p 1
133end
134if rsame b p n
135ret m
136end
137m = add m 1
138p = add p 1
139end
140rdie 64
141ret 0
142end
143
144fn rmember to ulong
145if or ne get M 2 0 ne get M 3 1
146rdie 68
147end
148v = ulong get Ib 17
149for m ulong 6
150if and eq v mcol 0 m eq get M 0 mcol 1 m
151if eq get M 1 mcol 2 m
152ret m
153end
154end
155end
156rdie 68
157ret 0
158end
159
160fn rop i ulong ob ulong to bool
161code = get Oc i
162if or ne get Ot i 1 ne get Oef i 0
163ret false
164end
165if ne get Oal i 0
166ret false
167end
168if eq code 9
169ret and eq get Oat i 0 eq get Oob i 1
170end
171if eq code 1
172ret and eq get Oat i 1 eq get Oob i 0
173end
174if or lt code 2 gt code 4
175ret false
176end
177ret and eq get Oat i 1 eq get Oob i ob
178end
179
180fn rfamily m ulong to void
181ob = mcol 3 m
182n = ulong 0
183for i ulong get M 4
184if not rop i ob
185rdie 68
186end
187if eq get Oc i 9
188n = add n 1
189end
190end
191for i ulong get M 4
192if eq get Oc i 9
193if ge get Oi i n
194rdie 68
195end
196end
197end
198end
199
200fn rb v ulong to void
201p = get Rlen 0
202put Rout p uchar and v 255
203put Rlen 0 add p 1
204end
205
206fn rle v ulong n ulong to void
207for i ulong n
208rb and shr v mul i 8 255
209end
210end
211
212fn remit t ulong to void
213lang = mcol 1 t
214ob = mcol 3 t
215count = get M 4
216put Rlen 0 0
217rle 1112755535 4
218rb 1
219rle add 44 mul 20 count 4
220rle 0 4
221rle 1095978319 4
222rb mcol 0 t
223rb lang
224rb mcol 2 t
225rb 1
226rb 0
227rb 1
228rle count 2
229for i ulong 32
230rb ulong get Ib add 25 i
231end
232for i ulong count
233code = get Oc i
234rb lang
235rb 1
236rb code
237rb 1
238rb get Oat i
239rb 0
240rb 0
241if and ge code 2 le code 4
242rb ob
243else
244rb get Oob i
245end
246rle get Oa i 2
247rle get Ob i 2
248rle get Oi i 8
249end
250end
251
252fn main to int
253t = rtarget
254n = ulong 0
255more = ulong 1
256while and eq more 1 lt n 8192
257r = read 0 Ib n sub 8192 n
258if lt r 0
259rdie 77
260end
261if eq r 0
262more = 0
263else
264n = add n ulong r
265end
266end
267if eq n 8192
268r = read 0 Rone 0 1
269if lt r 0
270rdie 77
271end
272if gt r 0
273rdie 67
274end
275end
276constants
277code = decode n
278if ne code 0
279rdie code
280end
281m = rmember
282rfamily m
283remit t
284sent = ulong 0
285k = get Rlen 0
286while lt sent k
287r = write 1 Rout sent sub k sent
288if le r 0
289rdie 77
290end
291sent = add sent ulong r
292end
293ret 0
294end