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