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 / 20-infer.om

363 lines · 7026 bytes Raw Blame History
1note ======== infer.tsv rules, topics.tsv terms, parent resolution ========
2note infer.tsv: pattern<TAB>parent<TAB>why[<TAB>layer]; '#' lines and blank lines are skipped.
3note pattern: a case-insensitive glob (* ?) on the bare repo name, or desc:<substring> of the purpose.
4note parent: ROOT, NONE, repo, owner/repo, optionally @ref. The first matching rule wins; a rule that
5note would make a repo its own parent is skipped.
6
7note rules: (pattern, parent, why, layer) offset/length pairs, and the file line number
8global grule ulong 4096
9global grln ulong 512
10global gtf ulong 8
11
12text tsroot "ROOT"
13text tsnone "NONE"
14text tsconf "CONFIRMED"
15text tsinf "INFERRED"
16text tcrumb "crumb"
17text tunknown "unknown"
18text tdescp "desc:"
19
20fn sm_pfile p ulong n ulong to ulong
21o = get gst SPOOL
22for i ulong n
23sm_pb get gfile add p i
24end
25ret o
26end
27
28note sm_tsvsplit: split the row gfile[p, p + m) at tabs; the first 4 fields go to gtf as pool slices;
29note returns the number of fields
30fn sm_tsvsplit p ulong m ulong to ulong
31nf = ulong 0
32s = p
33for i ulong add m 1
34de = eq i m
35if not de
36de = eq get gfile add p i 9
37end
38if de
39if lt nf 4
40put gtf mul nf 2 sm_pfile s sub add p i s
41put gtf add mul nf 2 1 sub add p i s
42end
43nf = add nf 1
44s = add add p i 1
45end
46end
47ret nf
48end
49
50note sm_tsv: split gfile[0, SFLEN) into tab-separated rows of kind 1 (rules) or 2 (topics)
51fn sm_tsv kind ulong to long
52n = get gst SFLEN
53p = ulong 0
54ln = ulong 0
55put gst SBAD 0
56while lt p n bound 999999
57e = p
58while lt e n bound 999999
59if eq get gfile e 10
60break
61end
62e = add e 1
63end
64ln = add ln 1
65m = sub e p
66if gt m 0
67if eq get gfile sub e 1 13
68m = sub m 1
69end
70end
71skip = sm_blank p m
72if not skip
73skip = eq get gfile p 35
74end
75if not skip
76nf = sm_tsvsplit p m
77x = sm_tsvrow kind nf ln
78if lt x 0
79put gst SBAD ln
80ret x
81end
82end
83p = add e 1
84end
85ret 0
86end
87
88fn sm_tsvrow kind ulong nf ulong ln ulong to long
89if eq kind 2
90ret sm_toprow nf
91end
92if lt nf 3
93ret -65
94end
95if or eq get gtf 1 0 eq get gtf 3 0
96ret -65
97end
98i = get gst SNRUL
99if ge i 512
100ret -12
101end
102b = mul i 8
103for f ulong 6
104put grule add b f get gtf f
105end
106put grule add b 6 0
107put grule add b 7 0
108if gt nf 3
109put grule add b 6 get gtf 6
110put grule add b 7 get gtf 7
111end
112put grln i ln
113put gst SNRUL add i 1
114ret 0
115end
116
117note sm_toprow: repo<TAB>terms<TAB>evidence; terms are appended to the record's topic field
118fn sm_toprow nf ulong to long
119if lt nf 2
120ret -65
121end
122r = sm_findany get gtf 0 get gtf 1
123if eq r SNONE
124ret 0
125end
126o = sm_pcp sm_fo r FTOP sm_fl r FTOP
127sm_pb 32
128x = sm_pcp get gtf 2 get gtf 3
129sm_fset r FTOP o add add sm_fl r FTOP 1 get gtf 3
130ret 0
131end
132
133note sm_findany: record by owner/repo, or by bare name when the slice has no '/'
134fn sm_findany o ulong n ulong to ulong
135if lt sm_pfind o n 47 n
136ret sm_find o n
137end
138for r ulong get gst SNREC
139if sm_pieq sm_fo r FNAME sm_fl r FNAME o n
140ret r
141end
142end
143ret SNONE
144end
145
146fn sm_gat o ulong n ulong i ulong to uchar
147if lt i n
148ret sm_lc get gpool add o i
149end
150ret 0
151end
152
153note sm_glob: case-insensitive wildcard match of pattern (po, pn) against (so, sn); * any run, ? one byte
154fn sm_glob po ulong pn ulong so ulong sn ulong to bool
155p = ulong 0
156s = ulong 0
157st = SNONE
158mk = ulong 0
159while lt s sn bound 999999
160pc = sm_gat po pn p
161sc = sm_lc get gpool add so s
162one = false
163if and ne pc 42 ne pc 0
164one = or eq pc 63 eq pc sc
165end
166if one
167p = add p 1
168s = add s 1
169else
170if eq pc 42
171st = p
172mk = s
173p = add p 1
174else
175if eq st SNONE
176ret false
177end
178p = add st 1
179mk = add mk 1
180s = mk
181end
182end
183end
184while eq sm_gat po pn p 42 bound 999999
185p = add p 1
186end
187ret eq p pn
188end
189
190note sm_isub: case-insensitive substring test of needle (no, nn) in haystack (ho, hn)
191fn sm_isub ho ulong hn ulong no ulong nn ulong to bool
192if gt nn hn
193ret false
194end
195for i ulong add sub hn nn 1
196m = true
197for j ulong nn
198if ne sm_lc get gpool add ho add i j sm_lc get gpool add no j
199m = false
200break
201end
202end
203if m
204ret true
205end
206end
207ret false
208end
209
210fn sm_rmatch i ulong r ulong to bool
211po = get grule mul i 8
212pn = get grule add mul i 8 1
213if gt pn 5
214if sm_pteq po 5 tdescp
215ret sm_isub sm_fo r FPUR sm_fl r FPUR add po 5 sub pn 5
216end
217end
218ret sm_glob po pn sm_fo r FNAME sm_fl r FNAME
219end
220
221note sm_pfull: owner/repo[@ref] for a parent slice, prefixing the catalog org when no owner is given
222fn sm_pfull o ulong n ulong to ulong
223s = get gst SPOOL
224q = sm_pfind o n 64
225if ge sm_pfind o q 47 q
226x = sm_pcp get gst SORGO get gst SORGL
227sm_pb 47
228end
229y = sm_pcp o n
230put gst SSLEN sub get gst SPOOL s
231ret s
232end
233
234note sm_isself: parent slice (o, n) names record r itself
235fn sm_isself r ulong o ulong n ulong to bool
236q = sm_pfind o n 64
237ret sm_pieq o q sm_fo r FREPO sm_fl r FREPO
238end
239
240fn sm_setrule r ulong i ulong to void
241o = get gst SPOOL
242sm_pb 76
243sm_pnum get grln i
244sm_pb 32
245x = sm_pcp get grule mul i 8 get grule add mul i 8 1
246sm_fset r FRULE o sub get gst SPOOL o
247sm_ks r KRUL add i 1
248end
249
250note sm_rlayer: record r takes the layer of the rule at grule[b] when it has none
251fn sm_rlayer r ulong b ulong to void
252if and eq sm_fl r FLAY 0 gt get grule add b 7 0
253sm_fset r FLAY get grule add b 6 get grule add b 7
254end
255end
256
257note sm_infer: apply the first matching rule to record r; a crumb-confirmed record only takes the layer
258fn sm_infer r ulong to void
259cf = ne sm_kg r KCONF 0
260for i ulong get gst SNRUL
261b = mul i 8
262if sm_rmatch i r
263po = get grule add b 2
264pn = get grule add b 3
265skip = false
266if not or cf or sm_pteq po pn tsroot sm_pteq po pn tsnone
267o = sm_pfull po pn
268skip = sm_isself r o get gst SSLEN
269end
270if not skip
271sm_rlayer r b
272if cf
273ret
274end
275sm_setrule r i
276if sm_pteq po pn tsroot
277sm_fsett r FPST tsroot
278sm_ks r KPNUL 1
279ret
280end
281if sm_pteq po pn tsnone
282sm_fsett r FPST tsnone
283sm_ks r KPNUL 1
284ret
285end
286o = sm_pfull po pn
287sm_fset r FPAR o get gst SSLEN
288sm_fsett r FPST tsinf
289sm_ks r KPNUL 0
290ret
291end
292end
293end
294if not cf
295sm_fsett r FPST tsnone
296sm_ks r KPNUL 1
297sm_fset r FRULE 0 0
298end
299end
300
301note sm_resolve: crumb parent (CONFIRMED), else rules; purpose and layer fall back to the crumb
302fn sm_resolve r ulong to void
303sm_ks r KCONF 0
304sm_ks r KPNUL 1
305sm_fset r FPAR 0 0
306sm_fset r FRULE 0 0
307if gt sm_fl r FCPAR 0
308o = sm_pfull sm_fo r FCPAR sm_fl r FCPAR
309n = get gst SSLEN
310if not sm_isself r o n
311sm_fset r FPAR o n
312sm_fsett r FPST tsconf
313sm_fsett r FRULE tcrumb
314sm_ks r KCONF 1
315sm_ks r KPNUL 0
316end
317end
318sm_infer r
319if eq sm_fl r FLAY 0
320sm_fset r FLAY sm_fo r FCLAY sm_fl r FCLAY
321end
322if eq sm_fl r FPUR 0
323sm_fset r FPUR sm_fo r FCPUR sm_fl r FCPUR
324end
325end
326
327note sm_refs: pin every parent without @ref to the parent's default branch, or @unknown
328fn sm_refs to void
329for r ulong get gst SNREC
330if eq sm_kg r KPNUL 0
331po = sm_fo r FPAR
332pn = sm_fl r FPAR
333if eq sm_pfind po pn 64 pn
334p = sm_find po pn
335o = sm_pcp po pn
336sm_pb 64
337if ne p SNONE
338if gt sm_fl p FDEF 0
339x = sm_pcp sm_fo p FDEF sm_fl p FDEF
340else
341x = sm_pt tunknown
342end
343else
344x = sm_pt tunknown
345end
346sm_fset r FPAR o sub get gst SPOOL o
347end
348end
349end
350end
351
352note sm_link: parent record index + 1 into KPIDX (0 when null or not in the map)
353fn sm_link to void
354for r ulong get gst SNREC
355sm_ks r KPIDX 0
356if eq sm_kg r KPNUL 0
357p = sm_find sm_fo r FPAR sm_parref r
358if ne p SNONE
359sm_ks r KPIDX add p 1
360end
361end
362end
363end