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 / native / omegese45 / mjr1.om

174 lines · 3348 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note MJR1 receipt parser (aien-train #45, contract lane). Requires vocab.om before it.
3note Layout and static rules follow aien-dev/aien-protocols-mv e705fdc9
4note crates/aien-microjob/src/lib.rs: RECEIPT_MAGIC L34, VERSION L36, RECEIPT_LEN L38,
5note mod outcome L103-109, encode_receipt L857-883, decode_receipt L885-928;
6note specs/microjob/SPEC.md section 5 (L162-206). Integers are big-endian.
7note The signature (bytes 340..404 over [0,340)) is NOT verified here.
8note Public API: fn ocmjr n ulong to long (ocrb[0,n)) -> outcome 1..5 | -reason;
9note fn ocmjrf plen ulong to long (path ocpath[0,plen)) -> same; ocmv = outcome attempt generation.
10note Every refusal maps to exit 43 MJR1_INVALID in callers.
11const ocmlen ulong 404
12const ocmrlen long 1
13const ocmrmag long 2
14const ocmrver long 3
15const ocmrres long 4
16const ocmrout long 5
17const ocmratt long 6
18const ocmrsig long 7
19const ocmrzero long 8
20const ocmrdig long 9
21const ocmrvrd long 10
22const ocmrio long 11
23text ocmtx "length magic version reservedoutcome attempt signer zerohashoutput verdict io "
24text ocmotx "completedrefused failed cancelleduncertain"
25global ocrb uchar 512
26global ocpath uchar 4096
27global ocmv ulong 3
28
29fn ocmz a ulong b ulong to bool
30for i ulong sub b a
31if ne get ocrb add a i 0
32ret false
33end
34end
35ret true
36end
37
38fn ocmu32 a ulong to ulong
39v = ulong 0
40for i ulong 4
41v = add mul v 256 ulong get ocrb add a i
42end
43ret v
44end
45
46fn ocmjr n ulong to long
47if ne n ocmlen
48ret ocerrset n ocmrlen
49end
50note magic "MJR1"
51mg = true
52if ne get ocrb 0 77
53mg = false
54end
55if ne get ocrb 1 74
56mg = false
57end
58if ne get ocrb 2 82
59mg = false
60end
61if ne get ocrb 3 49
62mg = false
63end
64if not mg
65ret ocerrset 0 ocmrmag
66end
67if ne get ocrb 4 1
68ret ocerrset 4 ocmrver
69end
70if ne get ocrb 7 0
71ret ocerrset 7 ocmrres
72end
73if not ocmz 84 88
74ret ocerrset 84 ocmrres
75end
76if not ocmz 337 340
77ret ocerrset 337 ocmrres
78end
79oc = get ocrb 5
80if or lt oc 1 gt oc 5
81ret ocerrset 5 ocmrout
82end
83if eq get ocrb 6 0
84ret ocerrset 6 ocmratt
85end
86sg = get ocrb 304
87if and ne sg 2 ne sg 3
88ret ocerrset 304 ocmrsig
89end
90if ocmz 176 208
91ret ocerrset 176 ocmrzero
92end
93if ocmz 240 272
94ret ocerrset 240 ocmrzero
95end
96done = eq oc 1
97if eq done ocmz 144 176
98ret ocerrset 144 ocmrdig
99end
100if done
101if ocmz 272 304
102ret ocerrset 272 ocmrvrd
103end
104end
105put ocmv 0 ulong oc
106put ocmv 1 ulong get ocrb 6
107put ocmv 2 ocmu32 72
108ret long oc
109end
110
111note Read at most 512 bytes of the file named by ocpath[0,plen), then parse.
112fn ocmjrf plen ulong to long
113if or eq plen 0 gt plen 4096
114ret ocerrset 0 ocmrio
115end
116fd = fopen ocpath 0 plen 0 0
117if lt fd 0
118ret ocerrset 0 ocmrio
119end
120t = ulong 0
121fin = false
122while and lt t 512 not fin bound 600
123r = read int fd ocrb t sub 512 t
124if lt r 0
125c = fclose int fd
126ret ocerrset t ocmrio
127end
128if eq r 0
129fin = true
130end
131t = add t ulong r
132end
133c = fclose int fd
134ret ocmjr t
135end
136
137fn ocmputrs r ulong to void
138o = mul sub r 1 8
139for j ulong 8
140ch = get ocmtx add o j
141if ne ch 32
142ocputc ch
143end
144end
145end
146
147fn ocmputo oc ulong to void
148o = mul sub oc 1 9
149for j ulong 9
150ch = get ocmotx add o j
151if ne ch 32
152ocputc ch
153end
154end
155end
156
157note Print ocrb[a,b) as lowercase hex.
158fn ocmhex a ulong b ulong to void
159for i ulong sub b a
160v = get ocrb add a i
161h = div v 16
162l = rem v 16
163if lt h 10
164ocputc add h 48
165else
166ocputc add h 87
167end
168if lt l 10
169ocputc add l 48
170else
171ocputc add l 87
172end
173end
174end