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 / protocol / synapse / claims / src / 10_base.om

395 lines · 7119 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note synapse-claims (aien-dev/synapse-claims): append-only, hash-chained, signed lease ledger for AI lanes.
3note Unit = om2 line + om/tls/sha2.om + src/*.om (build.sh). This file: capacities, global state, buffered
4note output, the string arena, word tables, decimal and hex helpers, die.
5
6const lncap ulong 65536
7const ncl ulong 131072
8const nf ulong 24
9const arcap ulong 33554432
10const arbank ulong 16777216
11const pecap ulong 8388608
12const outcap ulong 524288
13const errcap ulong 8192
14const socap ulong 1048576
15const sicap ulong 1048576
16const htmask ulong 262143
17const evcap ulong 65536
18const tbad ulong 18446744073709551615
19
20note gx cells (scalar state)
21const xoutn ulong 0
22const xerrn ulong 1
23const xsel ulong 2
24const xarn ulong 3
25const xnc ulong 4
26const xseq ulong 5
27const xnow ulong 6
28const xpkn ulong 7
29const xson ulong 8
30const xsin ulong 9
31const xmfd ulong 10
32const xpen ulong 11
33const xpec ulong 12
34const xlfd ulong 13
35const xlkfd ulong 14
36const xlp ulong 15
37const xrfd ulong 16
38const xrpos ulong 17
39const xrlen ulong 18
40const xreof ulong 19
41const xhome ulong 20
42const xhomel ulong 21
43const xpled ulong 22
44const xpledl ulong 23
45const xplk ulong 24
46const xplkl ulong 25
47const xpkey ulong 26
48const xpkeyl ulong 27
49const xppub ulong 28
50const xppubl ulong 29
51const xpkd ulong 30
52const xpkdl ulong 31
53const xsig ulong 32
54const xsigl ulong 33
55const xevn ulong 34
56const xbad ulong 35
57const xwhy ulong 36
58const xcmd ulong 37
59const xall ulong 38
60const xnowset ulong 39
61const xidv ulong 40
62const xttl ulong 41
63const xmode ulong 42
64const xstate ulong 43
65const xpos ulong 44
66const xkind ulong 45
67
68global gout uchar 524288
69global gerr uchar 8192
70note gar0/gar1: the arcap-byte string arena as two banks; one global holds at most 16777216 elements
71global gar0 uchar 16777216
72global gar1 uchar 16777216
73global gcl ulong 3145728
74global ght ulong 262144
75global ghk ulong 262144
76global gpend uchar 8388608
77global gpe ulong 8192
78global gso uchar 1048576
79global gsi uchar 1048576
80global grd uchar 65536
81global gpk uchar 4096
82global glh uchar 64
83global gtb uchar 32
84global gst uchar 64
85global gevb uchar 16384
86global gx ulong 64
87global gp ulong 64
88global gop ulong 64
89global gev ulong 32
90global gfd uchar 8
91global gws uchar 4
92
93note word tables: index = position of the space-separated word
94note wall: ops 0..4 (code-1), states 5..12 (code+4), kinds 13..17 (code+12), modes 18 excl 19 shared
95text wall "claim renew release state expire PROPOSED IMPLEMENTED EXERCISED QUALIFIED MERGED DEPLOYED NOT_RUN BLOCKED repo branch path pr ext excl shared"
96text wreason "same_target repo_covers path_overlap ext_casefold"
97text wcmds "init claim renew release state who list conflicts verify expire"
98text wflags "--home --now --sig-bin --agent --session --target --ttl --mode --state --intent --evidence --import --id --all --agent-prefix"
99text wwhy "malformed seq prev hash id signature"
100
101text tpref "synapse-claims: "
102text tjerr "{\"ok\":false,\"error\":\""
103text tjend "\"}\n"
104text ttrue "true"
105text tfalse "false"
106text mfull "arena full"
107
108note ======== word tables ========
109
110fn tw_off t view uchar * w ulong to ulong
111k = ulong 0
112p = ulong 0
113while lt p len t bound 999999
114if eq k w
115ret p
116end
117if eq get t p 32
118k = add k 1
119end
120p = add p 1
121end
122ret p
123end
124
125fn tw_len t view uchar * w ulong to ulong
126s = tw_off t w
127e = s
128while lt e len t bound 999999
129if eq get t e 32
130ret sub e s
131end
132e = add e 1
133end
134ret sub e s
135end
136
137note tw_eqat: s equals t[p .. p+len s)
138fn tw_eqat s edit uchar * t view uchar * p ulong to bool
139for i ulong len s
140if ne get s i get t add p i
141ret false
142end
143end
144ret true
145end
146
147note tw_find: index of the word in t[base .. base+cnt) equal to s (whole slice), or tbad
148fn tw_find s edit uchar * t view uchar * base ulong cnt ulong to ulong
149for k ulong cnt
150w = add base k
151if eq tw_len t w len s
152if tw_eqat s t tw_off t w
153ret w
154end
155end
156end
157ret tbad
158end
159
160note ======== buffered output: xsel 0 stdout (gout), 1 stderr (gerr) ========
161
162fn o_flush to void
163n = get gx xoutn
164p = ulong 0
165while lt p n bound 999999
166w = write 1 gout p sub n p
167if le w 0
168exit 70
169end
170p = add p ulong w
171end
172put gx xoutn 0
173end
174
175fn e_flush to void
176n = get gx xerrn
177p = ulong 0
178while lt p n bound 999999
179w = write 2 gerr p sub n p
180if le w 0
181break
182end
183p = add p ulong w
184end
185put gx xerrn 0
186end
187
188fn o_b c uchar to void
189if eq get gx xsel 1
190m = get gx xerrn
191if lt m errcap
192put gerr m c
193put gx xerrn add m 1
194end
195ret
196end
197if ge get gx xoutn outcap
198o_flush
199end
200n = get gx xoutn
201put gout n c
202put gx xoutn add n 1
203end
204
205fn o_t t view uchar * to void
206for i ulong len t
207o_b get t i
208end
209end
210
211fn o_wd t view uchar * w ulong to void
212p = tw_off t w
213for i ulong tw_len t w
214o_b get t add p i
215end
216end
217
218fn o_ar off ulong n ulong to void
219for i ulong n
220o_b ar_g add off i
221end
222end
223
224fn o_u v ulong to void
225x = v
226k = ulong 0
227for i ulong 20
228put gst i uchar add 48 rem x 10
229x = div x 10
230k = add k 1
231if eq x 0
232break
233end
234end
235for j ulong k
236o_b get gst sub sub k j 1
237end
238end
239
240note o_key: writes ,"KEY": (first true: {"KEY":)
241fn o_key t view uchar * first bool to void
242if first
243o_b 123
244else
245o_b 44
246end
247o_b 34
248o_t t
249o_b 34
250o_b 58
251end
252
253fn o_q to void
254o_b 34
255end
256
257note die: {"ok":false,"error":"T"} on stdout, `synapse-claims: T` on stderr, exit code
258fn die code int t view uchar * to void
259o_t tjerr
260o_t t
261o_t tjend
262o_flush
263put gx xsel 1
264o_t tpref
265o_t t
266o_b 10
267e_flush
268exit code
269end
270
271note ======== arena ========
272
273fn ar_b c uchar to void
274n = get gx xarn
275if ge n arcap
276die 70 mfull
277end
278if lt n arbank
279put gar0 n c
280else
281put gar1 sub n arbank c
282end
283put gx xarn add n 1
284end
285
286fn ar_g n ulong to uchar
287if lt n arbank
288ret get gar0 n
289end
290ret get gar1 sub n arbank
291end
292
293note ar_tv/ar_lnv/ar_cpv append to the arena; ar_t/ar_ln/ar_cp also return the start offset
294fn ar_tv t view uchar * to void
295for i ulong len t
296ar_b get t i
297end
298end
299
300fn ar_t t view uchar * to ulong
301s = get gx xarn
302ar_tv t
303ret s
304end
305
306fn ar_lnv s edit uchar * off ulong n ulong to void
307for i ulong n
308ar_b get s add off i
309end
310end
311
312fn ar_ln s edit uchar * off ulong n ulong to ulong
313st = get gx xarn
314ar_lnv s off n
315ret st
316end
317
318fn ar_cpv off ulong n ulong to void
319for i ulong n
320ar_b ar_g add off i
321end
322end
323
324fn ar_cp off ulong n ulong to ulong
325st = get gx xarn
326ar_cpv off n
327ret st
328end
329
330fn ar_eq a ulong an ulong b ulong bn ulong to bool
331if ne an bn
332ret false
333end
334for i ulong an
335if ne ar_g add a i ar_g add b i
336ret false
337end
338end
339ret true
340end
341
342fn lower c uchar to uchar
343if and ge c 65 le c 90
344ret add c 32
345end
346ret c
347end
348
349fn ar_eqci a ulong an ulong b ulong bn ulong to bool
350if ne an bn
351ret false
352end
353for i ulong an
354if ne lower ar_g add a i lower ar_g add b i
355ret false
356end
357end
358ret true
359end
360
361fn hexd v ulong to uchar
362if lt v 10
363ret uchar add v 48
364end
365ret uchar add v 87
366end
367
368fn hexv c uchar to ulong
369if and ge c 48 le c 57
370ret ulong sub c 48
371end
372if and ge c 97 le c 102
373ret ulong sub c 87
374end
375ret 16
376end
377
378note sf_ok: 1..256 bytes, each 0x21..0x7e except quote and backslash (identifiers, targets, URLs)
379fn sf_ok s edit uchar * to bool
380n = len s
381if or eq n 0 gt n 256
382ret false
383end
384for i ulong n
385c = get s i
386if or lt c 33 gt c 126
387ret false
388end
389if or eq c 34 eq c 92
390ret false
391end
392end
393ret true
394end
395