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 / map / src / 10-json.om

619 lines · 10936 bytes Raw Blame History
1note ======== JSON input: catalog, extra/map/skills JSONL, root crumbs, xerj hits ========
2note Every document is parsed by seed/json/json.om into a caller-owned tape; strings are decoded with
3note js_sget and copied into gpool. Kinds: 1 catalog, 2 extra JSONL, 3 map.jsonl, 4 skills.jsonl,
4note 5 root crumb of record r, 6 xerj search response.
5
6global gsk ulong 4096
7global gxr ulong 512
8
9text tkname "name"
10text tkdesc "description"
11text tkpurp "purpose"
12text tkrepo "repo"
13text tkpar "parent"
14text tkpst "parent_status"
15text tklay "layer"
16text tksrc "source"
17text tkrule "infer_rule"
18text tkdefb "default_branch"
19text tkpush "pushed_at"
20text tkbrf "brief"
21text tkarch "archived"
22text tkfork "fork"
23text tkurl "url"
24text tkorg "org"
25text tkrepos "repos"
26text tkext "extensions"
27text tkmap "map"
28text tkhits "hits"
29text tkid "_id"
30text tkscore "_score"
31text tkerrs "errors"
32text tcatalog "catalog"
33text textra "extra"
34text tdup "synapse-map: duplicate repo ignored: "
35text trepop "repo:"
36text tskillp "skill:"
37
38note sm_jstr: decode string token t into the pool; offset, length in SSLEN; -65 when refused
39fn sm_jstr src view uchar * tape view uint * t ulong to long
40sb = new uchar 65536 0
41k = js_sget src js_off tape t sb
42if lt k 0
43ret -65
44end
45o = get gst SPOOL
46for i ulong ulong k
47sm_pb get sb i
48end
49put gst SSLEN ulong k
50ret long o
51end
52
53note sm_jsf: string (or null) token v into record string cell rf = r * 16 + field
54fn sm_jsf src view uchar * tape view uint * v ulong rf ulong to long
55ty = js_type tape v
56if eq ty jsnull
57ret 0
58end
59if ne ty jsstr
60ret -65
61end
62o = sm_jstr src tape v
63if lt o 0
64ret o
65end
66put gro rf ulong o
67put grl rf get gst SSLEN
68ret 0
69end
70
71note sm_jbool: true/false token v into record flag cell rk
72fn sm_jbool tape view uint * v ulong rk ulong to long
73ty = js_type tape v
74if eq ty jstrue
75put grf rk 1
76ret 0
77end
78if eq ty jsfalse
79put grf rk 0
80ret 0
81end
82ret -65
83end
84
85note sm_jkw: key at src[o] is key number w of the fixed table below
86fn sm_jkw src view uchar * o ulong w ulong to bool
87if eq w 1
88ret js_streq src o tkhits
89end
90if eq w 2
91ret js_streq src o tkid
92end
93if eq w 3
94ret js_streq src o tkscore
95end
96if eq w 4
97ret js_streq src o tkext
98end
99if eq w 5
100ret js_streq src o tkmap
101end
102if eq w 6
103ret js_streq src o tkpar
104end
105if eq w 7
106ret js_streq src o tkpurp
107end
108if eq w 8
109ret js_streq src o tklay
110end
111if eq w 9
112ret js_streq src o tkorg
113end
114if eq w 10
115ret js_streq src o tkrepos
116end
117if eq w 11
118ret js_streq src o tkerrs
119end
120if eq w 12
121ret js_streq src o tkname
122end
123if eq w 13
124ret js_streq src o tkdesc
125end
126ret false
127end
128
129note sm_jkeyv: value token of key w in object t, jsnone when t is not an object or has no such key
130fn sm_jkeyv src view uchar * tape view uint * t ulong w ulong to ulong
131if ne js_type tape t jsobj
132ret jsnone
133end
134k = js_first tape t
135while ne k jsnone bound 999999
136if sm_jkw src js_off tape k w
137ret add k 1
138end
139k = js_mnext tape k
140end
141ret jsnone
142end
143
144note sm_jkey: one member of a repo object (catalog, extra or map record) into record r; unknown keys ignored
145fn sm_jkey src view uchar * tape view uint * k ulong r ulong to long
146o = js_off tape k
147v = add k 1
148b = mul r 16
149if js_streq src o tkname
150ret sm_jsf src tape v add b FNAME
151end
152if or js_streq src o tkdesc js_streq src o tkpurp
153ret sm_jsf src tape v add b FPUR
154end
155if js_streq src o tkrepo
156ret sm_jsf src tape v add b FREPO
157end
158if js_streq src o tklay
159ret sm_jsf src tape v add b FLAY
160end
161if js_streq src o tkdefb
162ret sm_jsf src tape v add b FDEF
163end
164if js_streq src o tkpush
165ret sm_jsf src tape v add b FPUSH
166end
167if js_streq src o tkurl
168ret sm_jsf src tape v add b FURL
169end
170if js_streq src o tksrc
171ret sm_jsf src tape v add b FSRC
172end
173if js_streq src o tkrule
174ret sm_jsf src tape v add b FRULE
175end
176if js_streq src o tkpst
177ret sm_jsf src tape v add b FPST
178end
179if js_streq src o tkpar
180if eq js_type tape v jsnull
181sm_ks r KPNUL 1
182ret 0
183end
184ret sm_jsf src tape v add b FPAR
185end
186if js_streq src o tkbrf
187if eq js_type tape v jsnull
188sm_ks r KBNUL 1
189ret 0
190end
191ret sm_jsf src tape v add b FBRF
192end
193if js_streq src o tkarch
194ret sm_jbool tape v add b KARCH
195end
196if js_streq src o tkfork
197ret sm_jbool tape v add b KFORK
198end
199ret 0
200end
201
202note sm_setname: FNAME = the part of FREPO after its last '/'
203fn sm_setname r ulong to void
204o = sm_fo r FREPO
205n = sm_fl r FREPO
206s = ulong 0
207for i ulong n
208if eq get gpool add o i 47
209s = add i 1
210end
211end
212sm_fset r FNAME add o s sub n s
213end
214
215note sm_jfin: complete record r (kind sk) and count it unless its repo is already present
216fn sm_jfin r ulong sk ulong to long
217if eq sk 3
218if eq sm_fl r FREPO 0
219ret -65
220end
221sm_setname r
222else
223no = sm_fo r FNAME
224nl = sm_fl r FNAME
225if eq nl 0
226ret -65
227end
228if lt sm_pfind no nl 47 nl
229sm_fset r FREPO no nl
230sm_setname r
231else
232o = sm_pcp get gst SORGO get gst SORGL
233sm_pb 47
234x = sm_pcp no nl
235sm_fset r FREPO o add add get gst SORGL 1 nl
236end
237if eq sk 1
238sm_fsett r FSRC tcatalog
239else
240sm_fsett r FSRC textra
241end
242end
243d = sm_find sm_fo r FREPO sm_fl r FREPO
244if ne d SNONE
245sm_err tdup
246sm_errp sm_fo r FREPO sm_fl r FREPO
247sm_errnl
248ret 0
249end
250put gst SNREC add r 1
251ret 1
252end
253
254fn sm_jrepo src view uchar * tape view uint * t ulong sk ulong to long
255if ne js_type tape t jsobj
256ret -65
257end
258r = get gst SNREC
259if ge r 1000
260ret -12
261end
262for f ulong 16
263sm_fset r f 0 0
264sm_ks r f 0
265end
266k = js_first tape t
267while ne k jsnone bound 999999
268e = sm_jkey src tape k r
269if lt e 0
270ret e
271end
272k = js_mnext tape k
273end
274ret sm_jfin r sk
275end
276
277fn sm_jcat src view uchar * tape view uint * to long
278v = sm_jkeyv src tape 0 9
279if ne v jsnone
280if eq js_type tape v jsstr
281o = sm_jstr src tape v
282if lt o 0
283ret o
284end
285put gst SORGO ulong o
286put gst SORGL get gst SSLEN
287end
288end
289a = sm_jkeyv src tape 0 10
290if eq a jsnone
291ret -65
292end
293if ne js_type tape a jsarr
294ret -65
295end
296e = js_first tape a
297while ne e jsnone bound 999999
298x = sm_jrepo src tape e 1
299if lt x 0
300ret x
301end
302e = js_enext tape e
303end
304ret 0
305end
306
307note sm_jcrumb: purpose, layer and extensions.map.parent of a root crumb into record r
308fn sm_jcrumb src view uchar * tape view uint * r ulong to long
309if ne js_type tape 0 jsobj
310ret -65
311end
312b = mul r 16
313v = sm_jkeyv src tape 0 7
314if ne v jsnone
315x = sm_jsf src tape v add b FCPUR
316end
317v = sm_jkeyv src tape 0 8
318if ne v jsnone
319x = sm_jsf src tape v add b FCLAY
320end
321e = sm_jkeyv src tape 0 4
322if eq e jsnone
323ret 0
324end
325m = sm_jkeyv src tape e 5
326if eq m jsnone
327ret 0
328end
329p = sm_jkeyv src tape m 6
330if eq p jsnone
331ret 0
332end
333ret sm_jsf src tape p add b FCPAR
334end
335
336fn sm_sb src view uchar * p ulong to uchar
337if lt p len src
338ret get src p
339end
340ret 0
341end
342
343fn sm_isdig c uchar to bool
344ret and ge c 48 le c 57
345end
346
347note sm_jnum: a JSON number lexeme at src[o] in millionths (nonnegative; negative values give 0)
348fn sm_jnum src view uchar * o ulong to ulong
349p = o
350if eq sm_sb src p 45
351ret 0
352end
353v = ulong 0
354for i ulong 20
355c = sm_sb src p
356if not sm_isdig c
357break
358end
359if lt v 100000000000
360v = add mul v 10 ulong sub c 48
361end
362p = add p 1
363end
364f = ulong 0
365s = ulong 1000000
366if eq sm_sb src p 46
367p = add p 1
368for i ulong 40
369c = sm_sb src p
370if not sm_isdig c
371break
372end
373if gt s 1
374s = div s 10
375f = add f mul s ulong sub c 48
376end
377p = add p 1
378end
379end
380v = add mul v 1000000 f
381c = sm_sb src p
382if or eq c 101 eq c 69
383ret sm_jexp src add p 1 v
384end
385ret v
386end
387
388fn sm_jexp src view uchar * p ulong v ulong to ulong
389q = p
390ng = false
391if eq sm_sb src q 45
392ng = true
393q = add q 1
394end
395if eq sm_sb src q 43
396q = add q 1
397end
398e = ulong 0
399for i ulong 6
400c = sm_sb src q
401if not sm_isdig c
402break
403end
404e = add mul e 10 ulong sub c 48
405q = add q 1
406end
407x = v
408for i ulong 20
409if ge i e
410break
411end
412if ng
413x = div x 10
414else
415if lt x 1000000000000
416x = mul x 10
417end
418end
419end
420ret x
421end
422
423note sm_skfind: skill whose name equals the pool slice, or SNONE
424fn sm_skfind o ulong n ulong to ulong
425for s ulong get gst SNSKL
426so = get gsk mul s 4
427sn = get gsk add mul s 4 1
428if sm_peq so sn o n
429ret s
430end
431end
432ret SNONE
433end
434
435note sm_jhits: {"hits":{"hits":[{"_id":"repo:..|skill:..","_score":x}]}} into gxr (code, millionths)
436fn sm_jhits src view uchar * tape view uint * to long
437put gst SNXR 0
438h = sm_jkeyv src tape 0 1
439if eq h jsnone
440ret 0
441end
442a = sm_jkeyv src tape h 1
443if eq a jsnone
444ret 0
445end
446if ne js_type tape a jsarr
447ret -65
448end
449e = js_first tape a
450while ne e jsnone bound 999999
451i = sm_jkeyv src tape e 2
452s = sm_jkeyv src tape e 3
453if and ne i jsnone ne s jsnone
454o = sm_jstr src tape i
455if lt o 0
456ret o
457end
458x = sm_jhit ulong o get gst SSLEN sm_jnum src js_off tape s
459end
460e = js_enext tape e
461end
462ret 0
463end
464
465note sm_jhit: map a hit id to a code (record index, or 1048576 + skill index) and append it
466fn sm_jhit o ulong n ulong sc ulong to long
467k = get gst SNXR
468if ge k 256
469ret 0
470end
471c = SNONE
472if gt n 5
473if sm_pteq o 5 trepop
474r = sm_find add o 5 sub n 5
475if ne r SNONE
476c = r
477end
478end
479end
480if gt n 6
481if sm_pteq o 6 tskillp
482s = sm_skfind add o 6 sub n 6
483if ne s SNONE
484c = add s 1048576
485end
486end
487end
488if eq c SNONE
489ret 0
490end
491put gxr mul k 2 c
492put gxr add mul k 2 1 sc
493put gst SNXR add k 1
494ret 0
495end
496
497fn sm_jskill src view uchar * tape view uint * t ulong to long
498s = get gst SNSKL
499if ge s 1000
500ret -12
501end
502v = sm_jkeyv src tape t 12
503if eq v jsnone
504ret -65
505end
506if ne js_type tape v jsstr
507ret -65
508end
509o = sm_jstr src tape v
510if lt o 0
511ret o
512end
513put gsk mul s 4 ulong o
514put gsk add mul s 4 1 get gst SSLEN
515put gsk add mul s 4 2 0
516put gsk add mul s 4 3 0
517d = sm_jkeyv src tape t 13
518if ne d jsnone
519if eq js_type tape d jsstr
520o = sm_jstr src tape d
521if lt o 0
522ret o
523end
524put gsk add mul s 4 2 ulong o
525put gsk add mul s 4 3 get gst SSLEN
526end
527end
528put gst SNSKL add s 1
529ret 1
530end
531
532fn sm_jdoc src view uchar * tape view uint * kind ulong r ulong to long
533if eq kind 1
534ret sm_jcat src tape
535end
536if eq kind 5
537ret sm_jcrumb src tape r
538end
539ret sm_jhits src tape
540end
541
542fn sm_jline src view uchar * tape view uint * kind ulong to long
543if eq kind 4
544ret sm_jskill src tape 0
545end
546ret sm_jrepo src tape 0 kind
547end
548
549fn sm_blank p ulong m ulong to bool
550for i ulong m
551c = get gfile add p i
552if not or eq c 32 or eq c 13 eq c 9
553ret false
554end
555end
556ret true
557end
558
559note sm_jcopy: gfile[p, p + m) into src[0, m)
560fn sm_jcopy src edit uchar 983040 p ulong m ulong to void
561for i ulong m
562put src i get gfile add p i
563end
564end
565
566note sm_jload: parse gfile[0, SFLEN) as kind (whole document for 1, 5, 6; one object per line otherwise).
567note Returns >= 0, -65 malformed (line number in SBAD for JSONL), -27 too large, -12 table full.
568fn sm_jload kind ulong r ulong to long
569src = new uchar 983040 0
570tape = new uint 262160 0
571x = js_init tape 983040 64
572n = get gst SFLEN
573put gst SBAD 0
574if or eq kind 1 or eq kind 5 eq kind 6
575if gt n len src
576ret -27
577end
578for i ulong n
579put src i get gfile i
580end
581k = js_parse src tape n
582if lt k 0
583ret -65
584end
585ret sm_jdoc src tape kind r
586end
587p = ulong 0
588ln = ulong 0
589while lt p n bound 999999
590e = p
591while lt e n bound 999999
592if eq get gfile e 10
593break
594end
595e = add e 1
596end
597m = sub e p
598ln = add ln 1
599if not sm_blank p m
600if gt m len src
601put gst SBAD ln
602ret -27
603end
604sm_jcopy src p m
605k = js_parse src tape m
606if lt k 0
607put gst SBAD ln
608ret -65
609end
610y = sm_jline src tape kind
611if lt y 0
612put gst SBAD ln
613ret y
614end
615end
616p = add e 1
617end
618ret long ln
619end