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