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 / kernel / core / lifecycle.om

511 lines · 10217 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/core/lifecycle.om: Pure-Omega Resident Production Lifecycle FSM.
3note Converted from upstream aienux native/kernel/core/lifecycle_fsm.h and lifecycle_fsm.c.
4
5note States
6const LC_INIT uint 0
7const LC_LOCKED uint 1
8const LC_READY uint 2
9const LC_SERVE uint 3
10const LC_QUIESCE uint 4
11const LC_STOP uint 5
12
13note Verbs
14const LC_V_INVALID int -1
15const LC_V_UNKNOWN int 0
16const LC_V_EMPTY int 1
17const LC_V_HELP int 2
18const LC_V_STATUS int 3
19const LC_V_UNLOCK int 4
20const LC_V_TASK int 5
21const LC_V_APPROVE int 6
22const LC_V_DENY int 7
23const LC_V_CANCEL int 8
24const LC_V_EVIDENCE int 9
25const LC_V_SHUTDOWN int 10
26const LC_V_PROMPT int 11
27const LC_V_RECALL int 12
28const LC_V_REMEMBER int 13
29const LC_V_FACTS int 14
30const LC_V_ROTATE int 15
31const LC_V_UPDATE int 16
32const LC_V_PREFER int 17
33
34note Pending kinds
35const LC_PENDING_NONE uint 0
36const LC_PENDING_NOTE uint 1
37const LC_PENDING_REPLY uint 2
38
39note Transition outcomes
40const LC_R_OK uint 0
41const LC_R_REFUSED uint 1
42const LC_R_INVALID uint 2
43const LC_R_COMMIT uint 3
44const LC_R_UNLOCK uint 4
45const LC_R_STOP uint 5
46const LC_R_GENERATE uint 6
47const LC_R_RECALL uint 7
48const LC_R_REMEMBER uint 8
49const LC_R_FACTS uint 9
50const LC_R_ROTATE uint 10
51const LC_R_UPDATE uint 11
52const LC_R_PREFER uint 12
53
54note Generation completion outcomes
55const LC_GEN_REPLY uint 0
56const LC_GEN_CANCELLED uint 1
57const LC_GEN_FAILED uint 2
58
59note Bounds
60const LC_LINE_MAX ulong 144
61const LC_TASK_MAX ulong 48
62const LC_REPLY_MAX ulong 1536
63
64note Counters indices in lc_cnt (18 u32s)
65const LC_C_STATE ulong 0
66const LC_C_PENDING ulong 1
67const LC_C_TASK_LEN ulong 2
68const LC_C_REPLY_LEN ulong 3
69const LC_C_FACT_LEN ulong 4
70const LC_C_REQUESTS ulong 5
71const LC_C_REFUSED ulong 6
72const LC_C_INVALID ulong 7
73const LC_C_TASKS ulong 8
74const LC_C_APPROVED ulong 9
75const LC_C_DENIED ulong 10
76const LC_C_CANCELLED ulong 11
77const LC_C_PROMPTS ulong 12
78const LC_C_REPLIES ulong 13
79const LC_C_GEN_CANCEL ulong 14
80const LC_C_GEN_FAIL ulong 15
81const LC_C_RECALLS ulong 16
82const LC_C_REMEMBERS ulong 17
83const LC_C_FACTS ulong 18
84const LC_C_UPDATES ulong 19
85const LC_C_PREFERS ulong 20
86const LC_C_BIND_REF ulong 21
87const LC_C_REPLAYS ulong 22
88
89global lc_cnt uint 24
90global lc_task uchar 48
91global lc_fact uchar 48
92global lc_reply uchar 1536
93
94text lcw_task "task"
95text lcw_prompt "prompt"
96text lcw_remember "remember"
97text lcw_prefer "prefer"
98text lcw_unlock "unlock"
99text lcw_rotate "rotate"
100text lcw_update "update"
101text lcw_help "help"
102text lcw_status "status"
103text lcw_approve "approve"
104text lcw_deny "deny"
105text lcw_cancel "cancel"
106text lcw_recall "recall"
107text lcw_facts "facts"
108text lcw_evidence "evidence"
109text lcw_shutdown "shutdown"
110
111fn lc_word_is line view uchar * ws ulong wlen ulong lit view uchar * to bool
112if ne wlen len lit
113ret false
114end
115i = ulong 0
116while lt i wlen bound 32
117if ne get line add ws i get lit i
118ret false
119end
120i = add i 1
121end
122ret true
123end
124
125fn lc_decode_noarg line view uchar * ws ulong wn ulong to int
126if lc_word_is line ws wn lcw_help
127ret LC_V_HELP
128end
129if lc_word_is line ws wn lcw_status
130ret LC_V_STATUS
131end
132if lc_word_is line ws wn lcw_approve
133ret LC_V_APPROVE
134end
135if lc_word_is line ws wn lcw_deny
136ret LC_V_DENY
137end
138if lc_word_is line ws wn lcw_cancel
139ret LC_V_CANCEL
140end
141if lc_word_is line ws wn lcw_recall
142ret LC_V_RECALL
143end
144if lc_word_is line ws wn lcw_facts
145ret LC_V_FACTS
146end
147if lc_word_is line ws wn lcw_evidence
148ret LC_V_EVIDENCE
149end
150if lc_word_is line ws wn lcw_shutdown
151ret LC_V_SHUTDOWN
152end
153ret LC_V_UNKNOWN
154end
155
156fn lc_decode line view uchar * arg_out edit LcArg to int
157put arg_out off 0
158put arg_out alen 0
159n = len line
160if gt n LC_LINE_MAX
161ret LC_V_INVALID
162end
163i = ulong 0
164while lt i n bound 144
165ch = get line i
166if or lt ch 0x20 gt ch 0x7e
167ret LC_V_INVALID
168end
169i = add i 1
170end
171i = ulong 0
172while lt i n bound 144
173if ne get line i 32
174break
175end
176i = add i 1
177end
178if eq i n
179ret LC_V_EMPTY
180end
181ws = i
182while lt i n bound 144
183if eq get line i 32
184break
185end
186i = add i 1
187end
188we = i
189while lt i n bound 144
190if ne get line i 32
191break
192end
193i = add i 1
194end
195aend = n
196while gt aend i bound 144
197if ne get line sub aend 1 32
198break
199end
200aend = sub aend 1
201end
202alen = sub aend i
203put arg_out off i
204put arg_out alen alen
205wn = sub we ws
206if lc_word_is line ws wn lcw_task
207if or eq alen 0 gt alen LC_TASK_MAX
208ret LC_V_INVALID
209end
210ret LC_V_TASK
211end
212if lc_word_is line ws wn lcw_prompt
213if or eq alen 0 gt alen LC_TASK_MAX
214ret LC_V_INVALID
215end
216ret LC_V_PROMPT
217end
218if lc_word_is line ws wn lcw_remember
219if or eq alen 0 gt alen LC_TASK_MAX
220ret LC_V_INVALID
221end
222ret LC_V_REMEMBER
223end
224if lc_word_is line ws wn lcw_prefer
225if or eq alen 0 gt alen LC_TASK_MAX
226ret LC_V_INVALID
227end
228ret LC_V_PREFER
229end
230if lc_word_is line ws wn lcw_unlock
231ret LC_V_UNLOCK
232end
233if lc_word_is line ws wn lcw_rotate
234ret LC_V_ROTATE
235end
236if lc_word_is line ws wn lcw_update
237ret LC_V_UPDATE
238end
239if ne alen 0
240ret LC_V_INVALID
241end
242ret lc_decode_noarg line ws wn
243end
244
245fn lc_init to void
246for i ulong 24
247put lc_cnt i 0
248end
249for i ulong 48
250put lc_task i 0
251put lc_fact i 0
252end
253for i ulong 1536
254put lc_reply i 0
255end
256put lc_cnt LC_C_STATE LC_INIT
257end
258
259fn lc_start store_open bool to void
260if store_open
261put lc_cnt LC_C_STATE LC_READY
262else
263put lc_cnt LC_C_STATE LC_LOCKED
264end
265end
266
267fn lc_drop_task to void
268for i ulong 48
269put lc_task i 0
270end
271for i ulong 1536
272put lc_reply i 0
273end
274put lc_cnt LC_C_TASK_LEN 0
275put lc_cnt LC_C_REPLY_LEN 0
276put lc_cnt LC_C_PENDING LC_PENDING_NONE
277end
278
279fn lc_set_task arg view uchar * to void
280n = len arg
281i = ulong 0
282while lt i n bound 48
283put lc_task i get arg i
284i = add i 1
285end
286put lc_cnt LC_C_TASK_LEN uint n
287end
288
289fn lc_set_fact arg view uchar * to void
290n = len arg
291i = ulong 0
292while lt i n bound 48
293put lc_fact i get arg i
294i = add i 1
295end
296put lc_cnt LC_C_FACT_LEN uint n
297end
298
299fn lc_refuse to uint
300put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
301ret LC_R_REFUSED
302end
303
304fn lc_apply_ready_verbs verb int arg view uchar * st uint to uint
305alen = len arg
306if eq verb LC_V_TASK
307if or eq st LC_LOCKED or eq st LC_SERVE or eq alen 0 gt alen LC_TASK_MAX
308ret lc_refuse
309end
310lc_set_task arg
311put lc_cnt LC_C_PENDING LC_PENDING_NOTE
312put lc_cnt LC_C_TASKS add get lc_cnt LC_C_TASKS 1
313put lc_cnt LC_C_STATE LC_SERVE
314ret LC_R_OK
315end
316if eq verb LC_V_PROMPT
317if or eq st LC_LOCKED or eq st LC_SERVE or eq alen 0 gt alen LC_TASK_MAX
318ret lc_refuse
319end
320lc_set_task arg
321put lc_cnt LC_C_PROMPTS add get lc_cnt LC_C_PROMPTS 1
322ret LC_R_GENERATE
323end
324if eq verb LC_V_RECALL
325if eq st LC_LOCKED
326ret lc_refuse
327end
328put lc_cnt LC_C_RECALLS add get lc_cnt LC_C_RECALLS 1
329ret LC_R_RECALL
330end
331if eq verb LC_V_REMEMBER
332if or eq st LC_LOCKED or eq alen 0 gt alen LC_TASK_MAX
333ret lc_refuse
334end
335lc_set_fact arg
336put lc_cnt LC_C_REMEMBERS add get lc_cnt LC_C_REMEMBERS 1
337ret LC_R_REMEMBER
338end
339if eq verb LC_V_PREFER
340if or eq st LC_LOCKED or eq alen 0 gt alen LC_TASK_MAX
341ret lc_refuse
342end
343lc_set_fact arg
344put lc_cnt LC_C_PREFERS add get lc_cnt LC_C_PREFERS 1
345ret LC_R_PREFER
346end
347if eq verb LC_V_FACTS
348if eq st LC_LOCKED
349ret lc_refuse
350end
351put lc_cnt LC_C_FACTS add get lc_cnt LC_C_FACTS 1
352ret LC_R_FACTS
353end
354ret lc_refuse
355end
356
357fn lc_apply verb int arg view uchar * to uint
358put lc_cnt LC_C_REQUESTS add get lc_cnt LC_C_REQUESTS 1
359st = get lc_cnt LC_C_STATE
360if or eq st LC_QUIESCE or eq st LC_STOP eq st LC_INIT
361ret lc_refuse
362end
363if eq verb LC_V_INVALID
364put lc_cnt LC_C_INVALID add get lc_cnt LC_C_INVALID 1
365ret LC_R_INVALID
366end
367if eq verb LC_V_UNKNOWN
368ret lc_refuse
369end
370if or eq verb LC_V_EMPTY or eq verb LC_V_HELP or eq verb LC_V_STATUS eq verb LC_V_EVIDENCE
371ret LC_R_OK
372end
373if eq verb LC_V_UNLOCK
374if ne st LC_LOCKED
375ret lc_refuse
376end
377ret LC_R_UNLOCK
378end
379if eq verb LC_V_ROTATE
380if or eq st LC_LOCKED or eq st LC_SERVE eq len arg 0
381ret lc_refuse
382end
383ret LC_R_ROTATE
384end
385if eq verb LC_V_UPDATE
386if or eq st LC_LOCKED eq st LC_SERVE
387ret lc_refuse
388end
389put lc_cnt LC_C_UPDATES add get lc_cnt LC_C_UPDATES 1
390ret LC_R_UPDATE
391end
392if eq verb LC_V_APPROVE
393if ne st LC_SERVE
394ret lc_refuse
395end
396ret LC_R_COMMIT
397end
398if eq verb LC_V_DENY
399if ne st LC_SERVE
400ret lc_refuse
401end
402put lc_cnt LC_C_DENIED add get lc_cnt LC_C_DENIED 1
403lc_drop_task
404put lc_cnt LC_C_STATE LC_READY
405ret LC_R_OK
406end
407if eq verb LC_V_CANCEL
408if ne st LC_SERVE
409ret lc_refuse
410end
411put lc_cnt LC_C_CANCELLED add get lc_cnt LC_C_CANCELLED 1
412lc_drop_task
413put lc_cnt LC_C_STATE LC_READY
414ret LC_R_OK
415end
416if eq verb LC_V_SHUTDOWN
417if eq st LC_SERVE
418lc_drop_task
419end
420put lc_cnt LC_C_STATE LC_QUIESCE
421ret LC_R_STOP
422end
423ret lc_apply_ready_verbs verb arg st
424end
425
426fn lc_commit_done rc int to void
427if ne get lc_cnt LC_C_STATE LC_SERVE
428ret
429end
430if eq rc 0
431put lc_cnt LC_C_APPROVED add get lc_cnt LC_C_APPROVED 1
432lc_drop_task
433put lc_cnt LC_C_STATE LC_READY
434else
435put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
436end
437end
438
439fn lc_commit_replay to void
440if ne get lc_cnt LC_C_STATE LC_SERVE
441ret
442end
443put lc_cnt LC_C_REPLAYS add get lc_cnt LC_C_REPLAYS 1
444put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
445lc_drop_task
446put lc_cnt LC_C_STATE LC_READY
447end
448
449fn lc_commit_refused to void
450if ne get lc_cnt LC_C_STATE LC_SERVE
451ret
452end
453put lc_cnt LC_C_BIND_REF add get lc_cnt LC_C_BIND_REF 1
454put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
455end
456
457fn lc_unlock_done opened bool to void
458if ne get lc_cnt LC_C_STATE LC_LOCKED
459ret
460end
461if opened
462put lc_cnt LC_C_STATE LC_READY
463else
464put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
465end
466end
467
468fn lc_rotate_done ok bool to void
469if ne get lc_cnt LC_C_STATE LC_READY
470ret
471end
472if not ok
473put lc_cnt LC_C_REFUSED add get lc_cnt LC_C_REFUSED 1
474end
475end
476
477fn lc_generate_done outcome uint reply view uchar * to void
478if or ne get lc_cnt LC_C_STATE LC_READY eq get lc_cnt LC_C_TASK_LEN 0
479ret
480end
481rlen = len reply
482if and eq outcome LC_GEN_REPLY and gt rlen 0 le rlen LC_REPLY_MAX
483i = ulong 0
484while lt i rlen bound 1536
485put lc_reply i get reply i
486i = add i 1
487end
488put lc_cnt LC_C_REPLY_LEN uint rlen
489put lc_cnt LC_C_PENDING LC_PENDING_REPLY
490put lc_cnt LC_C_REPLIES add get lc_cnt LC_C_REPLIES 1
491put lc_cnt LC_C_STATE LC_SERVE
492ret
493end
494if eq outcome LC_GEN_CANCELLED
495put lc_cnt LC_C_GEN_CANCEL add get lc_cnt LC_C_GEN_CANCEL 1
496else
497put lc_cnt LC_C_GEN_FAIL add get lc_cnt LC_C_GEN_FAIL 1
498end
499lc_drop_task
500end
501
502fn lc_stopped to void
503put lc_cnt LC_C_STATE LC_STOP
504end
505
506fn lc_get_cnt idx ulong to uint
507if ge idx 24
508ret 0
509end
510ret get lc_cnt idx
511end