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 / aienux / allen / application.om

241 lines · 3864 bytes Raw Blame History
1note Native application binding: conversation state, courier lifecycle and reply/code.
2note A initialized, queued AGAIN bytes, per-call event, reserved.
3note Events:0 none,1 visible answer/ack,2 AGAIN queued,3 code give-up,
4note 4 refused LINE payload,5 slow notice,6 silence timeout.
5note Transport acceptance is separate from payload acceptance: appreceive true
6note means envelope accepted; inspect A2 for malformed payload, never invent text.
7global A ulong 4
8global Appjob uchar 4096
9global Appwire uchar 8192
10global Askin uchar 160
11fn appinit run ulong now ulong to bool
12if or ne get A 0 0 ne get R 0 0
13ret false
14end
15if ne get Q 0 0
16ret false
17end
18if not qstart run now
19ret false
20end
21constants
22put A 0 1
23put A 1 0
24put A 2 0
25ret true
26end
27fn appclock now ulong to bool
28if eq get A 0 0
29ret false
30end
31ret and ge now get T 0 ge now get R 4
32end
33fn appask now ulong to bool
34if not appclock now
35ret false
36end
37if or ne get R 1 0 ne get A 1 0
38ret false
39end
40if or ne get T 10 0 ne get T 13 0
41ret false
42end
43if and ne get T 5 0 eq get T 6 0
44ret false
45end
46if or ge get R 0 4294967295 ge get Q 1 4294967295
47ret false
48end
49if not textok
50ret false
51end
52kind = classify
53if or lt kind 1 gt kind 3
54ret false
55end
56if and eq kind 3 eq get R 6 0
57ret false
58end
59note Validate restored context before jobbuild reads its variable-layout names.
60if not ctxmeta 6
61ret false
62end
63if not jobbuild kind add get R 0 1
64ret false
65end
66if not ctxappend
67ret false
68end
69n = get Inlen 0
70size = get Outlen 0
71for i ulong n
72put Askin i get In i
73end
74for i ulong size
75put Appjob i get Outb i
76end
77for i ulong size
78put In i get Appjob i
79end
80put Inlen 0 size
81queued = qsubmit now
82for i ulong n
83put In i get Askin i
84end
85put Inlen 0 n
86if not queued
87ret false
88end
89note start preconditions were checked before qsubmit; no concurrent calls permitted.
90if not start kind now
91qcancel
92ret false
93end
94put A 2 0
95if gt kind 1
96codebeg get R 0
97put A 2 1
98end
99ret true
100end
101fn appcancel to void
102cancel
103qcancel
104put A 1 0
105put A 2 0
106end
107fn appreset to void
108appcancel
109reset
110end
111note First acknowledge the triggering LINE, then submit AGAIN with a new wire
112note sequence while retaining the original conversation ID in its body.
113fn appqueue now ulong to bool
114if eq get A 1 0
115ret true
116end
117if or ne get T 10 0 ne get T 13 0
118ret true
119end
120put Inlen 0 get A 1
121for i ulong get A 1
122put In i get Appjob i
123end
124if not qsubmit now
125ret false
126end
127put A 1 0
128ret true
129end
130fn apppoll now ulong online bool to bool
131if not appclock now
132ret false
133end
134put A 2 0
135put T 0 now
136status = tick now
137if eq status 1
138put A 2 5
139end
140if eq status 2
141qcancel
142put A 1 0
143put A 2 6
144end
145if not appqueue now
146appcancel
147put A 2 3
148ret false
149end
150ret qnext now online
151end
152fn appsent now ulong ok bool to bool
153if not appclock now
154ret false
155end
156if not qsent now ok
157ret false
158end
159put A 2 0
160ret true
161end
162fn appbody now ulong to bool
163if eq get R 1 0
164put A 2 4
165ret true
166end
167if ineq 0 67
168if or le get R 2 1 ne get C 0 get R 0
169put A 2 4
170ret true
171end
172if codetake
173if heard get C 0 now
174ret true
175end
176end
177put A 2 4
178ret true
179end
180if or ineq 0 83 ineq 0 87
181status = saytake now
182if eq status 1
183if eq get R 1 0
184put A 1 0
185end
186if ne get S 1 0
187put A 2 1
188end
189ret true
190end
191if eq status 2
192n = get Outlen 0
193if or eq n 0 gt n 4096
194cancel
195put A 1 0
196put A 2 3
197ret true
198end
199for i ulong n
200put Appjob i get Outb i
201end
202put A 1 n
203put A 2 2
204ret true
205end
206if eq status 3
207put A 1 0
208put A 2 3
209ret true
210end
211end
212put A 2 4
213ret true
214end
215note Reply parsing can serialize AGAIN internally. Preserve the already offered
216note datagram until the provider records its send result, including on refusal.
217fn appreceive now ulong to bool
218if not appclock now
219ret false
220end
221result = qincoming now
222if eq result 0
223ret false
224end
225put A 2 0
226if not qtake
227ret true
228end
229n = get Outlen 0
230e = get Err 0
231for i ulong n
232put Appwire i get Outb i
233end
234ok = appbody now
235for i ulong n
236put Outb i get Appwire i
237end
238put Outlen 0 n
239put Err 0 e
240ret ok
241end