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 / core / cortex / tests / parity / gen.om

749 lines · 11053 bytes Raw Blame History
1note gen.om: parity corpus generator (read phase). usage: gen DATA OUT
2note DATA is written by tests/parity/gen.sh from a copy of the cortex-rs database (sqlite3 is used
3note only to extract real values, as hex): "T<TAB><hex query term>" and
4note "E<TAB><hex id><TAB><hex canonical name><TAB><hex space slug>". OUT gets one corpus line per
5note request, CLASS TAB METHOD TAB PATH TAB FLAGS TAB BODY (spec/PARITY.md):
6note - every term, alone, against search GET, search POST and recall, over five spaces (none,
7note aien-lessons, aien-sources, atlas-memory, an unknown one) with the limit cycling over
8note absent/0/1/5/12/50/999 and occasional query=, include_retracted, tokenBudget, origin and
9note spaced-token variants;
10note - eleven FTS operator forms over term pairs (AND, OR, NOT, prefix, phrase, NEAR, column
11note filter, dangling AND, open and close parenthesis, leading minus);
12note - eighteen empty and malformed queries that use no term;
13note - get by id, by name, with the right, default and wrong space, id+name, HEAD; traverse.
14global pa uchar 4096
15global db uchar 4194304
16global ob uchar 2097152
17global qb uchar 16384
18note tt: term i hex at db offset tt[2i], length tt[2i+1]
19global tt ulong 2048
20note et: entity e: id, name, space hex (offset, length) at et[6e .. 6e+5]
21global et ulong 3072
22note gv: 0 data len, 1 out fd, 2 ob pos, 3 terms, 4 entities, 5 request counter, 6 qb len, 7 write failed
23global gv ulong 8
24text u_use "usage: gen DATA OUT\n"
25text u_open "gen: cannot open a file\n"
26text u_big "gen: data too large or malformed\n"
27text u_wr "gen: write failed\n"
28text s_sp1 "aien-lessons"
29text s_sp2 "aien-sources"
30text s_sp3 "atlas-memory"
31text s_sp4 "no-such-space"
32text p_sg "/api/cortex/search?"
33text p_sp "/api/cortex/search"
34text p_rc "/api/cortex/recall"
35text p_get "/api/cortex/get?"
36text p_tr "/api/cortex/traverse"
37text m_get "GET"
38text m_post "POST"
39text m_head "HEAD"
40text a_q "q="
41text a_qy "query="
42text a_sp "&space="
43text a_lim "&limit="
44text a_ir "&include_retracted=true"
45text a_id "id="
46text a_nm "name="
47text a_spn "&space=no-such-space"
48text a_nz "&name=zzz-no-such-name"
49text j_q "{\"q\":\""
50text j_qy "{\"query\":\""
51text j_sj "{\"subjectId\":\""
52text j_sp ",\"space\":\""
53text j_lim ",\"limit\":"
54text j_ir ",\"include_retracted\":true"
55text j_tb ",\"tokenBudget\":200"
56text c_sgt "search.get.term"
57text c_spt "search.post.term"
58text c_rt "recall.term"
59text c_sgo "search.get.ops"
60text c_spo "search.post.ops"
61text c_ro "recall.ops"
62text c_sge "search.get.malformed"
63text c_spe "search.post.malformed"
64text c_re "recall.malformed"
65text c_get "get.read"
66text c_tr "traverse.read"
67text f_and " AND "
68text f_or " OR "
69text f_not " NOT "
70text f_near "NEAR("
71text f_col "canonical_name:"
72text f_dand " AND"
73text x_00 " "
74text x_01 "\""
75text x_02 "*"
76text x_03 "AND"
77text x_04 "OR"
78text x_05 "NOT"
79text x_06 "("
80text x_07 ")"
81text x_08 "\"unclosed phrase"
82text x_09 "%"
83text x_10 "_"
84text x_11 "%_%"
85text x_12 "'"
86text x_13 "NEAR("
87text x_14 "a:b"
88text x_15 "^"
89text x_16 "\\"
90text x_17 "\t tab and newline \n"
91
92fn say t view uchar * to void
93w = write 2 t 0 len t
94if lt w 0
95ret
96end
97end
98fn argp i ulong to ulong
99n = argread i pa 0 len pa
100if lt n 0
101ret 0
102end
103ret ulong n
104end
105fn rdall fd int to bool
106n = ulong 0
107while true bound 999999
108if ge n len db
109say u_big
110ret false
111end
112r = pread fd db n sub len db n long n
113if lt r 0
114ret false
115end
116if eq r 0
117put gv 0 n
118ret true
119end
120n = add n ulong r
121end
122ret false
123end
124note ---- output ----
125fn flush to void
126k = ulong 0
127e = get gv 2
128while lt k e bound 999999
129w = write int get gv 1 ob k sub e k
130if le w 0
131put gv 7 1
132put gv 2 0
133ret
134end
135k = add k ulong w
136end
137put gv 2 0
138end
139fn oc c uchar to void
140p = get gv 2
141put ob p c
142put gv 2 add p 1
143end
144fn ot t view uchar * to void
145for i ulong len t
146oc get t i
147end
148end
149fn odec v ulong to void
150if ge v 10
151odec div v 10
152end
153oc uchar add rem v 10 48
154end
155fn hexv c ulong to ulong
156if le c 57
157ret sub c 48
158end
159if le c 70
160ret sub c 55
161end
162ret sub c 87
163end
164fn hexd v ulong to uchar
165if lt v 10
166ret uchar add v 48
167end
168ret uchar add v 55
169end
170note end of a corpus line; flushes when the buffer is mostly full
171fn eol to void
172oc 10
173put gv 5 add get gv 5 1
174if gt get gv 2 1900000
175flush
176end
177end
178fn tab to void
179oc 9
180end
181note ---- the query buffer qb ----
182fn qclr to void
183put gv 6 0
184end
185fn qc c uchar to void
186p = get gv 6
187if lt p len qb
188put qb p c
189put gv 6 add p 1
190end
191end
192fn qt t view uchar * to void
193for i ulong len t
194qc get t i
195end
196end
197note append the bytes of term i (decoded from hex)
198fn qterm i ulong to void
199o = get tt mul i 2
200n = div get tt add mul i 2 1 2
201for j ulong n
202a = hexv ulong get db add o mul j 2
203b = hexv ulong get db add add o mul j 2 1
204qc uchar add mul a 16 b
205end
206end
207note qb as "~" plus hex pairs (pdrive sends them as %HH)
208fn ourl to void
209oc 126
210for i ulong get gv 6
211c = ulong get qb i
212oc hexd shr c 4
213oc hexd and c 15
214end
215end
216fn ou4 c ulong to void
217oc 92
218oc 117
219oc 48
220oc 48
221oc hexd shr c 4
222oc hexd and c 15
223end
224note qb as the inside of a JSON string
225fn ojson to void
226for i ulong get gv 6
227c = get qb i
228if or eq c 34 eq c 92
229oc 92
230oc c
231continue
232end
233if lt c 32
234ou4 ulong c
235continue
236end
237oc c
238end
239end
240note hex region of db copied as "~" plus hex (url) or decoded and escaped (json)
241fn ohex o ulong n ulong to void
242oc 126
243for j ulong n
244oc get db add o j
245end
246end
247fn ojhex o ulong n ulong to void
248qclr
249for j ulong div n 2
250a = hexv ulong get db add o mul j 2
251b = hexv ulong get db add add o mul j 2 1
252qc uchar add mul a 16 b
253end
254ojson
255end
256note ---- spaces and limits ----
257fn ospace s ulong to void
258if eq s 1
259ot s_sp1
260end
261if eq s 2
262ot s_sp2
263end
264if eq s 3
265ot s_sp3
266end
267if eq s 4
268ot s_sp4
269end
270end
271fn limv l ulong to ulong
272if eq l 1
273ret 0
274end
275if eq l 2
276ret 1
277end
278if eq l 3
279ret 5
280end
281if eq l 4
282ret 12
283end
284if eq l 5
285ret 50
286end
287ret 999
288end
289note flags for request number n: a token, plus an allowed origin or a spaced token now and then
290fn oflags json bool to void
291n = get gv 5
292if eq rem n 13 6
293oc 115
294else
295oc 97
296end
297if json
298oc 106
299end
300if eq rem n 11 4
301oc 111
302end
303end
304note ---- one request built from qb: ep 0 search GET, 1 search POST, 2 recall ----
305fn rqget c view uchar * s ulong l ulong to void
306n = get gv 5
307ot c
308tab
309ot m_get
310tab
311ot p_sg
312if eq rem n 5 3
313ot a_qy
314else
315ot a_q
316end
317ourl
318if ne s 0
319ot a_sp
320ospace s
321end
322if ne l 0
323ot a_lim
324odec limv l
325end
326if eq rem n 7 2
327ot a_ir
328end
329tab
330oflags false
331tab
332eol
333end
334fn jtail s ulong l ulong to void
335oc 34
336if ne s 0
337ot j_sp
338ospace s
339oc 34
340end
341if ne l 0
342ot j_lim
343odec limv l
344end
345end
346fn rqpost c view uchar * s ulong l ulong to void
347n = get gv 5
348ot c
349tab
350ot m_post
351tab
352ot p_sp
353tab
354oflags true
355tab
356ot j_q
357ojson
358jtail s l
359if eq rem n 7 2
360ot j_ir
361end
362oc 125
363eol
364end
365fn rqrec c view uchar * s ulong l ulong to void
366n = get gv 5
367ot c
368tab
369ot m_post
370tab
371ot p_rc
372tab
373oflags true
374tab
375ot j_qy
376ojson
377jtail s l
378if eq rem n 5 1
379ot j_tb
380end
381oc 125
382eol
383end
384note kind 0 term, 1 ops, 2 malformed: picks the class names
385fn rq3 kind ulong ep ulong s ulong l ulong to void
386if eq ep 0
387if eq kind 0
388rqget c_sgt s l
389end
390if eq kind 1
391rqget c_sgo s l
392end
393if eq kind 2
394rqget c_sge s l
395end
396ret
397end
398if eq ep 1
399if eq kind 0
400rqpost c_spt s l
401end
402if eq kind 1
403rqpost c_spo s l
404end
405if eq kind 2
406rqpost c_spe s l
407end
408ret
409end
410if eq kind 0
411rqrec c_rt s l
412end
413if eq kind 1
414rqrec c_ro s l
415end
416if eq kind 2
417rqrec c_re s l
418end
419end
420note ---- phases ----
421fn gterm to void
422nt = get gv 3
423for i ulong nt
424qclr
425qterm i
426for s ulong 5
427for ep ulong 3
428rq3 0 ep s rem add add mul i 5 mul s 3 ep 7
429end
430end
431end
432end
433note operator form f (1..11) over terms t and u into qb
434fn qform f ulong t ulong u ulong to void
435qclr
436if eq f 5
437qc 34
438end
439if eq f 6
440qt f_near
441end
442if eq f 7
443qt f_col
444end
445if eq f 9
446qc 40
447end
448if eq f 11
449qc 45
450end
451qterm t
452if eq f 1
453qt f_and
454qterm u
455end
456if eq f 2
457qt f_or
458qterm u
459end
460if eq f 3
461qt f_not
462qterm u
463end
464if eq f 4
465qc 42
466end
467if or eq f 5 eq f 6
468qc 32
469qterm u
470end
471if eq f 5
472qc 34
473end
474if eq f 6
475qc 41
476end
477if eq f 8
478qt f_dand
479end
480if eq f 10
481qc 41
482end
483end
484fn opsone i ulong f ulong ep ulong to void
485s = rem add add i f ep 5
486l = rem add mul i 3 add f ep 7
487rq3 1 ep s l
488end
489fn gops to void
490nt = get gv 3
491np = nt
492if gt np 50
493np = 50
494end
495for i ulong np
496for f ulong 11
497qform add f 1 i rem add i 7 nt
498for ep ulong 3
499opsone i f ep
500end
501end
502end
503end
504fn qmal x ulong to void
505qclr
506if eq x 1
507qt x_00
508end
509if eq x 2
510qt x_01
511end
512if eq x 3
513qt x_02
514end
515if eq x 4
516qt x_03
517end
518if eq x 5
519qt x_04
520end
521if eq x 6
522qt x_05
523end
524if eq x 7
525qt x_06
526end
527if eq x 8
528qt x_07
529end
530if eq x 9
531qt x_08
532end
533if eq x 10
534qt x_09
535end
536if eq x 11
537qt x_10
538end
539if eq x 12
540qt x_11
541end
542if eq x 13
543qt x_12
544end
545if eq x 14
546qt x_13
547end
548if eq x 15
549qt x_14
550end
551if eq x 16
552qt x_15
553end
554if eq x 17
555qt x_16
556end
557if eq x 18
558qt x_17
559end
560end
561note x 0 is the empty query
562fn gmal to void
563for x ulong 19
564qmal x
565for s ulong 5
566for ep ulong 3
567rq3 2 ep s rem add add x s mul ep 3 7
568end
569end
570end
571end
572note get lines for entity e: v 0 id+space, 1 id (default space), 2 name+space, 3 name+wrong
573note space, 4 id+name+space, 5 HEAD id+space
574fn ghead e ulong m view uchar * to void
575ot c_get
576tab
577ot m
578tab
579ot p_get
580end
581fn gone e ulong v ulong to void
582b = mul e 6
583if eq v 5
584ghead e m_head
585else
586ghead e m_get
587end
588if or eq v 2 eq v 3
589ot a_nm
590ohex get et add b 2 get et add b 3
591else
592ot a_id
593ohex get et b get et add b 1
594end
595if eq v 4
596ot a_nz
597end
598if eq v 3
599ot a_spn
600end
601if and ne v 1 ne v 3
602ot a_sp
603ohex get et add b 4 get et add b 5
604end
605tab
606oflags false
607tab
608eol
609end
610fn trone e ulong to void
611b = mul e 6
612ot c_tr
613tab
614ot m_post
615tab
616ot p_tr
617tab
618oflags true
619tab
620ot j_sj
621ojhex get et b get et add b 1
622oc 34
623if eq rem e 2 0
624ot j_sp
625ojhex get et add b 4 get et add b 5
626oc 34
627end
628oc 125
629eol
630end
631fn gget to void
632for e ulong get gv 4
633for v ulong 5
634gone e v
635end
636if eq rem e 3 0
637gone e 5
638end
639if eq rem e 5 0
640trone e
641end
642end
643end
644note ---- data file ----
645fn eolat i ulong to ulong
646n = get gv 0
647for j ulong sub n i
648if eq get db add i j 10
649ret add i j
650end
651end
652ret n
653end
654fn tabat i ulong e ulong to ulong
655for j ulong sub e i
656if eq get db add i j 9
657ret add i j
658end
659end
660ret e
661end
662fn addt s ulong e ulong to bool
663k = get gv 3
664if ge mul add k 1 2 len tt
665ret false
666end
667put tt mul k 2 add s 2
668put tt add mul k 2 1 sub e add s 2
669put gv 3 add k 1
670ret true
671end
672fn adde s ulong e ulong to bool
673k = get gv 4
674b = mul k 6
675if ge add b 6 len et
676ret false
677end
678t1 = tabat add s 2 e
679t2 = tabat add t1 1 e
680if ge t2 e
681ret false
682end
683put et b add s 2
684put et add b 1 sub t1 add s 2
685put et add b 2 add t1 1
686put et add b 3 sub t2 add t1 1
687put et add b 4 add t2 1
688put et add b 5 sub e add t2 1
689put gv 4 add k 1
690ret true
691end
692fn parse to bool
693i = ulong 0
694n = get gv 0
695while lt i n bound 999999
696e = eolat i
697if gt e add i 2
698c = get db i
699ok = false
700if eq c 84
701ok = addt i e
702end
703if eq c 69
704ok = adde i e
705end
706if not ok
707ret false
708end
709end
710i = add e 1
711end
712ret and gt get gv 3 8 gt get gv 4 0
713end
714fn main to int
715if ne ulong argcnt 3
716say u_use
717ret 2
718end
719fd = int fopen pa 0 argp 1 524288 0
720if lt fd 0
721say u_open
722ret 3
723end
724if not rdall fd
725ret 3
726end
727x = fclose fd
728if not parse
729say u_big
730ret 3
731end
732of = int fopen pa 0 argp 2 524865 420
733if lt of 0
734say u_open
735ret 3
736end
737put gv 1 ulong of
738gterm
739gops
740gmal
741gget
742flush
743y = fclose of
744if ne get gv 7 0
745say u_wr
746ret 4
747end
748ret 0
749end