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/30-pipe.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 / 30-pipe.om` 613 lines ยท 8600 bytes Raw Blame History 1 note babel 30-pipe: configuration, paths, adapter runs per unit (import, lower, Omega check, export). 2 global Rt0 ulong 1 3 global Rtn ulong 1 4 global Isf ulong 1 5 global Ot0 ulong 1 6 global Otn ulong 1 7 global Ad0 ulong 1 8 global Adn ulong 1 9 global Lg ulong 1 10 global Tl0 ulong 8 11 global Tln ulong 8 12 global Tv0 ulong 8 13 global Tvn ulong 8 14 global Pg0 ulong 1 15 global Pgn ulong 1 16 global Nid ulong 1 17 global Jsn ulong 1 18 global Col ulong 1 19 text AdDir "/tools/adapters/" 20 text OmcRel "/build/T624/seed/seed/out/omc" 21 text OmcPin "`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`" 22 text Slash "/" 23 text NL "\n" 24 text Wk ".work/" 25 text WkIn "unit.c" 26 text WkUp "up.omsa" 27 text WkC "c.omsa" 28 text WkT "t.omsa" 29 text WkErr "err.txt" 30 text WkOut "out.txt" 31 text WkBin "check.bin" 32 text DOmega "omega/" 33 text ExOm ".om" 34 text ExOmsa ".omsa" 35 text AdCi "c-import" 36 text AdRt "retarget" 37 text AdLo "lower" 38 text ArgC "c" 39 text ArgRs "rust" 40 text ArgPy "python" 41 text ArgCpp "cpp" 42 text ArgZig "zig" 43 text ArgGo "go" 44 text AdRsE "rust-export" 45 text AdPyE "python-export" 46 text AdCE "c-export" 47 text AdCpE "cpp-export" 48 text AdZgE "zig-export" 49 text AdGoE "go-export" 50 text RsDup "BABEL_DUPLICATE_NAME: a unit with this name was already translated in this run; babel packages one flat namespace per target" 51 text RsExit "exit " 52 text RsEmpty " with empty stderr" 53 text RsOmc "omc (pinned `734f0a39`) refused the lowered unit: " 54 text RsLow "lower refused the imported unit: " 55 text RsTool "adapter environment failure (not a profile refusal): " 56 text RsNoTl "target toolchain not found; export written but never built or run: " 57 text Ext_rs ".rs" 58 text Ext_py ".py" 59 text Ext_c ".c" 60 text Ext_cp ".cpp" 61 text Ext_zg ".zig" 62 text Ext_go ".go" 63 text URs "rust/src/units/" 64 text UCc "c/units/" 65 text UCp "cpp/units/" 66 text UZg "zig/units/" 67 text UGo "go/" 68 text UGoF "/calc.go" 69 text UPy "/units/" 70 text DPy "python/" 71 text HdStd "#include \n" 72 73 fn bout to void 74 bpl get Ot0 0 get Otn 0 75 end 76 77 note / 78 fn bouts s view uchar * to void 79 bout 80 bc 47 81 bs s 82 end 83 84 note /.work/ 85 fn bwk s view uchar * to void 86 bout 87 bc 47 88 bs Wk 89 bs s 90 end 91 92 note /tools/adapters/ 93 fn bad s view uchar * to void 94 bpl get Ad0 0 get Adn 0 95 bs AdDir 96 bs s 97 end 98 99 fn bname u ulong to void 100 bpl get Un0 u get Unn u 101 end 102 103 fn rset i ulong a ulong b ulong to void 104 put Rio i a 105 put Rio add i 1 b 106 end 107 108 note stdin, stdout and stderr from three .work names; argv must already hold the program 109 fn rwork si view uchar * so view uchar * to void 110 a = mark 111 bwk si 112 b = mark 113 bwk so 114 c = mark 115 bwk WkErr 116 d = mark 117 rset 0 a b 118 rset 2 b c 119 rset 4 c d 120 end 121 122 note first line of .work/err.txt as the unit reason, prefixed by s 123 fn errwhy u ulong s view uchar * rc ulong to void 124 m = mark 125 bs s 126 k = mark 127 bwk WkErr 128 e = mark 129 r = rfile k e 130 reset k 131 n = ulong 0 132 if gt r 0 133 n = ulong r 134 end 135 j = ulong 0 136 while lt j n bound 999999 137 if eq get Fb j 10 138 break 139 end 140 j = add j 1 141 end 142 if gt j 400 143 j = 400 144 end 145 if eq j 0 146 bs RsExit 147 bu rc 148 bs RsEmpty 149 else 150 bfb 0 j 151 end 152 ureasob u m 153 end 154 155 fn kad s view uchar * to void 156 m = mark 157 bad s 158 e = mark 159 kob m sub e m 160 reset m 161 end 162 163 note c-import with stdin .work/unit.c and stdout .work/up.omsa 164 fn adimport to ulong 165 m = mark 166 rclr 167 kenv 168 kad AdCi 169 rwork WkIn WkUp 170 r = spawn 171 reset m 172 ret r 173 end 174 175 note copy .work/up.omsa to /omega/.omsa 176 fn wkomsa u ulong to long 177 m = mark 178 bwk WkUp 179 a = mark 180 bouts DOmega 181 bname u 182 bs ExOmsa 183 b = mark 184 r = cphash m a a b 185 reset m 186 ret r 187 end 188 189 fn isrefusal rc ulong to bool 190 if ge rc 65 191 ret le rc 72 192 end 193 ret false 194 end 195 196 fn setst u ulong st ulong sg ulong rc ulong to void 197 put Ust u st 198 put Usg u sg 199 put Urc u rc 200 end 201 202 note unit text with the adapter rename, prefixed by the S1 header 203 fn bunit u ulong to void 204 bs HdStd 205 o = get Ut0 u 206 n = get Utn u 207 k = get Uno u 208 bpl o k 209 if not renamed u 210 bs NmPfx 211 end 212 bpl add o k sub n k 213 bc 10 214 end 215 216 fn renamed u ulong to bool 217 o = get Un0 u 218 n = get Unn u 219 if plteq o n NmCalc 220 ret true 221 end 222 ret plpre o n NmPfx 223 end 224 225 fn setaname u ulong to void 226 m = mark 227 if not renamed u 228 bs NmPfx 229 end 230 bname u 231 put Ua0 u psave m sub mark m 232 put Uan u sub mark m 233 reset m 234 end 235 236 fn dupname u ulong to bool 237 for i ulong u 238 if ge get Ust i 7 239 if pleq get Un0 i get Unn i get Un0 u get Unn u 240 ret true 241 end 242 end 243 end 244 ret false 245 end 246 247 note import stage: write .work/unit.c and omega/.c, run c-import 248 fn stimport u ulong to bool 249 setaname u 250 m = mark 251 bunit u 252 c1 = mark 253 bwk WkIn 254 p1 = mark 255 w = wfile m c1 c1 p1 256 reset c1 257 r = adimport 258 if ne r 0 259 if isrefusal r 260 setst u 2 2 r 261 else 262 setst u 4 2 r 263 end 264 if isrefusal r 265 errwhy u NL r 266 else 267 errwhy u RsTool r 268 end 269 trimnl u 270 reset m 271 ret false 272 end 273 if dupname u 274 setst u 3 2 0 275 ureason u RsDup 276 reset m 277 ret false 278 end 279 bouts DOmega 280 bname u 281 bs Ext_c 282 p2 = mark 283 w = wfile m c1 c1 p2 284 reset m 285 c = wkomsa u 286 ret true 287 end 288 289 note drop the leading newline errwhy uses as an empty prefix 290 fn trimnl u ulong to void 291 if gt get Urn u 0 292 if eq get Pl get Ur0 u 10 293 put Ur0 u add get Ur0 u 1 294 put Urn u sub get Urn u 1 295 end 296 end 297 end 298 299 note /omega/.omsa as stdin, a .work file as stdout 300 fn romsa u ulong so view uchar * to void 301 a = mark 302 bouts DOmega 303 bname u 304 bs ExOmsa 305 b = mark 306 bwk so 307 c = mark 308 bwk WkErr 309 d = mark 310 rset 0 a b 311 rset 2 b c 312 rset 4 c d 313 end 314 315 note lower stage: retarget c then lower NAME into omega/.om, then the function-mode Omega check 316 fn stlower u ulong to bool 317 m = mark 318 rclr 319 kenv 320 kad AdRt 321 ktx ArgC 322 romsa u WkC 323 r = spawn 324 reset m 325 if ne r 0 326 setst u 4 3 r 327 errwhy u RsLow r 328 ret false 329 end 330 r = lowerto u get Un0 u get Unn u 331 if eq r 64 332 r = lowerto u get Ua0 u get Uan u 333 put Uw0 u get Ua0 u 334 put Uwn u get Uan u 335 else 336 put Uw0 u get Un0 u 337 put Uwn u get Unn u 338 end 339 if ne r 0 340 setst u 4 3 r 341 errwhy u RsLow r 342 ret false 343 end 344 r = omccheck u 345 if ne r 0 346 setst u 4 4 r 347 errwhy u RsOmc r 348 ret false 349 end 350 ret true 351 end 352 353 fn lowerto u ulong no ulong nn ulong to ulong 354 m = mark 355 rclr 356 kenv 357 kad AdLo 358 kpl no nn 359 a = mark 360 bwk WkC 361 b = mark 362 bouts DOmega 363 bname u 364 bs ExOm 365 c = mark 366 bwk WkErr 367 d = mark 368 rset 0 a b 369 rset 2 b c 370 rset 4 c d 371 r = spawn 372 reset m 373 ret r 374 end 375 376 fn bomc to void 377 bpl get Ad0 0 get Adn 0 378 bs OmcRel 379 end 380 381 fn omccheck u ulong to ulong 382 m = mark 383 rclr 384 krst 385 k = mark 386 bomc 387 e = mark 388 kob k sub e k 389 reset k 390 a = mark 391 bouts DOmega 392 bname u 393 bs ExOm 394 b = mark 395 bwk WkBin 396 c = mark 397 bwk WkErr 398 d = mark 399 rset 0 a b 400 rset 2 b c 401 rset 4 c d 402 r = spawn 403 reset m 404 ret r 405 end 406 407 note export stage for the selected target 408 fn stexport u ulong to bool 409 g = get Lg 0 410 r = ulong 0 411 if eq g 2 412 r = exp2 u AdRsE ArgRs 413 end 414 if eq g 3 415 r = exp2 u AdPyE ArgPy 416 end 417 if eq g 1 418 r = expc u 419 end 420 if eq g 6 421 r = exp1 u AdCpE 422 end 423 if eq g 5 424 r = exp1 u AdZgE 425 end 426 if eq g 4 427 r = expgo u 428 end 429 if ne r 0 430 if isrefusal r 431 setst u 2 5 r 432 errwhy u NL r 433 trimnl u 434 else 435 setst u 4 5 r 436 errwhy u RsTool r 437 end 438 ret false 439 end 440 put Uid u get Nid 0 441 put Nid 0 add get Nid 0 1 442 setst u 7 5 0 443 ret true 444 end 445 446 note unit output path of the selected target: / 447 fn bupath u ulong to void 448 g = get Lg 0 449 if eq g 2 450 bouts URs 451 end 452 if eq g 3 453 bouts DPy 454 bpl get Pg0 0 get Pgn 0 455 bs UPy 456 end 457 if eq g 1 458 bouts UCc 459 end 460 if eq g 6 461 bouts UCp 462 end 463 if eq g 5 464 bouts UZg 465 end 466 bname u 467 bext 468 end 469 470 fn bext to void 471 g = get Lg 0 472 if eq g 2 473 bs Ext_rs 474 end 475 if eq g 3 476 bs Ext_py 477 end 478 if eq g 1 479 bs Ext_c 480 end 481 if eq g 6 482 bs Ext_cp 483 end 484 if eq g 5 485 bs Ext_zg 486 end 487 end 488 489 note retarget to the target, then the target exporter without arguments 490 fn exp2 u ulong ad view uchar * arg view uchar * to ulong 491 m = mark 492 rclr 493 kenv 494 kad AdRt 495 ktx arg 496 romsa u WkT 497 r = spawn 498 reset m 499 if ne r 0 500 ret r 501 end 502 rclr 503 kenv 504 kad ad 505 a = mark 506 bwk WkT 507 b = mark 508 bupath u 509 c = mark 510 bwk WkErr 511 d = mark 512 rset 0 a b 513 rset 2 b c 514 rset 4 c d 515 r = spawn 516 reset m 517 ret r 518 end 519 520 note exporters that read the upper envelope directly (cpp, zig) 521 fn exp1 u ulong ad view uchar * to ulong 522 m = mark 523 rclr 524 kenv 525 kad ad 526 a = mark 527 bouts DOmega 528 bname u 529 bs ExOmsa 530 b = mark 531 bupath u 532 c = mark 533 bwk WkErr 534 d = mark 535 rset 0 a b 536 rset 2 b c 537 rset 4 c d 538 r = spawn 539 reset m 540 ret r 541 end 542 543 note C: .work/c.omsa (retarget c from the lower stage) into c-export with the adapter name 544 fn expc u ulong to ulong 545 m = mark 546 rclr 547 kenv 548 kad AdCE 549 kpl get Ua0 u get Uan u 550 a = mark 551 bwk WkC 552 b = mark 553 bupath u 554 c = mark 555 bwk WkErr 556 d = mark 557 rset 0 a b 558 rset 2 b c 559 rset 4 c d 560 r = spawn 561 reset m 562 ret r 563 end 564 565 note Go: one package-main directory per unit, go//calc.go 566 fn expgo u ulong to ulong 567 m = mark 568 bouts UGo 569 bname u 570 e = mark 571 q = mkdirs m e 572 reset m 573 rclr 574 kenv 575 kad AdGoE 576 a = mark 577 bouts DOmega 578 bname u 579 bs ExOmsa 580 b = mark 581 bouts UGo 582 bname u 583 bs UGoF 584 c = mark 585 bwk WkErr 586 d = mark 587 rset 0 a b 588 rset 2 b c 589 rset 4 c d 590 r = spawn 591 reset m 592 ret r 593 end 594 595 note run every function unit through import, lower, Omega check and export 596 fn pipeline to void 597 for u ulong get Nu 0 598 if ne get Ukd u 1 599 continue 600 end 601 if ne get Ust u 0 602 continue 603 end 604 progress u 605 if not stimport u 606 continue 607 end 608 if not stlower u 609 continue 610 end 611 ok = stexport u 612 end 613 end