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 / gpu / runtime / cfacts.om

1607 lines · 32358 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/runtime/cfacts.om: facts about every C file (.c, .h, .inc) of CUDApp src/, read by gpu/runtime/classes.om,
3note in seeded Omega (OM-2 program mode, Linux AArch64). This file is the scanner; cfacts-main.om is the program
4note and check/cfacts-check.om the gate's check of it. Build from the repository root:
5note { printf 'om2\n'; cat seed/ng/sha256.om gpu/runtime/zsha.om gpu/runtime/cfacts.om gpu/runtime/cfacts-main.om; } \
6note | seed/out/omc > cfacts
7note Run from the repository root: cfacts ROOT [DIR] (ROOT a CUDApp checkout, DIR defaults to gpu/runtime)
8note Inputs in DIR: cudapp-src.sha256.txt (the files, with their sha256), cudapp-ident.txt (its unit= values name
9note Omega units: the C symbol of unit U is omega_U), devwords.txt (call names that reach the GPU, the driver
10note or the operating system). Every listed file is read at ROOT/PATH and must hash to its line of the list, so
11note the facts are of the CUDApp commit the list was taken from. A generated file (gen 1) is C that omega-bridge
12note lowered from Omega, so a name starting omega (omega_, omega2_) that it declares or defines (the name before a ( at brace and
13note paren depth 0, in the act lines) is an Omega unit too; it is found in the same passes as the off names.
14note Output on stdout: a header, then one row per file in list order, tab separated:
15note path the CUDApp path
16note gen 1 when the file starts with the bytes "/* Generated", else 0
17note act lines a default build compiles: CUDApp's Makefile build, every off name undefined or 0. The off
18note switches are the pending flags (names starting CUDAPP_MIGRATION_PENDING), which select the old C kept
19note to compare against, and OMEGA_GPU_NO_POSIX, which selects the C kept for the freestanding build. The
20note off names are the off switches and every name derived only from them: a name #define'd (with or
21note without parameters) in a dropped region of some file and outside a dropped region in none. The
22note files are read in passes: each pass uses the off names found by the passes before it, and the
23note passes stop when one finds no new off name; the rows are those of the last pass
24note pend lines that a default build drops because an off name is off: C kept for comparison or for the
25note freestanding build, where CUDApp cannot call Omega yet
26note fns function definitions in the act lines
27note omfn of them, functions that hand work to Omega: they call an Omega unit, or a function that does
28note devfn of the rest, functions that call a device word, or a function that does
29note hostl lines of the functions that do neither: host logic written in C
30note shell lines of the omfn and devfn functions
31note The rules, applied to the text with comments blanked and string and character literal bodies blanked:
32note - A line whose first byte that is not white space is # is a directive, joined with the next line while it
33note ends with a backslash. #if, #elif, #ifdef, #ifndef evaluate their condition in three values (false, true,
34note unknown): an off name is 0 and defined(NAME) is false; a name #define'd without parameters earlier in
35note the file outside a dropped region stands for its body when every enclosing region is certainly taken, and
36note is unknown otherwise, or when its chain of names meets a name twice; every other name is unknown; 0 is
37note false and other decimal numbers true; ! && || and
38note parentheses combine. A region whose condition is certainly false is dropped; #else and #elif follow C.
39note - A directive counts in act unless it starts inside a dropped region (then pend) or opens one (neither).
40note Other lines count when they hold a byte that is not white space: in pend inside a dropped region, else act.
41note - A function definition is a { at brace depth 0 whose last token at depth 0 was ); its name is the token
42note before the first ( of that statement. A { at depth 0 after a string token (extern "C" {) opens nothing.
43note Its lines are the act lines from the one with its { to the one with its matching }.
44note - A call is a name followed, on the same line after spaces and tabs, by (. A call names the functions of
45note that name in the same file when there are any, else every function of that name in the list.
46note Exit 0, 2 bad usage, 3 an input is malformed or unreadable or a file does not hash to its list line, 4 the
47note host refused memory. Memory grows with the input; the one fixed buffer is a path of PATH_MAX (4096) bytes.
48text cf_dflt "gpu/runtime"
49text cf_fsrc "/cudapp-src.sha256.txt"
50text cf_fid "/cudapp-ident.txt"
51text cf_fdev "/devwords.txt"
52text cf_hdr "path\tgen\tact\tpend\tfns\tomfn\tdevfn\thostl\tshell\n"
53text cf_kgen "/* Generated"
54text cf_kpend "CUDAPP_MIGRATION_PENDING"
55text cf_knp "OMEGA_GPU_NO_POSIX"
56text cf_komega "omega_"
57text cf_kgenom "omega"
58text cf_kcc "CORE_CALL"
59text cf_kcv "CORE_VOID"
60text cf_kunit "unit="
61text cf_kc ".c"
62text cf_kh ".h"
63text cf_kinc ".inc"
64text cf_wif "if"
65text cf_wifdef "ifdef"
66text cf_wifndef "ifndef"
67text cf_welif "elif"
68text cf_welse "else"
69text cf_wendif "endif"
70text cf_wdefine "define"
71text cf_wdefined "defined"
72text cf_e_usage "usage: cfacts ROOT [DIR] (ROOT a CUDApp checkout; run from the repository root)\n"
73text cf_e_read "cfacts: cannot read "
74text cf_e_list "cfacts: malformed sha256 list line in "
75text cf_e_sha "cfacts: the file does not hash to its line of cudapp-src.sha256.txt: "
76text cf_e_mem "cfacts: the host refused memory\n"
77text cf_e_long "cfacts: a path is longer than 4095 bytes\n"
78global cf_t uchar *
79global cf_f uchar *
80global cf_o uchar *
81global cf_w uchar *
82global cf_nm uchar *
83global cf_ni ulong *
84global cf_h ulong *
85global cf_fn ulong *
86global cf_cl ulong *
87global cf_r ulong *
88global cf_al ulong *
89global cf_g ulong *
90global cf_fh ulong *
91global cf_fx ulong *
92global cf_dn ulong *
93global cf_pa uchar 4096
94global cf_root uchar 4096
95global cf_dir uchar 4096
96global cf_n ulong 64
97note cf_t inputs, cf_f the file being read, cf_o output, cf_w a name being interned, cf_nm name bytes, cf_ni per
98note name (start, length, kind: 1 an Omega unit, 2 a device word), cf_h the name hash table (name + 1, 0 empty),
99note cf_fn per function (file, name, flags 1 Omega 2 device, lines, first call, end of calls), cf_cl call names,
100note cf_r per file (path start, path end, gen, act, pend, fns, omfn, devfn, hostl, shell), cf_al per #define
101note (name, body start, body end; start CF_NONE when unknown), cf_g the region stack (value, taken),
102note cf_dn per name 1 a #define of it in a dropped region this pass, 2 one outside a dropped region, 4 off,
103note cf_fh per name its first function + 1, cf_fx per function the next of its name + 1.
104note cf_n: 0 path length, 1 dir length, 2 cf_t used, 3 cf_o used, 4..9 ranges [s,e) of the list, ident, devwords;
105note 10 cf_f length, 11 names, 12 cf_nm used, 13 hash table size, 14 functions, 15 calls, 16 files, 17 defines,
106note 18 region depth, 19, 20 the condition cursor and its end, 21 root length, 22 cf_w length, 23 brace depth,
107note 24 in a function, 25 it calls Omega, 26 it calls a device word, 27 its lines, 28 the last byte at depth 0,
108note 29 paren depth at depth 0, 30, 31 the name candidate [s,e), 32, 33 the previous token [s,e), 34 the function
109note name, 35 its first call, 36 act, 37 pend, 38 fns, 39 this line counted, 40 file index, 41, 42 the condition
110note token [s,e), 43 its kind (0 none, 1 name, 2 number, 3 &&, 4 ||, 5 one byte), 44 the file is generated,
111note 45 this pass found a new Omega unit in a generated file, 46 CORE_CALL state (1 after the name, 2 after its ()
112const CF_NONE ulong 9223372036854775808
113note ---- failure
114fn die t view uchar * code int to void
115r = write 2 t 0 len t
116exit code
117end
118fn diepa t view uchar * to void
119r = write 2 t 0 len t
120r = write 2 cf_pa 0 get cf_n 0
121q = new uchar 1 10
122r = write 2 q 0 1
123exit 3
124end
125note ---- growth: each makes room for index n
126fn gt_ n ulong to void
127if ge n len cf_t
128r = enlarge cf_t add mul n 2 131072
129if ne r 0
130die cf_e_mem 4
131end
132end
133end
134fn gf_ n ulong to void
135if ge n len cf_f
136r = enlarge cf_f add mul n 2 131072
137if ne r 0
138die cf_e_mem 4
139end
140end
141end
142fn gw_ n ulong to void
143if ge n len cf_w
144r = enlarge cf_w add mul n 2 4096
145if ne r 0
146die cf_e_mem 4
147end
148end
149end
150fn gnm_ n ulong to void
151if ge n len cf_nm
152r = enlarge cf_nm add mul n 2 65536
153if ne r 0
154die cf_e_mem 4
155end
156end
157end
158fn gni_ n ulong to void
159if ge n len cf_ni
160r = enlarge cf_ni add mul n 2 4096
161if ne r 0
162die cf_e_mem 4
163end
164end
165end
166fn gfn_ n ulong to void
167if ge n len cf_fn
168r = enlarge cf_fn add mul n 2 4096
169if ne r 0
170die cf_e_mem 4
171end
172end
173end
174fn gcl_ n ulong to void
175if ge n len cf_cl
176r = enlarge cf_cl add mul n 2 4096
177if ne r 0
178die cf_e_mem 4
179end
180end
181end
182fn gr_ n ulong to void
183if ge n len cf_r
184r = enlarge cf_r add mul n 2 4096
185if ne r 0
186die cf_e_mem 4
187end
188end
189end
190fn gal_ n ulong to void
191if ge n len cf_al
192r = enlarge cf_al add mul n 2 4096
193if ne r 0
194die cf_e_mem 4
195end
196end
197end
198fn gg_ n ulong to void
199if ge n len cf_g
200r = enlarge cf_g add mul n 2 64
201if ne r 0
202die cf_e_mem 4
203end
204end
205end
206fn gdn_ n ulong to void
207if ge n len cf_dn
208r = enlarge cf_dn add mul n 2 4096
209if ne r 0
210die cf_e_mem 4
211end
212end
213end
214note ---- output pool
215fn oc c ulong to void
216n = get cf_n 3
217if ge n len cf_o
218r = enlarge cf_o add mul n 2 65536
219if ne r 0
220die cf_e_mem 4
221end
222end
223put cf_o n uchar c
224put cf_n 3 add n 1
225end
226fn ot t view uchar * to void
227for i ulong len t bound 4096
228oc ulong get t i
229end
230end
231fn otr a ulong b ulong to void
232for i ulong sub b a bound 9223372036854775807
233oc ulong get cf_t add a i
234end
235end
236fn onum v ulong to void
237if ge v 10
238onum div v 10
239end
240oc add 48 rem v 10
241end
242fn oflush to void
243n = get cf_n 3
244o = ulong 0
245while lt o n bound 9223372036854775807
246x = write 1 cf_o o sub n o
247if le x 0
248exit 3
249end
250o = add o ulong x
251end
252put cf_n 3 0
253end
254note ---- paths: cf_pa[0, cf_n 0)
255fn pclr to void
256put cf_n 0 0
257end
258fn pc c ulong to void
259n = get cf_n 0
260if ge n 4095
261die cf_e_long 3
262end
263put cf_pa n uchar c
264put cf_n 0 add n 1
265end
266fn pt t view uchar * to void
267for i ulong len t bound 4096
268pc ulong get t i
269end
270end
271fn ptr a ulong b ulong to void
272for i ulong sub b a bound 9223372036854775807
273pc ulong get cf_t add a i
274end
275end
276fn pdir t view uchar * to void
277pclr
278for i ulong get cf_n 1 bound 4096
279pc ulong get cf_dir i
280end
281pt t
282end
283note ROOT / then cf_t[a, b)
284fn proot a ulong b ulong to void
285pclr
286for i ulong get cf_n 21 bound 4096
287pc ulong get cf_root i
288end
289pc 47
290ptr a b
291end
292fn popen to int
293r = fopen cf_pa 0 get cf_n 0 int 524288 int 0
294if lt r 0
295ret -1
296end
297ret int r
298end
299note ---- inputs: append the file at cf_pa to cf_t; slot k gets its start, k+1 its end
300fn tload k ulong to void
301fd = popen
302if lt fd 0
303diepa cf_e_read
304end
305s = get cf_n 2
306n = s
307while true bound 9223372036854775807
308gt_ add n 65536
309x = read fd cf_t n sub len cf_t n
310if lt x 0
311diepa cf_e_read
312end
313if eq x 0
314break
315end
316n = add n ulong x
317end
318r = fclose fd
319put cf_n 2 n
320put cf_n k s
321put cf_n add k 1 n
322end
323note the file at cf_pa into cf_f[0, cf_n 10)
324fn fload to void
325fd = popen
326if lt fd 0
327diepa cf_e_read
328end
329n = ulong 0
330while true bound 9223372036854775807
331gf_ add n 65536
332x = read fd cf_f n sub len cf_f n
333if lt x 0
334diepa cf_e_read
335end
336if eq x 0
337break
338end
339n = add n ulong x
340end
341r = fclose fd
342put cf_n 10 n
343end
344note ---- bytes
345fn teol p ulong e ulong to ulong
346q = p
347while lt q e bound 9223372036854775807
348if eq get cf_t q 10
349ret q
350end
351q = add q 1
352end
353ret e
354end
355fn feol p ulong e ulong to ulong
356q = p
357while lt q e bound 9223372036854775807
358if eq get cf_f q 10
359ret q
360end
361q = add q 1
362end
363ret e
364end
365fn tteq a ulong n ulong t view uchar * to bool
366if ne n len t
367ret false
368end
369for i ulong n bound 4096
370if ne get cf_t add a i get t i
371ret false
372end
373end
374ret true
375end
376fn fteq a ulong n ulong t view uchar * to bool
377if ne n len t
378ret false
379end
380for i ulong n bound 4096
381if ne get cf_f add a i get t i
382ret false
383end
384end
385ret true
386end
387note cf_f[a, e) starts with t
388fn fpre a ulong e ulong t view uchar * to bool
389if lt sub e a len t
390ret false
391end
392ret fteq a len t t
393end
394note cf_t[a, e) ends with t
395fn tsuf a ulong e ulong t view uchar * to bool
396if lt sub e a len t
397ret false
398end
399ret tteq sub e len t len t t
400end
401note white space as C and Python's ASCII \s have it, less the newline
402fn isws c ulong to bool
403if or eq c 32 eq c 9
404ret true
405end
406ret or or eq c 13 eq c 12 eq c 11
407end
408note white space inside a directive: also the newline and backslash of a joined line
409fn dws c ulong to bool
410if isws c
411ret true
412end
413ret or eq c 10 eq c 92
414end
415fn isids c ulong to bool
416if or eq c 95 and ge c 97 le c 122
417ret true
418end
419ret and ge c 65 le c 90
420end
421fn isidc c ulong to bool
422if isids c
423ret true
424end
425ret and ge c 48 le c 57
426end
427note end of the name characters of cf_f from a, before e
428fn idend a ulong e ulong to ulong
429q = a
430while lt q e bound 9223372036854775807
431if not isidc ulong get cf_f q
432ret q
433end
434q = add q 1
435end
436ret e
437end
438note cf_f[s, e) is an off switch: a pending flag name, or OMEGA_GPU_NO_POSIX
439fn ispend s ulong e ulong to bool
440ret or fpre s e cf_kpend fteq s sub e s cf_knp
441end
442fn ishex c uchar to bool
443if and ge c 48 le c 57
444ret true
445end
446ret and ge c 97 le c 102
447end
448note ---- sha256sum list: 64 lowercase hex, two spaces, a path of at least one byte
449fn lineok p ulong q ulong to bool
450if lt sub q p 67
451ret false
452end
453for i ulong 64
454if not ishex get cf_t add p i
455ret false
456end
457end
458ret and eq get cf_t add p 64 32 eq get cf_t add p 65 32
459end
460fn listok to void
461p = get cf_n 4
462e = get cf_n 5
463while lt p e bound 9223372036854775807
464q = teol p e
465if or eq q e not lineok p q
466pdir cf_fsrc
467diepa cf_e_list
468end
469p = add q 1
470end
471end
472fn digeq p ulong to bool
473for j ulong 32
474b = get sh_dig j
475if ne get cf_t add p mul j 2 sh_hexd uint shr b 4
476ret false
477end
478if ne get cf_t add p add mul j 2 1 sh_hexd uint and b 15
479ret false
480end
481end
482ret true
483end
484note ---- names: interned, so a name is a number
485fn wclr to void
486put cf_n 22 0
487end
488fn wc c ulong to void
489n = get cf_n 22
490gw_ n
491put cf_w n uchar c
492put cf_n 22 add n 1
493end
494fn wf a ulong b ulong to void
495for i ulong sub b a bound 9223372036854775807
496wc ulong get cf_f add a i
497end
498end
499fn wtr a ulong b ulong to void
500for i ulong sub b a bound 9223372036854775807
501wc ulong get cf_t add a i
502end
503end
504fn wt t view uchar * to void
505for i ulong len t bound 4096
506wc ulong get t i
507end
508end
509fn fnvw to ulong
510h = ulong 14695981039346656037
511for i ulong get cf_n 22 bound 9223372036854775807
512h = mul xor h ulong get cf_w i 1099511628211
513end
514ret h
515end
516fn fnvn id ulong to ulong
517s = get cf_ni mul id 3
518n = get cf_ni add mul id 3 1
519h = ulong 14695981039346656037
520for i ulong n bound 9223372036854775807
521c = ulong get cf_nm add s i
522h = mul xor h c 1099511628211
523end
524ret h
525end
526fn nmeq id ulong to bool
527s = get cf_ni mul id 3
528n = get cf_ni add mul id 3 1
529if ne n get cf_n 22
530ret false
531end
532for i ulong n bound 9223372036854775807
533if ne get cf_nm add s i get cf_w i
534ret false
535end
536end
537ret true
538end
539fn hins id ulong h ulong to void
540m = sub get cf_n 13 1
541i = and h m
542while ne get cf_h i 0 bound 9223372036854775807
543i = and add i 1 m
544end
545put cf_h i add id 1
546end
547note a table of sz empty slots, then every name back in
548fn hsize sz ulong to void
549if lt len cf_h sz
550r = enlarge cf_h sz
551if ne r 0
552die cf_e_mem 4
553end
554end
555for i ulong sz bound 9223372036854775807
556put cf_h i 0
557end
558put cf_n 13 sz
559for id ulong get cf_n 11 bound 9223372036854775807
560hins id fnvn id
561end
562end
563note the devwords.txt line cf_t[a, b) (trimmed, not empty) names cf_w: a line ending in * names every name
564note starting with the rest; a line starting with # names nothing
565fn dlm a ulong b ulong to bool
566if ne get cf_t a 35
567n = get cf_n 22
568e = b
569pre = eq get cf_t sub b 1 42
570if pre
571e = sub b 1
572end
573k = sub e a
574if or eq k n and pre le k n
575for i ulong k bound 9223372036854775807
576if ne get cf_t add a i get cf_w i
577ret false
578end
579end
580ret true
581end
582end
583ret false
584end
585note cf_w against devwords.txt: 2 when a line names it
586fn devk to ulong
587p = get cf_n 8
588e = get cf_n 9
589while lt p e bound 9223372036854775807
590q = teol p e
591a = p
592while lt a q bound 9223372036854775807
593if not isws ulong get cf_t a
594break
595end
596a = add a 1
597end
598b = q
599while gt b a bound 9223372036854775807
600if not isws ulong get cf_t sub b 1
601break
602end
603b = sub b 1
604end
605if lt a b
606if dlm a b
607ret 2
608end
609end
610p = add q 1
611end
612ret 0
613end
614fn intern to ulong
615h = fnvw
616m = sub get cf_n 13 1
617i = and h m
618while true bound 9223372036854775807
619x = get cf_h i
620if eq x 0
621break
622end
623if nmeq sub x 1
624ret sub x 1
625end
626i = and add i 1 m
627end
628id = get cf_n 11
629s = get cf_n 12
630n = get cf_n 22
631gnm_ add s n
632for j ulong n bound 9223372036854775807
633put cf_nm add s j get cf_w j
634end
635put cf_n 12 add s n
636gni_ add mul id 3 2
637gdn_ id
638put cf_ni mul id 3 s
639put cf_ni add mul id 3 1 n
640put cf_ni add mul id 3 2 devk
641put cf_h i add id 1
642put cf_n 11 add id 1
643if ge mul add id 1 2 get cf_n 13
644hsize mul get cf_n 13 2
645end
646ret id
647end
648note every unit=U of cudapp-ident.txt: the name omega_U is an Omega unit
649fn units to void
650p = get cf_n 6
651e = get cf_n 7
652while lt p e bound 9223372036854775807
653ok = false
654if ge sub e p len cf_kunit
655ok = tteq p len cf_kunit cf_kunit
656end
657if ok
658a = add p len cf_kunit
659b = a
660while lt b e bound 9223372036854775807
661c = ulong get cf_t b
662if or isws c eq c 10
663break
664end
665b = add b 1
666end
667if gt b a
668wclr
669wt cf_komega
670wtr a b
671id = intern
672k = add mul id 3 2
673put cf_ni k or get cf_ni k 1
674p = b
675else
676p = add p 1
677end
678else
679p = add p 1
680end
681end
682end
683note ---- C text: comments blanked, string and character literal bodies blanked (newlines stay)
684fn blank a ulong b ulong to void
685for i ulong sub b a bound 9223372036854775807
686if ne get cf_f add a i 10
687put cf_f add a i 32
688end
689end
690end
691note the end of the block comment opened at i (after its */), or n
692fn cmtend i ulong n ulong to ulong
693k = add i 2
694while lt add k 1 n bound 9223372036854775807
695if and eq get cf_f k 42 eq get cf_f add k 1 47
696ret add k 2
697end
698k = add k 1
699end
700ret n
701end
702note the stop of the literal opened at i by the byte c: its closing c, a newline, or n
703fn litend i ulong n ulong c ulong to ulong
704j = add i 1
705while lt j n bound 9223372036854775807
706x = ulong get cf_f j
707if or eq x c eq x 10
708ret j
709end
710if eq x 92
711j = add j 2
712else
713j = add j 1
714end
715end
716ret n
717end
718fn fstrip to void
719n = get cf_n 10
720i = ulong 0
721while lt i n bound 9223372036854775807
722c = ulong get cf_f i
723nx = i
724if lt add i 1 n
725d = ulong get cf_f add i 1
726if and eq c 47 eq d 42
727nx = cmtend i n
728blank i nx
729end
730if and eq c 47 eq d 47
731nx = feol i n
732blank i nx
733end
734end
735if eq nx i
736if or eq c 34 eq c 39
737j = litend i n c
738blank add i 1 j
739nx = j
740if lt j n
741if eq ulong get cf_f j c
742nx = add j 1
743end
744end
745end
746end
747if eq nx i
748nx = add i 1
749end
750i = nx
751end
752end
753note ---- regions
754fn anyoff to bool
755for k ulong get cf_n 18 bound 9223372036854775807
756if eq get cf_g mul k 2 0
757ret true
758end
759end
760ret false
761end
762fn allon to bool
763for k ulong get cf_n 18 bound 9223372036854775807
764if ne get cf_g mul k 2 1
765ret false
766end
767end
768ret true
769end
770fn gpush v ulong to void
771d = get cf_n 18
772gg_ add mul d 2 1
773put cf_g mul d 2 v
774put cf_g add mul d 2 1 v
775put cf_n 18 add d 1
776end
777fn c3and v ulong w ulong to ulong
778if or eq v 0 eq w 0
779ret 0
780end
781if and eq v 1 eq w 1
782ret 1
783end
784ret 2
785end
786fn c3or v ulong w ulong to ulong
787if or eq v 1 eq w 1
788ret 1
789end
790if and eq v 0 eq w 0
791ret 0
792end
793ret 2
794end
795note ---- conditions: the token at the cursor (slots 41, 42, 43), not consumed
796fn tk to void
797p = get cf_n 19
798e = get cf_n 20
799while lt p e bound 9223372036854775807
800if not dws ulong get cf_f p
801break
802end
803p = add p 1
804end
805put cf_n 19 p
806put cf_n 41 p
807put cf_n 42 p
808put cf_n 43 0
809if eq p e
810ret
811end
812c = ulong get cf_f p
813k = ulong 5
814q = add p 1
815if isidc c
816q = idend p e
817k = 2
818if isids c
819k = 1
820end
821else
822if lt q e
823d = ulong get cf_f q
824if and eq c 38 eq d 38
825q = add q 1
826k = 3
827end
828if and eq c 124 eq d 124
829q = add q 1
830k = 4
831end
832end
833end
834put cf_n 42 q
835put cf_n 43 k
836end
837fn adv to void
838put cf_n 19 get cf_n 42
839end
840note the token at the cursor is the one byte c
841fn tkis c ulong to bool
842tk
843if ne get cf_n 43 5
844ret false
845end
846ret eq ulong get cf_f get cf_n 41 c
847end
848fn tkk k ulong to bool
849tk
850ret eq get cf_n 43 k
851end
852note a number: 0 when it is one 0 then u U l L, 1 when digits then u U l L, else unknown
853fn numv s ulong e ulong to ulong
854i = s
855while lt i e bound 9223372036854775807
856c = get cf_f i
857if not and ge c 48 le c 57
858break
859end
860i = add i 1
861end
862nd = sub i s
863while lt i e bound 9223372036854775807
864c = get cf_f i
865if not or or eq c 117 eq c 85 or eq c 108 eq c 76
866ret 2
867end
868i = add i 1
869end
870if and eq nd 1 eq get cf_f s 48
871ret 0
872end
873ret 1
874end
875note name id is off: every #define of it, in every file, sat in a dropped region in an earlier pass
876fn dropname id ulong to bool
877ret ne and get cf_dn id 4 0
878end
879note cf_f[s, e) is false in a default build: an off switch, or a name derived only from one
880fn offname s ulong e ulong to bool
881if ispend s e
882ret true
883end
884wclr
885wf s e
886ret dropname intern
887end
888fn defd to ulong
889pr = false
890if tkis 40
891adv
892pr = true
893end
894tk
895k = get cf_n 43
896s = get cf_n 41
897e = get cf_n 42
898adv
899pd = false
900if eq k 1
901pd = offname s e
902end
903if pr
904if tkis 41
905adv
906end
907end
908if pd
909ret 0
910end
911ret 2
912end
913note the value of the name cf_f[s, e): its latest #define, read at depth dp + 1, or unknown
914fn aliasv s ulong e ulong dp ulong to ulong
915wclr
916wf s e
917id = intern
918n = get cf_n 17
919for j ulong n bound 9223372036854775807
920k = sub sub n 1 j
921if eq get cf_al mul k 3 id
922a = get cf_al add mul k 3 1
923if eq a CF_NONE
924ret 2
925end
926note a chain longer than the defines seen so far has met a name twice: a cycle, unknown
927if ge dp n
928ret 2
929end
930ret ev a get cf_al add mul k 3 2 add dp 1
931end
932end
933ret 2
934end
935fn prim dp ulong to ulong
936tk
937k = get cf_n 43
938if eq k 0
939ret 2
940end
941s = get cf_n 41
942e = get cf_n 42
943adv
944if eq k 5
945c = get cf_f s
946if eq c 33
947v = prim dp
948if eq v 2
949ret 2
950end
951ret sub 1 v
952end
953if eq c 40
954v = evor dp
955if tkis 41
956adv
957end
958ret v
959end
960ret 2
961end
962if eq k 2
963ret numv s e
964end
965if eq k 1
966if fteq s sub e s cf_wdefined
967ret defd
968end
969if offname s e
970ret 0
971end
972ret aliasv s e dp
973end
974ret 2
975end
976fn evand dp ulong to ulong
977v = prim dp
978while tkk 3 bound 9223372036854775807
979adv
980w = prim dp
981v = c3and v w
982end
983ret v
984end
985fn evor dp ulong to ulong
986v = evand dp
987while tkk 4 bound 9223372036854775807
988adv
989w = evand dp
990v = c3or v w
991end
992ret v
993end
994note the value of the condition cf_f[a, b): unknown unless every token is used
995fn ev a ulong b ulong dp ulong to ulong
996sp = get cf_n 19
997se = get cf_n 20
998put cf_n 19 a
999put cf_n 20 b
1000v = evor dp
1001tk
1002if ne get cf_n 43 0
1003v = 2
1004end
1005put cf_n 19 sp
1006put cf_n 20 se
1007ret v
1008end
1009note #ifdef (want 0) or #ifndef (want 1): an off switch or a name derived only from one decides, anything
1010note else is unknown
1011fn flagdir a ulong b ulong want ulong to void
1012put cf_n 19 a
1013put cf_n 20 b
1014tk
1015v = ulong 2
1016if eq get cf_n 43 1
1017if offname get cf_n 41 get cf_n 42
1018v = want
1019end
1020end
1021gpush v
1022end
1023fn dodefine a ulong b ulong dr bool to void
1024p = a
1025while lt p b bound 9223372036854775807
1026if not dws ulong get cf_f p
1027break
1028end
1029p = add p 1
1030end
1031if eq p b
1032ret
1033end
1034if not isids ulong get cf_f p
1035ret
1036end
1037q = idend p b
1038if ispend p q
1039ret
1040end
1041wclr
1042wf p q
1043id = intern
1044if dr
1045put cf_dn id or get cf_dn id 1
1046else
1047put cf_dn id or get cf_dn id 2
1048end
1049if lt q b
1050if eq get cf_f q 40
1051ret
1052end
1053end
1054if dr
1055ret
1056end
1057n = get cf_n 17
1058gal_ add mul n 3 2
1059put cf_al mul n 3 id
1060put cf_al add mul n 3 1 CF_NONE
1061put cf_al add mul n 3 2 CF_NONE
1062if allon
1063put cf_al add mul n 3 1 q
1064put cf_al add mul n 3 2 b
1065end
1066put cf_n 17 add n 1
1067end
1068fn doelif a ulong b ulong to void
1069d = get cf_n 18
1070if eq d 0
1071ret
1072end
1073k = mul sub d 1 2
1074w = ev a b 0
1075g = get cf_g add k 1
1076v = ulong 2
1077if eq g 1
1078v = 0
1079end
1080if eq g 0
1081v = w
1082end
1083if eq g 2
1084if eq w 0
1085v = 0
1086end
1087end
1088put cf_g k v
1089put cf_g add k 1 c3or g w
1090end
1091fn doelse to void
1092d = get cf_n 18
1093if eq d 0
1094ret
1095end
1096k = mul sub d 1 2
1097g = get cf_g add k 1
1098v = ulong 2
1099if eq g 1
1100v = 0
1101end
1102if eq g 0
1103v = 1
1104end
1105put cf_g k v
1106put cf_g add k 1 1
1107end
1108note one directive: cf_f[a, b) after its #, n physical lines
1109fn dline a ulong b ulong n ulong to void
1110off = anyoff
1111s = a
1112while lt s b bound 9223372036854775807
1113if not isws ulong get cf_f s
1114break
1115end
1116s = add s 1
1117end
1118t = s
1119if lt s b
1120if isids ulong get cf_f s
1121t = idend s b
1122end
1123end
1124w = sub t s
1125if fteq s w cf_wif
1126gpush ev t b 0
1127end
1128if fteq s w cf_wifdef
1129flagdir t b 0
1130end
1131if fteq s w cf_wifndef
1132flagdir t b 1
1133end
1134if fteq s w cf_welif
1135doelif t b
1136end
1137if fteq s w cf_welse
1138doelse
1139end
1140if fteq s w cf_wendif
1141d = get cf_n 18
1142if gt d 0
1143put cf_n 18 sub d 1
1144end
1145end
1146if fteq s w cf_wdefine
1147dodefine t b off
1148end
1149if off
1150put cf_n 37 add get cf_n 37 n
1151else
1152if not anyoff
1153put cf_n 36 add get cf_n 36 n
1154end
1155end
1156end
1157note ---- functions
1158fn setprev s ulong t ulong to void
1159put cf_n 32 s
1160put cf_n 33 t
1161end
1162fn fnopen to void
1163put cf_n 24 1
1164put cf_n 38 add get cf_n 38 1
1165put cf_n 25 0
1166put cf_n 26 0
1167wclr
1168wf get cf_n 30 get cf_n 31
1169put cf_n 34 intern
1170put cf_n 35 get cf_n 15
1171if eq get cf_n 39 0
1172put cf_n 27 add get cf_n 27 1
1173put cf_n 39 1
1174end
1175end
1176fn fnclose to void
1177put cf_n 24 0
1178n = get cf_n 14
1179gfn_ add mul n 6 5
1180b = mul n 6
1181put cf_fn b get cf_n 40
1182put cf_fn add b 1 get cf_n 34
1183put cf_fn add b 2 or get cf_n 25 shl get cf_n 26 1
1184put cf_fn add b 3 get cf_n 27
1185put cf_fn add b 4 get cf_n 35
1186put cf_fn add b 5 get cf_n 15
1187put cf_n 14 add n 1
1188put cf_n 27 0
1189end
1190note the name cf_f[s, t) inside a function: a call when ( follows on this line after spaces and tabs
1191fn callchk s ulong t ulong q ulong to void
1192k = t
1193while lt k q bound 9223372036854775807
1194c = get cf_f k
1195if not or eq c 32 eq c 9
1196break
1197end
1198k = add k 1
1199end
1200if eq k q
1201ret
1202end
1203if ne get cf_f k 40
1204ret
1205end
1206wclr
1207wf s t
1208id = intern
1209n = get cf_n 15
1210gcl_ n
1211put cf_cl n id
1212put cf_n 15 add n 1
1213if or fteq s sub t s cf_kcc fteq s sub t s cf_kcv
1214put cf_n 46 1
1215end
1216kd = get cf_ni add mul id 3 2
1217if ne and kd 1 0
1218put cf_n 25 1
1219else
1220if ne and kd 2 0
1221put cf_n 26 1
1222end
1223end
1224end
1225note CORE_CALL(N, ...) and CORE_VOID(N, ...) of src/omega_core_binding.h call omega_N: inside a function, a name
1226note right after CORE_CALL( or CORE_VOID( that is an Omega unit once omega_ is put before it makes the function Omega
1227fn corestep s ulong t ulong c ulong one bool to void
1228st = get cf_n 46
1229put cf_n 46 0
1230if eq st 1
1231if and one eq c 40
1232put cf_n 46 2
1233end
1234ret
1235end
1236if and eq st 2 isids c
1237wclr
1238wt cf_komega
1239wf s t
1240id = intern
1241if ne and get cf_ni add mul id 3 2 1 0
1242put cf_n 25 1
1243end
1244end
1245end
1246note one token cf_f[s, t) of a code line that ends at q
1247fn ctok s ulong t ulong q ulong to void
1248c = ulong get cf_f s
1249one = eq sub t s 1
1250d = get cf_n 23
1251if and one eq c 123
1252if eq d 0
1253if eq get cf_n 28 34
1254put cf_n 28 123
1255setprev s t
1256ret
1257end
1258if eq get cf_n 28 41
1259fnopen
1260end
1261end
1262put cf_n 23 add d 1
1263setprev s t
1264ret
1265end
1266if and one eq c 125
1267if gt d 0
1268d = sub d 1
1269put cf_n 23 d
1270end
1271if and eq d 0 eq get cf_n 24 1
1272fnclose
1273end
1274put cf_n 28 125
1275setprev s t
1276ret
1277end
1278if eq d 0
1279pd = get cf_n 29
1280if and one eq c 40
1281if eq pd 0
1282put cf_n 30 get cf_n 32
1283put cf_n 31 get cf_n 33
1284if ne get cf_n 44 0
1285gendecl
1286end
1287end
1288put cf_n 29 add pd 1
1289end
1290if and one eq c 41
1291if gt pd 0
1292put cf_n 29 sub pd 1
1293end
1294end
1295put cf_n 28 ulong get cf_f sub t 1
1296end
1297if eq get cf_n 24 1
1298corestep s t c one
1299if isids c
1300callchk s t q
1301end
1302end
1303setprev s t
1304end
1305note in a generated file, the token before a ( at brace and paren depth 0: a name starting omega is an Omega unit
1306fn gendecl to void
1307s = get cf_n 32
1308t = get cf_n 33
1309if not fpre s t cf_kgenom
1310ret
1311end
1312wclr
1313wf s t
1314id = intern
1315k = add mul id 3 2
1316v = get cf_ni k
1317if eq and v 1 0
1318put cf_ni k or v 1
1319put cf_n 45 1
1320end
1321end
1322note one code line cf_f[a, q) that holds a byte that is not white space, outside dropped regions
1323fn ctoks a ulong q ulong to void
1324put cf_n 39 0
1325if eq get cf_n 24 1
1326put cf_n 27 add get cf_n 27 1
1327put cf_n 39 1
1328end
1329p = a
1330while lt p q bound 9223372036854775807
1331c = ulong get cf_f p
1332if isws c
1333p = add p 1
1334continue
1335end
1336t = add p 1
1337if isids c
1338t = idend p q
1339end
1340ctok p t q
1341p = t
1342end
1343end
1344note the physical line [ls, qq) ends with a backslash and another line follows it in a file of e bytes
1345fn dcont ls ulong qq ulong e ulong to bool
1346if ge add qq 1 e
1347ret false
1348end
1349k = qq
1350while gt k ls bound 9223372036854775807
1351if not isws ulong get cf_f sub k 1
1352break
1353end
1354k = sub k 1
1355end
1356if eq k ls
1357ret false
1358end
1359ret eq get cf_f sub k 1 92
1360end
1361fn fscan to void
1362put cf_n 17 0
1363put cf_n 18 0
1364for k ulong 17 bound 64
1365put cf_n add k 23 0
1366end
1367e = get cf_n 10
1368p = ulong 0
1369while lt p e bound 9223372036854775807
1370q = feol p e
1371a = p
1372while lt a q bound 9223372036854775807
1373if not isws ulong get cf_f a
1374break
1375end
1376a = add a 1
1377end
1378isd = false
1379if lt a q
1380if eq get cf_f a 35
1381isd = true
1382end
1383end
1384if isd
1385ls = p
1386qq = q
1387n = ulong 1
1388while dcont ls qq e bound 9223372036854775807
1389ls = add qq 1
1390qq = feol ls e
1391n = add n 1
1392end
1393dline add a 1 qq n
1394p = add qq 1
1395else
1396if anyoff
1397if lt a q
1398put cf_n 37 add get cf_n 37 1
1399end
1400else
1401if lt a q
1402put cf_n 36 add get cf_n 36 1
1403ctoks a q
1404end
1405end
1406p = add q 1
1407end
1408end
1409end
1410note ---- one listed file: the list line's hex at h, its path cf_t[a, b)
1411fn fproc h ulong a ulong b ulong to void
1412proot a b
1413fload
1414n = get cf_n 10
1415zbeg
1416for i ulong n bound 9223372036854775807
1417zbyte ulong get cf_f i
1418end
1419zend
1420if not digeq h
1421diepa cf_e_sha
1422end
1423fi = get cf_n 16
1424gr_ add mul fi 10 9
1425r = mul fi 10
1426put cf_r r a
1427put cf_r add r 1 b
1428put cf_r add r 2 0
1429put cf_n 44 0
1430put cf_n 46 0
1431if fpre 0 n cf_kgen
1432put cf_r add r 2 1
1433put cf_n 44 1
1434end
1435for k ulong 7
1436put cf_r add r add k 3 0
1437end
1438put cf_n 40 fi
1439fstrip
1440fscan
1441put cf_r add r 3 get cf_n 36
1442put cf_r add r 4 get cf_n 37
1443put cf_r add r 5 get cf_n 38
1444put cf_n 16 add fi 1
1445end
1446note ---- the call closure
1447note the flags of the functions a call of name id from file fi names
1448fn ftarg id ulong fi ulong to ulong
1449same = false
1450x = get cf_fh id
1451while ne x 0 bound 9223372036854775807
1452k = sub x 1
1453if eq get cf_fn mul k 6 fi
1454same = true
1455end
1456x = get cf_fx k
1457end
1458fl = ulong 0
1459x = get cf_fh id
1460while ne x 0 bound 9223372036854775807
1461k = sub x 1
1462if or not same eq get cf_fn mul k 6 fi
1463fl = or fl get cf_fn add mul k 6 2
1464end
1465x = get cf_fx k
1466end
1467ret fl
1468end
1469fn fpass k ulong to bool
1470b = mul k 6
1471fl = get cf_fn add b 2
1472if eq fl 3
1473ret false
1474end
1475fi = get cf_fn b
1476s = get cf_fn add b 4
1477n = sub get cf_fn add b 5 s
1478nf = fl
1479for j ulong n bound 9223372036854775807
1480id = get cf_cl add s j
1481t = ftarg id fi
1482nf = or nf t
1483end
1484if eq nf fl
1485ret false
1486end
1487put cf_fn add b 2 nf
1488ret true
1489end
1490fn closure to void
1491nn = get cf_n 11
1492nf = get cf_n 14
1493if lt len cf_fh add nn 1
1494r = enlarge cf_fh add nn 1
1495if ne r 0
1496die cf_e_mem 4
1497end
1498end
1499if lt len cf_fx add nf 1
1500r = enlarge cf_fx add nf 1
1501if ne r 0
1502die cf_e_mem 4
1503end
1504end
1505for i ulong nn bound 9223372036854775807
1506put cf_fh i 0
1507end
1508for k ulong nf bound 9223372036854775807
1509id = get cf_fn add mul k 6 1
1510put cf_fx k get cf_fh id
1511put cf_fh id add k 1
1512end
1513ch = true
1514while ch bound 9223372036854775807
1515ch = false
1516for k ulong nf bound 9223372036854775807
1517if fpass k
1518ch = true
1519end
1520end
1521end
1522tally nf
1523end
1524note add each function to its file: omfn and shell, devfn and shell, or hostl
1525fn tally nf ulong to void
1526for k ulong nf bound 9223372036854775807
1527b = mul k 6
1528r = mul get cf_fn b 10
1529fl = get cf_fn add b 2
1530ln = get cf_fn add b 3
1531if ne and fl 1 0
1532put cf_r add r 6 add get cf_r add r 6 1
1533put cf_r add r 9 add get cf_r add r 9 ln
1534else
1535if ne and fl 2 0
1536put cf_r add r 7 add get cf_r add r 7 1
1537put cf_r add r 9 add get cf_r add r 9 ln
1538else
1539put cf_r add r 8 add get cf_r add r 8 ln
1540end
1541end
1542end
1543end
1544fn rows to void
1545ot cf_hdr
1546for fi ulong get cf_n 16 bound 9223372036854775807
1547r = mul fi 10
1548otr get cf_r r get cf_r add r 1
1549for k ulong 8
1550oc 9
1551onum get cf_r add r add k 2
1552end
1553oc 10
1554if ge get cf_n 3 1048576
1555oflush
1556end
1557end
1558oflush
1559end
1560note one pass: read every listed file (all) or the .c, .h and .inc ones
1561fn cfpass all bool to void
1562put cf_n 14 0
1563put cf_n 15 0
1564put cf_n 16 0
1565put cf_n 45 0
1566for i ulong get cf_n 11 bound 9223372036854775807
1567put cf_dn i and get cf_dn i 4
1568end
1569p = get cf_n 4
1570e = get cf_n 5
1571while lt p e bound 9223372036854775807
1572q = teol p e
1573a = add p 66
1574if or all or or tsuf a q cf_kc tsuf a q cf_kh tsuf a q cf_kinc
1575fproc p a q
1576end
1577p = add q 1
1578end
1579end
1580note a name #define'd in a dropped region and nowhere else in this pass becomes off; true when one did, or when
1581note the pass found a new Omega unit in a generated file
1582fn newoff to bool
1583ch = false
1584for i ulong get cf_n 11 bound 9223372036854775807
1585if eq and get cf_dn i 7 1
1586put cf_dn i 5
1587ch = true
1588end
1589end
1590ret or ch ne get cf_n 45 0
1591end
1592note the list (slots 4, 5), cudapp-ident.txt (6, 7) and devwords.txt (8, 9) are loaded and cf_root is set:
1593note pass over the files until no name becomes off and no new Omega unit is found (each pass only adds, so this
1594note ends), then write the rows of the last pass
1595fn cfrun all bool to void
1596listok
1597put cf_n 11 0
1598hsize 65536
1599units
1600ch = true
1601while ch bound 9223372036854775807
1602cfpass all
1603ch = newoff
1604end
1605closure
1606rows
1607end