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 / board / src / 10-scan.om

501 lines · 8612 bytes Raw Blame History
1note synapse-board src/10-scan.om -- validate the three JSONL inputs and index what render needs.
2note gcnt: 0 active 1 lapsed 2 inactive 3 repos-with-claims 4 conflicts 5 error 6 warn 7 info
3note 8 map repos 9 inferred parents 10 findings (not conflicts) 11 claims seen
4const SBMAXC ulong 65536
5const SBMAXM ulong 4096
6global gcnt ulong 16
7global gpool uchar 8388608
8global gpl ulong 1
9global gcoff ulong 65536
10global gtoff ulong 65536
11global gtln ulong 65536
12global gkoff ulong 65536
13global gkln ulong 65536
14global gkrk ulong 65536
15global glap ulong 65536
16global gord ulong 65536
17global gnc ulong 1
18global gmoff ulong 4096
19global gmno ulong 4096
20global gmnl ulong 4096
21global gmpo ulong 4096
22global gmpl ulong 4096
23global gmst ulong 4096
24global gmpar ulong 4096
25global gmvis ulong 4096
26global gnm ulong 1
27global gstk ulong 4096
28global gsdp ulong 4096
29text tfc "claims"
30text tfm "map"
31text tff "findings"
32text kid "id"
33text kagent "agent"
34text ksess "session"
35text ktgt "target"
36text kmode "mode"
37text kstate "state"
38text kint "intent"
39text kexp "expires"
40text kact "active"
41text kev "evidence"
42text kkind "kind"
43text ksev "severity"
44text krepo "repo"
45text kpr "pr"
46text kpath "path"
47text kdet "detail"
48text koid "other_id"
49text koag "other_agent"
50text kpar "parent"
51text kpst "parent_status"
52text kpurp "purpose"
53text karch "archived"
54text kfork "fork"
55text krule "infer_rule"
56text vconf "conflict"
57text verr "error"
58text vwarn "warn"
59text vinfo "info"
60text vext "ext"
61text vcnf "CONFIRMED"
62text vinf "INFERRED"
63text vroot "ROOT"
64text vnone "NONE"
65text emjs "malformed JSON object line"
66text emlong "line longer than 65536 bytes"
67text emid "claim needs string id and target"
68text emrepo "map record needs string repo"
69text emkind "finding needs string kind"
70text emmany "too many records"
71text empool "string pool full"
72note sberr: "synapse-board: FILE:LINE: msg" on stderr; returns 65
73fn sberr w ulong ln ulong msg view uchar * to long
74d = new uchar 24 0
75i = ulong 24
76x = ln
77for it ulong 20
78i = sub i 1
79put d i uchar add rem x 10 48
80x = div x 10
81if eq x 0
82break
83end
84end
85r = write 2 tme 0 len tme
86if eq w 0
87r = write 2 tfc 0 len tfc
88end
89if eq w 1
90r = write 2 tfm 0 len tfm
91end
92if eq w 2
93r = write 2 tff 0 len tff
94end
95put d sub i 1 58
96r = write 2 d sub i 1 add sub 24 i 1
97put d 0 58
98put d 1 32
99r = write 2 d 0 2
100r = write 2 msg 0 len msg
101r = write 2 tnl 0 len tnl
102ret 65
103end
104note sbpl: parse the line of input w at off into lb/tp; its length (0 = empty line), -1 too long, -2 malformed
105fn sbpl w ulong off ulong lb edit uchar 65536 tp edit uint 16400 to long
106n = sbline w off lb
107if lt n 0
108ret -1
109end
110if eq n 0
111ret 0
112end
113r = js_init tp 65536 64
114r = js_parse lb tp ulong n
115if lt r 0
116ret -2
117end
118if ne js_type tp 0 jsobj
119ret -2
120end
121ret n
122end
123note sbpool: append sb[0..n) to the pool; its offset, or SBOCAP when the pool is full
124fn sbpool sb view uchar 65536 n ulong to ulong
125p = get gpl 0
126if gt add p n SBOCAP
127ret SBOCAP
128end
129for i ulong n
130put gpool add p i get sb i
131end
132put gpl 0 add p n
133ret p
134end
135fn sbeqv sb view uchar 65536 n long t view uchar * to bool
136if lt n 0
137ret false
138end
139if ne ulong n len t
140ret false
141end
142for i ulong len t
143if ne get sb i get t i
144ret false
145end
146end
147ret true
148end
149fn sbinc i ulong to void
150put gcnt i add get gcnt i 1
151end
152note sbtsless: whether string sb[0..n) sorts before the now timestamp (byte order)
153fn sbtsless sb view uchar 65536 n ulong to bool
154m = get gnowl 0
155for i ulong 64
156if or ge i n ge i m
157ret lt n m
158end
159a = get sb i
160b = get gnow i
161if ne a b
162ret lt a b
163end
164end
165ret false
166end
167note ======== findings: counts by kind conflict / severity
168fn sbscanf to long
169lb = new uchar 65536 0
170tp = new uint 16400 0
171sb = new uchar 65536 0
172tot = get glen 2
173off = ulong 0
174ln = ulong 0
175for it ulong SBLINES
176if ge off tot
177ret 0
178end
179ln = add ln 1
180n = sbpl 2 off lb tp
181if eq n -1
182ret sberr 2 ln emlong
183end
184if eq n -2
185ret sberr 2 ln emjs
186end
187if gt n 0
188k = sbgets lb tp sb kkind
189if lt k 0
190ret sberr 2 ln emkind
191end
192if sbeqv sb k vconf
193sbinc 4
194else
195sbinc 10
196k = sbgets lb tp sb ksev
197if sbeqv sb k verr
198sbinc 5
199end
200if sbeqv sb k vwarn
201sbinc 6
202end
203if sbeqv sb k vinfo
204sbinc 7
205end
206end
207end
208off = add add off ulong n 1
209end
210ret sberr 2 ln emmany
211end
212note sbrkey: repo grouping key of target sb[0..n) stored at pool offset p: sets gkoff/gkln/gkrk of claim c
213note rank 0 a repo (repo:R, branch:R#x, path:R:x, pr:R#n), 1 ext:, 2 unparsed
214fn sbrkey sb view uchar 65536 n ulong p ulong c ulong to void
215put gkrk c 2
216put gkoff c p
217put gkln c 0
218q = n
219for i ulong n
220if eq get sb i 58
221q = i
222break
223end
224end
225if ge q n
226ret
227end
228if and eq q 3 and eq get sb 0 101 and eq get sb 1 120 eq get sb 2 116
229put gkrk c 1
230ret
231end
232e = n
233for j ulong sub n add q 1
234k = add add q 1 j
235c2 = get sb k
236if or eq c2 35 eq c2 58
237e = k
238break
239end
240end
241if le e add q 1
242ret
243end
244put gkrk c 0
245put gkoff c add add p q 1
246put gkln c sub e add q 1
247end
248note ======== claims: active claims indexed; inactive counted
249fn sbscanc to long
250lb = new uchar 65536 0
251tp = new uint 16400 0
252sb = new uchar 65536 0
253tot = get glen 0
254off = ulong 0
255ln = ulong 0
256for it ulong SBLINES
257if ge off tot
258ret 0
259end
260ln = add ln 1
261n = sbpl 0 off lb tp
262if eq n -1
263ret sberr 0 ln emlong
264end
265if eq n -2
266ret sberr 0 ln emjs
267end
268if gt n 0
269k = sbgets lb tp sb kid
270t = sbgets lb tp sb ktgt
271if or le k 0 le t 0
272ret sberr 0 ln emid
273end
274sbinc 11
275if sbgetb lb tp kact
276c = get gnc 0
277if ge c SBMAXC
278ret sberr 0 ln emmany
279end
280p = sbpool sb ulong t
281if eq p SBOCAP
282ret sberr 0 ln empool
283end
284put gcoff c off
285put gtoff c p
286put gtln c ulong t
287sbrkey sb ulong t p c
288put glap c 0
289sbinc 0
290e = sbgets lb tp sb kexp
291if gt e 0
292if sbtsless sb ulong e
293put glap c 1
294sbinc 1
295end
296end
297put gord c c
298put gnc 0 add c 1
299else
300sbinc 2
301end
302end
303off = add add off ulong n 1
304end
305ret sberr 0 ln emmany
306end
307note sbkcmp: claim a sorts before claim b (rank, repo key bytes, file order)
308fn sbkcmp a ulong b ulong to bool
309ra = get gkrk a
310rb = get gkrk b
311if ne ra rb
312ret lt ra rb
313end
314la = get gkln a
315lb = get gkln b
316oa = get gkoff a
317ob = get gkoff b
318for i ulong 4096
319if or ge i la ge i lb
320if ne la lb
321ret lt la lb
322end
323ret lt a b
324end
325ca = get gpool add oa i
326cb = get gpool add ob i
327if ne ca cb
328ret lt ca cb
329end
330end
331ret lt a b
332end
333fn sbkeyeq a ulong b ulong to bool
334if ne get gkrk a get gkrk b
335ret false
336end
337la = get gkln a
338if ne la get gkln b
339ret false
340end
341oa = get gkoff a
342ob = get gkoff b
343for i ulong la
344if ne get gpool add oa i get gpool add ob i
345ret false
346end
347end
348ret true
349end
350note sbsortc: insertion sort of gord, then count distinct rank-0 repos
351fn sbsortc to void
352n = get gnc 0
353for i ulong n
354x = get gord i
355j = i
356while gt j 0 bound 65536
357y = get gord sub j 1
358if sbkcmp y x
359break
360end
361put gord j y
362j = sub j 1
363end
364put gord j x
365end
366for i2 ulong n
367c = get gord i2
368if eq get gkrk c 0
369if eq i2 0
370sbinc 3
371else
372if not sbkeyeq get gord sub i2 1 c
373sbinc 3
374end
375end
376end
377end
378end
379note sbpeq: pool strings equal ignoring ASCII case
380fn sbpeq ao ulong al ulong bo ulong bl ulong to bool
381if ne al bl
382ret false
383end
384for i ulong al
385a = get gpool add ao i
386b = get gpool add bo i
387if and ge a 65 le a 90
388a = add a 32
389end
390if and ge b 65 le b 90
391b = add b 32
392end
393if ne a b
394ret false
395end
396end
397ret true
398end
399note ======== map: records indexed, parents resolved within the map
400note Parse one row separately so stream state does not occupy the row parser's registers.
401fn sbmaprow lb view uchar 65536 tp view uint 16400 sb edit uchar 65536 off ulong ln ulong to long
402k = sbgets lb tp sb krepo
403if le k 0
404ret sberr 1 ln emrepo
405end
406m = get gnm 0
407if ge m SBMAXM
408ret sberr 1 ln emmany
409end
410p = sbpool sb ulong k
411if eq p SBOCAP
412ret sberr 1 ln empool
413end
414put gmoff m off
415put gmno m p
416put gmnl m ulong k
417put gmpl m 0
418put gmpar m jsnone
419put gmvis m 0
420k = sbgets lb tp sb kpar
421if gt k 0
422q = ulong k
423for i ulong ulong k
424if eq get sb i 64
425q = i
426break
427end
428end
429p = sbpool sb q
430if eq p SBOCAP
431ret sberr 1 ln empool
432end
433put gmpo m p
434put gmpl m q
435end
436k = sbgets lb tp sb kpst
437st = ulong 4
438if sbeqv sb k vcnf
439st = 0
440end
441if sbeqv sb k vinf
442st = 1
443sbinc 9
444end
445if sbeqv sb k vroot
446st = 2
447end
448if sbeqv sb k vnone
449st = 3
450end
451put gmst m st
452sbinc 8
453put gnm 0 add m 1
454ret 0
455end
456fn sbscanm to long
457lb = new uchar 65536 0
458tp = new uint 16400 0
459sb = new uchar 65536 0
460tot = get glen 1
461off = ulong 0
462ln = ulong 0
463for it ulong SBLINES
464if ge off tot
465ret sbresm
466end
467ln = add ln 1
468n = sbpl 1 off lb tp
469if eq n -1
470ret sberr 1 ln emlong
471end
472if eq n -2
473ret sberr 1 ln emjs
474end
475if gt n 0
476code = sbmaprow lb tp sb off ln
477if ne code 0
478ret code
479end
480end
481off = add add off ulong n 1
482end
483ret sberr 1 ln emmany
484end
485fn sbresm to long
486n = get gnm 0
487for i ulong n
488pl = get gmpl i
489if gt pl 0
490for j ulong n
491if ne i j
492if sbpeq get gmpo i pl get gmno j get gmnl j
493put gmpar i j
494break
495end
496end
497end
498end
499end
500ret 0
501end