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 / bridge / babel / src / 20-split.om

697 lines · 11003 bytes Raw Blame History
1note babel 20-split: input walk, file table, C top-level item scanner, unit table.
2note Files: relative path F0/Fl (pool), size Fsz, sha256 hex Fh0 (pool, 64 bytes), language Flg.
3global F0 ulong 2048
4global Fl ulong 2048
5global Fsz ulong 2048
6global Fh0 ulong 2048
7global Flg ulong 2048
8global Nf ulong 1
9note Units: file Ufi, kind Ukd, lines Ul0/Ul1, text Ut0/Utn, name Un0/Unn, adapter name Ua0/Uan,
10note Omega name Uw0/Uwn, status Ust, stage Usg, exit code Urc, reason Ur0/Urn, arity Uar, driver id Uid,
11note vectors Uv0/Uvn (pool), count Unv, oracle output Uo0/Uon, mismatches Umo (Omega) and Umt (target).
12global Ufi ulong 1024
13global Ukd ulong 1024
14global Ul0 ulong 1024
15global Ul1 ulong 1024
16global Ut0 ulong 1024
17global Utn ulong 1024
18global Un0 ulong 1024
19global Unn ulong 1024
20global Ua0 ulong 1024
21global Uan ulong 1024
22global Uw0 ulong 1024
23global Uwn ulong 1024
24global Ust ulong 1024
25global Usg ulong 1024
26global Urc ulong 1024
27global Ur0 ulong 1024
28global Urn ulong 1024
29global Uar ulong 1024
30global Uid ulong 1024
31global Uv0 ulong 1024
32global Uvn ulong 1024
33global Unv ulong 1024
34global Uo0 ulong 1024
35global Uon ulong 1024
36global Umo ulong 1024
37global Umt ulong 1024
38global Uno ulong 1024
39global Nu ulong 1
40global Sk0 ulong 2048
41global Skl ulong 2048
42global Skr ulong 2048
43global Nsk ulong 1
44note scanner state
45global Sx ulong 1
46global Sln ulong 1
47global Sfn ulong 1
48global Sn0 ulong 1
49global Sn1 ulong 1
50global Si0 ulong 1
51global Si1 ulong 1
52global Sp0 ulong 1
53global Sp1 ulong 1
54text ExC ".c"
55text ExH ".h"
56text ExRs ".rs"
57text ExPy ".py"
58text ExGo ".go"
59text ExZig ".zig"
60text ExCpp ".cpp"
61text ExCc ".cc"
62text ExCxx ".cxx"
63text ExHpp ".hpp"
64text ExBab ".babel"
65text IncStd "#include <stdint.h>"
66text WVoid "void"
67text NmCalc "calc"
68text NmPfx "omega_"
69
70note language codes: 0 other, 1 c, 2 rust, 3 python, 4 go, 5 zig, 6 cpp
71fn langof o ulong n ulong to ulong
72if plsuf o n ExC
73ret 1
74end
75if plsuf o n ExH
76ret 1
77end
78if plsuf o n ExRs
79ret 2
80end
81if plsuf o n ExPy
82ret 3
83end
84if plsuf o n ExGo
85ret 4
86end
87if plsuf o n ExZig
88ret 5
89end
90if plsuf o n ExCpp
91ret 6
92end
93if plsuf o n ExCc
94ret 6
95end
96if plsuf o n ExCxx
97ret 6
98end
99if plsuf o n ExHpp
100ret 6
101end
102ret 0
103end
104
105fn addfile r0 ulong r1 ulong to void
106n = get Nf 0
107if ge n 2048
108put Cap 0 1
109ret
110end
111p = psave r0 sub r1 r0
112put F0 n p
113put Fl n sub r1 r0
114put Flg n langof p sub r1 r0
115put Nf 0 add n 1
116end
117
118note walk directory Ob[p0, p1) whose path relative to the input root is Ob[r0, r1)
119note dot entries, symbolic links, other non-regular files and *.babel output folders are not walked;
120note each one is recorded in the skip table (skipadd) so the completion record counts it; depth <= 24
121fn walk p0 ulong p1 ulong r0 ulong r1 ulong depth ulong to void
122if gt depth 24
123put Cap 0 1
124ret
125end
126m = mark
127e = dirrecs p0 p1
128if eq e 0
129reset m
130skipadd r0 r1 5
131ret
132end
133o = m
134while lt o e bound 999999
135o = walkent o p0 p1 r0 r1 depth
136end
137reset m
138end
139
140fn walkent o ulong p0 ulong p1 ulong r0 ulong r1 ulong depth ulong to ulong
141n = add o 1
142k = n
143while ne get Ob k 0 bound 4096
144k = add k 1
145end
146c0 = mark
147bob p0 sub p1 p0
148bc 47
149bob n sub k n
150c1 = mark
151if gt r1 r0
152bob r0 sub r1 r0
153bc 47
154end
155bob n sub k n
156c2 = mark
157if eq get Ob n 46
158skipadd c1 c2 1
159else
160walkone c0 c1 c2 depth
161end
162reset c0
163ret add k 1
164end
165
166note one non-dot entry: full path Ob[c0, c1), relative path Ob[c1, c2)
167fn walkone c0 ulong c1 ulong c2 ulong depth ulong to void
168t = ftype c0 c1
169if eq t 2
170if obteq sub c2 len ExBab len ExBab ExBab
171skipadd c1 c2 4
172else
173walk c0 c1 c1 c2 add depth 1
174end
175end
176if eq t 1
177addfile c1 c2
178end
179if eq t 3
180if eq and get Sb 17 240 160
181skipadd c1 c2 2
182else
183skipadd c1 c2 3
184end
185end
186if eq t 0
187skipadd c1 c2 6
188end
189end
190
191note skip table: relative path Sk0/Skl (pool), reason Skr: 1 dot entry, 2 symbolic link,
192note 3 other non-regular file, 4 *.babel folder, 5 unreadable directory, 6 lstat failed
193fn skipadd r0 ulong r1 ulong why ulong to void
194n = get Nsk 0
195if ge n 2048
196put Cap 0 1
197ret
198end
199put Sk0 n psave r0 sub r1 r0
200put Skl n sub r1 r0
201put Skr n why
202put Nsk 0 add n 1
203end
204
205note skip table in path order, like the file table
206fn sksort to void
207n = get Nsk 0
208i = ulong 1
209while lt i n bound 4096
210j = i
211while gt j 0 bound 4096
212a = sub j 1
213if not pllt get Sk0 j get Skl j get Sk0 a get Skl a
214break
215end
216skswap j a
217j = a
218end
219i = add i 1
220end
221end
222
223fn skswap i ulong j ulong to void
224t = get Sk0 i
225put Sk0 i get Sk0 j
226put Sk0 j t
227t = get Skl i
228put Skl i get Skl j
229put Skl j t
230t = get Skr i
231put Skr i get Skr j
232put Skr j t
233end
234
235note lexicographic order of files by relative path (insertion sort over the table)
236fn pllt a ulong an ulong b ulong bn ulong to bool
237n = an
238if lt bn n
239n = bn
240end
241for i ulong n
242x = get Pl add a i
243y = get Pl add b i
244if lt x y
245ret true
246end
247if gt x y
248ret false
249end
250end
251ret lt an bn
252end
253
254fn fswap i ulong j ulong to void
255t = get F0 i
256put F0 i get F0 j
257put F0 j t
258t = get Fl i
259put Fl i get Fl j
260put Fl j t
261t = get Flg i
262put Flg i get Flg j
263put Flg j t
264end
265
266fn fsort to void
267n = get Nf 0
268i = ulong 1
269while lt i n bound 4096
270j = i
271while gt j 0 bound 4096
272a = sub j 1
273if not pllt get F0 j get Fl j get F0 a get Fl a
274break
275end
276fswap j a
277j = a
278end
279i = add i 1
280end
281end
282
283fn newunit fi ulong kind ulong l0 ulong l1 ulong to ulong
284u = get Nu 0
285if ge u 1024
286put Cap 0 1
287ret 1023
288end
289put Ufi u fi
290put Ukd u kind
291put Ul0 u l0
292put Ul1 u l1
293put Ust u 0
294put Usg u 1
295put Urc u 0
296put Urn u 0
297put Nu 0 add u 1
298ret u
299end
300
301fn ureason u ulong s view uchar * to void
302put Ur0 u ptext s
303put Urn u len s
304end
305
306note reason built on the arena from mark m
307fn ureasob u ulong m ulong to void
308put Ur0 u psave m sub mark m
309put Urn u sub mark m
310reset m
311end
312
313fn isid c uchar to bool
314if eq c 95
315ret true
316end
317if ge c 97
318ret le c 122
319end
320if ge c 65
321ret le c 90
322end
323if ge c 48
324ret le c 57
325end
326ret false
327end
328
329fn isidst c uchar to bool
330if ge c 48
331if le c 57
332ret false
333end
334end
335ret isid c
336end
337
338note skip from Fb[i] (a quote) to just past the matching close quote
339fn skipq i ulong to ulong
340n = get Fn 0
341q = get Fb i
342j = add i 1
343while lt j n bound 999999
344c = get Fb j
345if eq c 92
346j = add j 2
347continue
348end
349if eq c 10
350put Sln 0 add get Sln 0 1
351end
352if eq c q
353ret add j 1
354end
355j = add j 1
356end
357ret n
358end
359
360note skip a comment at Fb[i] ('/' then '/' or '*'); returns the index after it
361fn skipcm i ulong to ulong
362n = get Fn 0
363if eq get Fb add i 1 47
364j = i
365while lt j n bound 999999
366if eq get Fb j 10
367ret j
368end
369j = add j 1
370end
371ret n
372end
373j = add i 2
374while lt j n bound 999999
375c = get Fb j
376if eq c 10
377put Sln 0 add get Sln 0 1
378end
379if eq c 42
380if lt add j 1 n
381if eq get Fb add j 1 47
382ret add j 2
383end
384end
385end
386j = add j 1
387end
388ret n
389end
390
391fn iscmt i ulong to bool
392if ne get Fb i 47
393ret false
394end
395n = get Fn 0
396if ge add i 1 n
397ret false
398end
399c = get Fb add i 1
400if eq c 47
401ret true
402end
403ret eq c 42
404end
405
406note scan one top-level item starting at Fb[i]. Sets Sx (end), Sfn (1 function definition,
407note 2 declaration, 4 runs into end of file), Sn0/Sn1 (name), Sp0/Sp1 (parameter list inside parens)
408fn citem i ulong to void
409n = get Fn 0
410dep = ulong 0
411pd = ulong 0
412last = uchar 0
413nm = false
414put Sfn 0 4
415put Sn0 0 0
416put Sn1 0 0
417put Si0 0 0
418put Si1 0 0
419put Sp0 0 0
420put Sp1 0 0
421while lt i n bound 999999
422c = get Fb i
423if eq c 10
424put Sln 0 add get Sln 0 1
425i = add i 1
426continue
427end
428if iscmt i
429i = skipcm i
430continue
431end
432if le c 32
433i = add i 1
434continue
435end
436if eq c 34
437i = skipq i
438last = c
439continue
440end
441if eq c 39
442i = skipq i
443last = c
444continue
445end
446if isidst c
447i = cident i dep pd
448last = 97
449continue
450end
451if eq c 40
452if eq dep 0
453if eq pd 0
454if not nm
455nm = true
456put Sn0 0 get Si0 0
457put Sn1 0 get Si1 0
458put Sp0 0 add i 1
459end
460end
461end
462pd = add pd 1
463end
464if eq c 41
465if gt pd 0
466pd = sub pd 1
467end
468if eq dep 0
469if eq pd 0
470if eq get Sp1 0 0
471put Sp1 0 i
472end
473end
474end
475end
476if eq c 123
477if eq dep 0
478if eq pd 0
479if eq last 41
480put Sfn 0 1
481end
482end
483end
484dep = add dep 1
485end
486if eq c 125
487if gt dep 0
488dep = sub dep 1
489end
490if eq dep 0
491if eq get Sfn 0 1
492put Sx 0 add i 1
493ret
494end
495end
496end
497if eq c 59
498if eq dep 0
499if eq pd 0
500if ne get Sfn 0 1
501put Sfn 0 2
502put Sx 0 add i 1
503ret
504end
505end
506end
507end
508last = c
509i = add i 1
510end
511put Sfn 0 4
512put Sx 0 n
513end
514
515note identifier at Fb[i]; at top level it becomes the latest identifier (Si0/Si1)
516fn cident i ulong dep ulong pd ulong to ulong
517n = get Fn 0
518j = i
519while lt j n bound 999999
520if not isid get Fb j
521break
522end
523j = add j 1
524end
525if eq dep 0
526if eq pd 0
527put Si0 0 i
528put Si1 0 j
529end
530end
531ret j
532end
533
534note preprocessor line from Fb[i] ('#'), with backslash continuations; returns the index of its newline
535fn cpre i ulong to ulong
536n = get Fn 0
537j = i
538while lt j n bound 999999
539c = get Fb j
540if eq c 10
541if gt j i
542if eq get Fb sub j 1 92
543put Sln 0 add get Sln 0 1
544j = add j 1
545continue
546end
547end
548ret j
549end
550j = add j 1
551end
552ret n
553end
554
555fn fbteq o ulong n ulong s view uchar * to bool
556if ne n len s
557ret false
558end
559for i ulong n
560if ne get Fb add o i get s i
561ret false
562end
563end
564ret true
565end
566
567note arity from the parameter list Fb[a, b): 0 for "" or "void", else top-level commas + 1
568fn carity a ulong b ulong to ulong
569s = a
570while lt s b bound 999999
571if gt get Fb s 32
572break
573end
574s = add s 1
575end
576e = b
577while gt e s bound 999999
578if gt get Fb sub e 1 32
579break
580end
581e = sub e 1
582end
583if eq s e
584ret 0
585end
586if fbteq s sub e s WVoid
587ret 0
588end
589k = ulong 1
590d = ulong 0
591for i ulong sub e s
592c = get Fb add s i
593if eq c 40
594d = add d 1
595end
596if eq c 41
597d = sub d 1
598end
599if eq c 44
600if eq d 0
601k = add k 1
602end
603end
604end
605ret k
606end
607
608text RsPre "preprocessor directive: no adapter translates C preprocessing (S1 accepts only the leading `#include <stdint.h>`, which babel supplies)"
609text RsDecl "top-level declaration (prototype, global, type or typedef): no adapter translates C declarations; S1 covers one pure u64 function per unit"
610text RsEof "unterminated item at end of file: babel could not find the end of this top-level item"
611text RsAbs "absorbed: `#include <stdint.h>` is the S1 profile header; babel adds it to every unit"
612
613note split the C file fi (already in Fb) into units
614fn csplit fi ulong to void
615n = get Fn 0
616put Sln 0 1
617i = ulong 0
618while lt i n bound 999999
619c = get Fb i
620if eq c 10
621put Sln 0 add get Sln 0 1
622i = add i 1
623continue
624end
625if iscmt i
626i = skipcm i
627continue
628end
629if le c 32
630i = add i 1
631continue
632end
633l0 = get Sln 0
634if eq c 35
635e = cpre i
636u = newunit fi 3 l0 get Sln 0
637ctext u i e
638if fbteq i sub e i IncStd
639put Ukd u 6
640put Ust u 6
641ureason u RsAbs
642else
643put Ust u 3
644ureason u RsPre
645end
646i = e
647continue
648end
649citem i
650e = get Sx 0
651k = get Sfn 0
652u = newunit fi k l0 get Sln 0
653ctext u i e
654cname u
655if eq k 1
656put Uar u carity get Sp0 0 get Sp1 0
657end
658if eq k 2
659put Ust u 3
660ureason u RsDecl
661end
662if eq k 4
663put Ust u 3
664ureason u RsEof
665end
666i = e
667end
668end
669
670fn ctext u ulong a ulong b ulong to void
671m = mark
672bfb a sub b a
673put Ut0 u psave m sub b a
674put Utn u sub b a
675put Sx 0 a
676reset m
677end
678
679note unit name: the identifier before the first top-level '(' or else the latest top-level identifier;
680note its offset inside the unit text goes to Uno (used for the adapter rename)
681fn cname u ulong to void
682a = get Sn0 0
683b = get Sn1 0
684if eq b 0
685a = get Si0 0
686b = get Si1 0
687end
688if eq b 0
689ret
690end
691m = mark
692bfb a sub b a
693put Un0 u psave m sub b a
694put Unn u sub b a
695put Uno u sub a get Sx 0
696reset m
697end