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 / train / aien-train / tests / omegese45 / contract / main.om

361 lines · 5591 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Contract driver (aien-train #45). Build:
3note cat native/omegese45/vocab.om native/omegese45/msg.om native/omegese45/mjr1.om \
4note tests/omegese45/contract/main.om | omc > oe45c
5note stdin = one mode letter, LF, payload. Modes (see docs/omegese45/CONTRACT.md):
6note V <line> VALID <G|A|R|P> | exit 40 INVALID <bytepos> <reason>
7note N <kind G|A|R|P|M> LF <decimal ids> MASK <41 x 0|1> LF FINAL <0|1>
8note B <G line> LF <job> LF <A line> BIND_OK | 40 INVALID | 41 BIND_MISMATCH <r> | 42 BIND_BOUND
9note L <A line> LOWER <m> <k> <n> <seed> | 40 | 41 BIND_MISMATCH notjob
10note E <line> IDS <id>... | exit 40 INVALID <bytepos> <reason>
11note D <decimal ids> <text line> | exit 40 INVALID <idindex> <reason>
12note T the vocab table, byte-identical to vocab.tsv
13note J <receipt path> MJR1 <outcome> <attempt> <generation> <dag> <job> <output>
14note | exit 43 MJR1_INVALID <pos> <reason>
15note Exit 2: usage (bad mode, malformed payload, output failure).
16global ocxin uchar 16384
17global ocxn ulong 1
18text ocxva "VALID "
19text ocxiv "INVALID "
20text ocxmk "MASK "
21text ocxfi "FINAL "
22text ocxbo "BIND_OK\n"
23text ocxbm "BIND_MISMATCH "
24text ocxbb "BIND_BOUND\n"
25text ocxlo "LOWER"
26text ocxid "IDS"
27text ocxmj "MJR1 "
28text ocxmi "MJR1_INVALID "
29text ocxkl "?GARPM"
30
31note End of the line that starts at s (index of LF or the input length).
32fn ocxeol s ulong to ulong
33n = get ocxn 0
34e = s
35while and lt e n ne get ocxin e 10 bound 20000
36e = add e 1
37end
38ret e
39end
40
41note Copy ocxin[a,b) into ocin; return the length (capped at the ocin size).
42fn ocxcopy a ulong b ulong to ulong
43c = sub b a
44if gt c 4096
45c = 4096
46end
47for i ulong c
48put ocin i get ocxin add a i
49end
50ret sub b a
51end
52
53note Parse space-separated decimal numbers in ocxin[a,b) into ocids; -1 when malformed.
54fn ocxnums a ulong b ulong to long
55k = ulong 0
56v = ulong 0
57nd = ulong 0
58for i ulong add sub b a 1
59p = add a i
60sep = true
61if lt p b
62if ne get ocxin p 32
63sep = false
64end
65end
66if sep
67if eq nd 0
68if or lt p b gt k 0
69ret -1
70end
71else
72if ge k 256
73ret -1
74end
75put ocids k v
76k = add k 1
77v = 0
78nd = 0
79end
80else
81c = get ocxin p
82if or lt c 48 gt c 57
83ret -1
84end
85if ge nd 6
86ret -1
87end
88v = add mul v 10 ulong sub c 48
89nd = add nd 1
90end
91end
92ret long k
93end
94
95fn ocxinv r long to void
96w = write 1 ocxiv 0 len ocxiv
97ocputn get ocerr 0
98ocputc 32
99ocputrs get ocerr 1
100ocputc 10
101end
102
103fn ocxkind c uchar to ulong
104for i ulong 5
105if eq c get ocxkl add i 1
106ret add i 1
107end
108end
109ret 0
110end
111
112fn ocxmode_v to int
113e = ocxeol 2
114if ne e get ocxn 0
115if ne add e 1 get ocxn 0
116note a second line inside the payload is a control byte
117e = get ocxn 0
118end
119end
120n = ocxcopy 2 e
121r = ocvline n 0
122if lt r 0
123ocxinv r
124ret 40
125end
126w = write 1 ocxva 0 len ocxva
127ocputc get ocxkl ulong r
128ocputc 10
129ret 0
130end
131
132fn ocxmode_e to int
133e = ocxeol 2
134if ne e get ocxn 0
135if ne add e 1 get ocxn 0
136e = get ocxn 0
137end
138end
139n = ocxcopy 2 e
140r = ocenc n
141if lt r 0
142ocxinv r
143ret 40
144end
145w = write 1 ocxid 0 len ocxid
146for i ulong ulong r
147ocputc 32
148ocputn get ocids i
149end
150ocputc 10
151ret 0
152end
153
154fn ocxmode_d to int
155e = ocxeol 2
156k = ocxnums 2 e
157if lt k 0
158ret 2
159end
160r = ocdec ulong k
161if lt r 0
162ocxinv r
163ret 40
164end
165w = write 1 ocout 0 ulong r
166if ne w r
167exit 2
168end
169ocputc 10
170ret 0
171end
172
173fn ocxmode_n to int
174e1 = ocxeol 2
175if ne e1 3
176ret 2
177end
178kd = ocxkind get ocxin 2
179if eq kd 0
180ret 2
181end
182e2 = ocxeol add e1 1
183k = ocxnums add e1 1 e2
184if lt k 0
185ret 2
186end
187st = ocstart kd
188for i ulong ulong k
189id = get ocids i
190if ge id ocv
191ret 2
192end
193st = ocstep st id
194end
195c = ocmask st
196w = write 1 ocxmk 0 len ocxmk
197for id ulong ocv
198ocputc add 48 get ocmk id
199end
200ocputc 10
201w = write 1 ocxfi 0 len ocxfi
202if ocfinal st
203ocputc 49
204else
205ocputc 48
206end
207ocputc 10
208ret 0
209end
210
211fn ocxmode_b to int
212e1 = ocxeol 2
213n = ocxcopy 2 e1
214r = ocsetgl n
215if lt r 0
216ocxinv r
217ret 40
218end
219e2 = ocxeol add e1 1
220k = ocxnums add e1 1 e2
221if ne k 1
222ret 2
223end
224job = get ocids 0
225e3 = ocxeol add e2 1
226n = ocxcopy add e2 1 e3
227r = ocbindl n job
228if lt r 0
229ocxinv r
230ret 40
231end
232if eq r 41
233w = write 1 ocxbm 0 len ocxbm
234ocputrs get ocerr 1
235ocputc 10
236ret 41
237end
238if eq r 42
239w = write 1 ocxbb 0 len ocxbb
240ret 42
241end
242w = write 1 ocxbo 0 len ocxbo
243ret 0
244end
245
246fn ocxmode_l to int
247e = ocxeol 2
248n = ocxcopy 2 e
249r = oclowerl n
250if lt r 0
251ocxinv r
252ret 40
253end
254if eq r 41
255w = write 1 ocxbm 0 len ocxbm
256ocputrs get ocerr 1
257ocputc 10
258ret 41
259end
260w = write 1 ocxlo 0 len ocxlo
261for i ulong 4
262ocputc 32
263ocputn get oclv i
264end
265ocputc 10
266ret 0
267end
268
269fn ocxmode_t to int
270ocvinit
271w = write 1 ocvtsv 0 len ocvtsv
272if ne w long len ocvtsv
273exit 2
274end
275ret 0
276end
277
278fn ocxmode_j to int
279e = ocxeol 2
280pl = sub e 2
281if gt pl 4096
282ret 2
283end
284for i ulong pl
285put ocpath i get ocxin add 2 i
286end
287r = ocmjrf pl
288if lt r 0
289w = write 1 ocxmi 0 len ocxmi
290ocputn get ocerr 0
291ocputc 32
292ocmputrs get ocerr 1
293ocputc 10
294ret 43
295end
296w = write 1 ocxmj 0 len ocxmj
297ocmputo get ocmv 0
298ocputc 32
299ocputn get ocmv 1
300ocputc 32
301ocputn get ocmv 2
302ocputc 32
303ocmhex 8 40
304ocputc 32
305ocmhex 40 56
306ocputc 32
307ocmhex 144 176
308ocputc 10
309ret 0
310end
311
312fn main to int
313t = ulong 0
314fin = false
315while and lt t 16384 not fin bound 20000
316r = read 0 ocxin t sub 16384 t
317if le r 0
318fin = true
319else
320t = add t ulong r
321end
322end
323put ocxn 0 t
324if lt t 1
325ret 2
326end
327if gt t 1
328if ne get ocxin 1 10
329ret 2
330end
331end
332md = get ocxin 0
333if eq md 84
334ret ocxmode_t
335end
336if lt t 2
337ret 2
338end
339if eq md 86
340ret ocxmode_v
341end
342if eq md 78
343ret ocxmode_n
344end
345if eq md 66
346ret ocxmode_b
347end
348if eq md 76
349ret ocxmode_l
350end
351if eq md 69
352ret ocxmode_e
353end
354if eq md 68
355ret ocxmode_d
356end
357if eq md 74
358ret ocxmode_j
359end
360ret 2
361end