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 / core / sovereign-core / om / effects / world.om

438 lines · 7833 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Effect world check (ACCEPTANCE-v2 2.2) and reconcile record text in seeded Omega.
3note Same bytes as aien-runtime effects::world_state (file_sha256, state_from), the reference world
4note check, not the confined production path (confined_world_state), followed by
5note effects::reconcile_text with no declaration and no objective; om/effects/run.sh compares them.
6note Build: cat om/vendor/sha256.om om/effects/world.om | omc > world
7note Usage: world TARGET CONTENT_SHA256 PRIOR_SHA256|- INTENT AUTHORIZATION BY
8note Output: the record text, newline, sha256 of the text (append's text_sha256), newline; exit 0.
9note Refused (exit 2, no output): argument count, arguments over 16 KiB, a target over 4095 bytes,
10note a number Rust's u64 parse refuses, an errno with no message in em, a full buffer.
11global ga uchar 16384
12global gs ulong 8
13global gl ulong 8
14global ob uchar 65536
15global eb uchar 8192
16global sb uchar 128
17global fb uchar 65536
18global dg uchar 64
19note wk: 0 output length, 1 error length, 2 digest present, 3 error present, 4 refused,
20note 5 intent, 6 authorization, 7 state (0 DONE, 1 NOT_DONE, 2 UNRESOLVED).
21global wk ulong 8
22text lit "{\"authorization\":~,\"by\":~,\"disk_error\":~,\"disk_sha256\":~,\"intent\":~,\"phase\":\"reconcile\",\"state\":\"~\",\"world\":\"~\"}~null~DONE~NOT_DONE~UNRESOLVED~stat ~: ~ (os error ~)~ is not a regular file~read "
23note em: glibc strerror text for the errnos a stat, open or read of a path can give; Rust's
24note io::Error prints "<text> (os error N)". Every entry ends in ~.
25text em "1 Operation not permitted~2 No such file or directory~5 Input/output error~6 No such device or address~12 Cannot allocate memory~13 Permission denied~14 Bad address~20 Not a directory~21 Is a directory~23 Too many open files in system~24 Too many open files~36 File name too long~40 Too many levels of symbolic links~75 Value too large for defined data type~"
26text hx "0123456789abcdef"
27text nl "\n"
28
29note badd: append byte c to the output (d 0) or to the error message (d 1); a full buffer refuses.
30fn badd d ulong c uchar to void
31if eq d 0
32n0 = get wk 0
33if ge n0 len ob
34put wk 4 1
35ret
36end
37put ob n0 c
38put wk 0 add n0 1
39ret
40end
41n1 = get wk 1
42if ge n1 len eb
43put wk 4 1
44ret
45end
46put eb n1 c
47put wk 1 add n1 1
48end
49
50note frag: append fragment k of lit (fragments are separated by ~, byte 126) to d.
51fn frag d ulong k ulong to void
52c = ulong 0
53for i ulong len lit
54b = get lit i
55if eq b 126
56c = add c 1
57else
58if eq c k
59badd d b
60end
61end
62end
63end
64
65note dec: append v in decimal to d.
66fn dec d ulong v ulong to void
67p = ulong 1
68while le p div v 10
69p = mul p 10
70end
71while ne p 0
72badd d uchar add div v p 48
73v = rem v p
74p = div p 10
75end
76end
77
78note esc: append byte c to the output as serde_json writes it inside a string.
79fn esc c uchar to void
80if or eq c 34 eq c 92
81badd 0 92
82badd 0 c
83ret
84end
85if ge c 32
86badd 0 c
87ret
88end
89badd 0 92
90if eq c 8
91badd 0 98
92ret
93end
94if eq c 12
95badd 0 102
96ret
97end
98if eq c 10
99badd 0 110
100ret
101end
102if eq c 13
103badd 0 114
104ret
105end
106if eq c 9
107badd 0 116
108ret
109end
110badd 0 117
111badd 0 48
112badd 0 48
113badd 0 get hx ulong shr c 4
114badd 0 get hx ulong and c 15
115end
116
117note sarg: append argument i to the output as a JSON string.
118fn sarg i ulong to void
119badd 0 34
120s = get gs i
121for j ulong get gl i
122esc get ga add s j
123end
124badd 0 34
125end
126
127note serr: append the error message to the output as a JSON string.
128fn serr to void
129badd 0 34
130for j ulong get wk 1
131esc get eb j
132end
133badd 0 34
134end
135
136note apath: append the target (argument 1) to the error message, as Path::display shows it.
137fn apath to void
138s = get gs 1
139for j ulong get gl 1
140badd 1 get ga add s j
141end
142end
143
144note emsg: append "<text> (os error e)" to the error message; an errno outside em refuses.
145fn emsg e ulong to void
146i = ulong 0
147m = len em
148while lt i m
149v = ulong 0
150while ne get em i 32
151v = add mul v 10 ulong sub get em i 48
152i = add i 1
153end
154i = add i 1
155if eq v e
156while ne get em i 126
157badd 1 get em i
158i = add i 1
159end
160frag 1 14
161dec 1 e
162frag 1 15
163ret
164end
165while ne get em i 126
166i = add i 1
167end
168i = add i 1
169end
170put wk 4 1
171end
172
173note eerr: the error message "<stat |read ><target>: <text> (os error e)" (k 12 stat, 17 read).
174fn eerr k ulong e ulong to void
175frag 1 k
176apath
177frag 1 13
178emsg e
179put wk 3 1
180end
181
182note hfile: sha256 of the target's bytes into dg (wk 2 = 1), or a read error.
183fn hfile to void
184z = long 0
185fd = fopen ga get gs 1 get gl 1 524288 0
186if lt fd 0
187eerr 17 ulong sub z fd
188ret
189end
190hreset
191more = true
192while more
193r = read int fd fb 0 len fb
194if ne r -4
195if lt r 0
196x = fclose int fd
197eerr 17 ulong sub z r
198ret
199end
200if eq r 0
201more = false
202else
203for i ulong ulong r
204if not hpush get fb i
205put wk 4 1
206end
207end
208end
209end
210end
211y = fclose int fd
212if not hfinal
213put wk 4 1
214ret
215end
216for j ulong 64
217put dg j get hd j
218end
219put wk 2 1
220end
221
222note world: effects::file_sha256. Absent (ENOENT from lstat) leaves wk 2 and wk 3 at 0; a
223note lstat error or a target that is not a regular file is an error; else the digest.
224note An empty target is absent: Linux answers ENOENT for it, and Omega refuses an empty path
225note before the call (trap 3), so the kernel's answer is given here.
226fn world to void
227if eq get gl 1 0
228ret
229end
230z = long 0
231r = lstat ga get gs 1 get gl 1 sb 0 128
232if eq r -2
233ret
234end
235if lt r 0
236eerr 12 ulong sub z r
237ret
238end
239m = or ulong get sb 16 shl ulong get sb 17 8
240if ne and m 61440 32768
241apath
242frag 1 16
243put wk 3 1
244ret
245end
246hfile
247end
248
249note pnum: argument i as a u64, as Rust's str::parse: an optional +, then at least one digit.
250fn pnum i ulong to ulong
251s = get gs i
252n = get gl i
253j = ulong 0
254if gt n 0
255if eq get ga s 43
256j = 1
257end
258end
259if ge j n
260put wk 4 1
261ret 0
262end
263mx = ulong 0
264mx = sub mx 1
265v = ulong 0
266while lt j n
267c = get ga add s j
268if or lt c 48 gt c 57
269put wk 4 1
270ret 0
271end
272d = ulong sub c 48
273if gt v div sub mx d 10
274put wk 4 1
275ret 0
276end
277v = add mul v 10 d
278j = add j 1
279end
280ret v
281end
282
283note pnone: 1 when argument 3 is exactly "-" (no prior digest: the file was absent).
284fn pnone to ulong
285if ne get gl 3 1
286ret 0
287end
288if ne get ga get gs 3 45
289ret 0
290end
291ret 1
292end
293
294note dgeq: 1 when argument i equals the digest read from the target.
295fn dgeq i ulong to ulong
296if ne get gl i 64
297ret 0
298end
299s = get gs i
300for j ulong 64
301if ne get ga add s j get dg j
302ret 0
303end
304end
305ret 1
306end
307
308note decide: effects::state_from. DONE when the digest is the content; NOT_DONE when the
309note digest (or absence) is the prior; else UNRESOLVED, and always UNRESOLVED on an error.
310fn decide to ulong
311if eq get wk 3 1
312ret 2
313end
314if eq get wk 2 0
315if eq pnone 1
316ret 1
317end
318ret 2
319end
320if eq dgeq 2 1
321ret 0
322end
323if eq pnone 0
324if eq dgeq 3 1
325ret 1
326end
327end
328ret 2
329end
330
331note record: effects::reconcile_text, keys in serde_json's sorted order, compact.
332fn record to void
333frag 0 0
334dec 0 get wk 6
335frag 0 1
336sarg 6
337frag 0 2
338if eq get wk 3 1
339serr
340else
341frag 0 8
342end
343frag 0 3
344if eq get wk 2 1
345badd 0 34
346for j ulong 64
347badd 0 get dg j
348end
349badd 0 34
350else
351frag 0 8
352end
353frag 0 4
354dec 0 get wk 5
355frag 0 5
356frag 0 add 9 get wk 7
357frag 0 6
358frag 0 add 9 get wk 7
359frag 0 7
360end
361
362note args: arguments 1..6 into ga; false when they do not fit.
363fn args to bool
364o = ulong 0
365for i ulong 7
366if gt i 0
367r = argread i ga o sub len ga o
368if lt r 0
369ret false
370end
371put gs i o
372put gl i ulong r
373o = add o ulong r
374end
375end
376ret true
377end
378
379note wout: write the record, a newline, its sha256 and a newline.
380fn wout to bool
381o = ulong 0
382m = get wk 0
383while lt o m
384w = write 1 ob o sub m o
385if ne w -4
386if le w 0
387ret false
388end
389o = add o ulong w
390end
391end
392if ne write 1 nl 0 1 1
393ret false
394end
395if ne write 1 hd 0 64 64
396ret false
397end
398if ne write 1 nl 0 1 1
399ret false
400end
401ret true
402end
403
404fn main to int
405if ne argcnt 7
406ret 2
407end
408if not args
409ret 2
410end
411put wk 5 pnum 4
412put wk 6 pnum 5
413if gt get gl 1 4095
414ret 2
415end
416world
417if ne get wk 4 0
418ret 2
419end
420put wk 7 decide
421record
422if ne get wk 4 0
423ret 2
424end
425hreset
426for i ulong get wk 0
427if not hpush get ob i
428ret 2
429end
430end
431if not hfinal
432ret 2
433end
434if not wout
435ret 74
436end
437ret 0
438end