babel
aien-dev/babel
Brought by drakestapleton
| 1 | note babel 90-main: arguments, the target picker, input copy and the run order. |
| 2 | global Nocol ulong 1 |
| 3 | global Ps0 ulong 1 |
| 4 | global Psn ulong 1 |
| 5 | global Rd0 ulong 1 |
| 6 | global Rdn ulong 1 |
| 7 | global Ln uchar 64 |
| 8 | text Usage "usage: babel <path> [--to rust|c|python|cpp|zig|go] [--json] [--no-color] [--complete] [--exclude FILE] [--adapters DIR]\n\nTranslate the C functions under <path> through Omega into the target language. The result goes\nnext to <path>, in <path>.babel/: input/ (a hashed copy), omega/ (the Omega units), <target>/\n(the generated project), diff/ (the differential test) and REPORT.md + report.json.\n\nOnly profile S1 is implemented (pure functions of 0-6 uint64_t inputs using + - * modulo 2^64).\nEverything else is reported, with the reason and location, and is never approximated.\n\n --to LANG target: rust, c, python, cpp, zig or go (asked interactively when omitted on a terminal)\n --json print report.json on stdout instead of the summary table\n --no-color no ANSI colour (also when NO_COLOR is set or stdout is not a terminal)\n --complete strict completion policy complete-v1: exit 0 only when every walked file, split item,\n skipped entry and required check is covered or excluded (state COMPLETE)\n --exclude FILE exclusion manifest: one \"<path> <reason>\" per line, path relative to <path>, an exact\n path or a dir/ prefix (no globs); blank and # lines ignored. An excluded entry stays in\n the denominator as EXCLUDED. Source files and their split items cannot be excluded.\n A line without a reason, an entry that matches nothing or one that names source exits 2.\n --adapters DIR omega-mv checkout with built adapters (default: $BABEL_ADAPTERS)\n --version print the version and pins\n\nexit status: 0 no FAIL, 1 at least one FAIL, 2 usage, environment or exclusion-manifest error,\n64 no target and no terminal\nwith --complete: 0 COMPLETE, 1 FAILED, 3 PARTIAL, 4 BLOCKED (2 and 64 as above)\n" |
| 9 | text VerL "babel 0.1.0\nbuilt with omega-mv seed/out/omc OM-2 (main 0b77e6ea2, sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f)\nadapters: aien-dev/omega-mv universal/624-g1-integration 2d4c6407, profile S1 c17-uint64-pure-v1\nadapter omc sha256 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61\n" |
| 10 | text OTo "--to" |
| 11 | text OToE "--to=" |
| 12 | text OJson "--json" |
| 13 | text ONoc "--no-color" |
| 14 | text OCpl "--complete" |
| 15 | text OAd "--adapters" |
| 16 | text OAdE "--adapters=" |
| 17 | text OExc "--exclude" |
| 18 | text OExcE "--exclude=" |
| 19 | text OHelp "--help" |
| 20 | text OShort "-h" |
| 21 | text OVer "--version" |
| 22 | text EvAd "BABEL_ADAPTERS=" |
| 23 | text EvNoc "NO_COLOR=" |
| 24 | text LcPlus "c++" |
| 25 | text LcRs "rs" |
| 26 | text LcPy "py" |
| 27 | text EUnk "babel: unknown option: " |
| 28 | text EBadL "babel: unknown target language: " |
| 29 | text ETwo "babel: more than one <path> given\n" |
| 30 | text ENoP "babel: no <path> given (see babel --help)\n" |
| 31 | text ENoA "babel: no adapters: pass --adapters DIR or set BABEL_ADAPTERS to an omega-mv checkout whose adapters were built (tools/adapters/build-g3.py, see README)\n" |
| 32 | text ENoEx "babel: --exclude needs a manifest FILE\n" |
| 33 | text ENoIn "babel: input not found or not a regular file or directory: " |
| 34 | text EPin1 "babel: the adapters' native omc at " |
| 35 | text EPin2 " does not have the pinned sha256 734f0a39...6b61 (rebuild the adapters at the pinned revision; see README)\n" |
| 36 | text ENoTty "babel: no --to given and stdin is not a terminal; pass --to rust|c|python|cpp|zig|go\n" |
| 37 | text EOut "babel: cannot create the output folder: " |
| 38 | text ECap "babel: an internal capacity was exceeded (2048 files, 1024 units, 8 MiB pool); the report is incomplete\n" |
| 39 | text PkPick1 "babel: choose a target language for " |
| 40 | text PkPick2 "\n 1) rust 2) c 3) python 4) cpp 5) zig 6) go\n> " |
| 41 | text BabExt ".babel" |
| 42 | text DInput "input" |
| 43 | text DOm "omega" |
| 44 | text DDiff "diff" |
| 45 | text DWk ".work" |
| 46 | text DRsU "rust/src/units" |
| 47 | text DRsB "rust/src/bin" |
| 48 | text DRsT "rust/tests" |
| 49 | text DCU "c/units" |
| 50 | text DCpU "cpp/units" |
| 51 | text DCpD "cpp/diff" |
| 52 | text DZU "zig/units" |
| 53 | text DGo "go" |
| 54 | text DPyR "python" |
| 55 | text DUnits "/units" |
| 56 | text GitHead "/.git/HEAD" |
| 57 | text GitDir "/.git/" |
| 58 | text RefPfx "ref: " |
| 59 | text PkgDef "babel_out" |
| 60 | text PkgP "p_" |
| 61 | text RsBig "file larger than babel's 512 KiB splitter buffer: not split, nothing translated" |
| 62 | text RsLang1 "no babel splitter for " |
| 63 | text RsLang2 " sources yet: the omega-mv " |
| 64 | text RsLang3 "-import adapter takes one function per unit, and babel cannot cut " |
| 65 | text RsLang4 " files into units (C is the only input language in this release)" |
| 66 | text RsRead "file could not be read: " |
| 67 | text Zero64 "0000000000000000000000000000000000000000000000000000000000000000" |
| 68 | |
| 69 | fn argeq i ulong s view uchar * to bool |
| 70 | n = argread i Ag 0 len Ag |
| 71 | if ne n long len s |
| 72 | ret false |
| 73 | end |
| 74 | for j ulong len s |
| 75 | if ne get Ag j get s j |
| 76 | ret false |
| 77 | end |
| 78 | end |
| 79 | ret true |
| 80 | end |
| 81 | |
| 82 | note argument i into the pool (Ps0/Psn); false when it does not fit |
| 83 | fn argpl i ulong to bool |
| 84 | n = argread i Ag 0 len Ag |
| 85 | if lt n 0 |
| 86 | ret false |
| 87 | end |
| 88 | m = mark |
| 89 | for j ulong ulong n |
| 90 | bc get Ag j |
| 91 | end |
| 92 | put Ps0 0 psave m ulong n |
| 93 | put Psn 0 ulong n |
| 94 | reset m |
| 95 | ret true |
| 96 | end |
| 97 | |
| 98 | fn eputs s view uchar * to void |
| 99 | w = write 2 s 0 len s |
| 100 | end |
| 101 | |
| 102 | fn eputpl o ulong n ulong to void |
| 103 | m = mark |
| 104 | bpl o n |
| 105 | bc 10 |
| 106 | flush 2 m |
| 107 | end |
| 108 | |
| 109 | note language code of the pool text Ps0/Psn: 1 c, 2 rust, 3 python, 4 go, 5 zig, 6 cpp, 0 unknown |
| 110 | fn langname o ulong n ulong to ulong |
| 111 | if plteq o n LnC |
| 112 | ret 1 |
| 113 | end |
| 114 | if plteq o n LnRs |
| 115 | ret 2 |
| 116 | end |
| 117 | if plteq o n LcRs |
| 118 | ret 2 |
| 119 | end |
| 120 | if plteq o n LnPy |
| 121 | ret 3 |
| 122 | end |
| 123 | if plteq o n LcPy |
| 124 | ret 3 |
| 125 | end |
| 126 | if plteq o n LnGo |
| 127 | ret 4 |
| 128 | end |
| 129 | if plteq o n LnZig |
| 130 | ret 5 |
| 131 | end |
| 132 | if plteq o n LnCpp |
| 133 | ret 6 |
| 134 | end |
| 135 | if plteq o n LcPlus |
| 136 | ret 6 |
| 137 | end |
| 138 | ret 0 |
| 139 | end |
| 140 | |
| 141 | note parse argv; returns 0 to continue, else an exit status + 1 |
| 142 | fn args to ulong |
| 143 | c = argcnt |
| 144 | i = ulong 1 |
| 145 | put Rtn 0 0 |
| 146 | while lt i ulong c bound 4096 |
| 147 | r = arg1 i |
| 148 | if ge r 1000 |
| 149 | i = add i 1 |
| 150 | r = sub r 1000 |
| 151 | end |
| 152 | if ne r 0 |
| 153 | ret r |
| 154 | end |
| 155 | i = add i 1 |
| 156 | end |
| 157 | ret 0 |
| 158 | end |
| 159 | |
| 160 | note one argument at i: 0 consumed, 1000 + 0 consumed with its value, else exit status + 1 |
| 161 | fn arg1 i ulong to ulong |
| 162 | if argeq i OHelp |
| 163 | eputs Usage |
| 164 | ret 1 |
| 165 | end |
| 166 | if argeq i OShort |
| 167 | eputs Usage |
| 168 | ret 1 |
| 169 | end |
| 170 | if argeq i OVer |
| 171 | w = write 1 VerL 0 len VerL |
| 172 | ret 1 |
| 173 | end |
| 174 | if argeq i OJson |
| 175 | put Jsn 0 1 |
| 176 | ret 0 |
| 177 | end |
| 178 | if argeq i ONoc |
| 179 | put Nocol 0 1 |
| 180 | ret 0 |
| 181 | end |
| 182 | if argeq i OCpl |
| 183 | put Cpl 0 1 |
| 184 | ret 0 |
| 185 | end |
| 186 | if argeq i OTo |
| 187 | ret argto add i 1 |
| 188 | end |
| 189 | if argeq i OAd |
| 190 | ret argad add i 1 |
| 191 | end |
| 192 | if argeq i OExc |
| 193 | ret argex add i 1 |
| 194 | end |
| 195 | ok = argpl i |
| 196 | if not ok |
| 197 | eputs EUnk |
| 198 | ret 3 |
| 199 | end |
| 200 | o = get Ps0 0 |
| 201 | n = get Psn 0 |
| 202 | if plpre o n OToE |
| 203 | put Lg 0 langname add o len OToE sub n len OToE |
| 204 | if eq get Lg 0 0 |
| 205 | eputs EBadL |
| 206 | eputpl o n |
| 207 | ret 3 |
| 208 | end |
| 209 | ret 0 |
| 210 | end |
| 211 | if plpre o n OAdE |
| 212 | put Ad0 0 add o len OAdE |
| 213 | put Adn 0 sub n len OAdE |
| 214 | ret 0 |
| 215 | end |
| 216 | if plpre o n OExcE |
| 217 | put Ex0 0 add o len OExcE |
| 218 | put Exn 0 sub n len OExcE |
| 219 | ret 0 |
| 220 | end |
| 221 | if gt n 0 |
| 222 | if eq get Pl o 45 |
| 223 | eputs EUnk |
| 224 | eputpl o n |
| 225 | ret 3 |
| 226 | end |
| 227 | end |
| 228 | if gt get Rtn 0 0 |
| 229 | eputs ETwo |
| 230 | ret 3 |
| 231 | end |
| 232 | put Rt0 0 o |
| 233 | put Rtn 0 n |
| 234 | ret 0 |
| 235 | end |
| 236 | |
| 237 | fn argto i ulong to ulong |
| 238 | if ge i ulong argcnt |
| 239 | eputs EBadL |
| 240 | ret 3 |
| 241 | end |
| 242 | ok = argpl i |
| 243 | o = get Ps0 0 |
| 244 | n = get Psn 0 |
| 245 | put Lg 0 langname o n |
| 246 | if eq get Lg 0 0 |
| 247 | eputs EBadL |
| 248 | eputpl o n |
| 249 | ret 3 |
| 250 | end |
| 251 | ret 1000 |
| 252 | end |
| 253 | |
| 254 | fn argad i ulong to ulong |
| 255 | if ge i ulong argcnt |
| 256 | eputs ENoA |
| 257 | ret 3 |
| 258 | end |
| 259 | ok = argpl i |
| 260 | put Ad0 0 get Ps0 0 |
| 261 | put Adn 0 get Psn 0 |
| 262 | ret 1000 |
| 263 | end |
| 264 | |
| 265 | fn argex i ulong to ulong |
| 266 | if ge i ulong argcnt |
| 267 | eputs ENoEx |
| 268 | ret 3 |
| 269 | end |
| 270 | ok = argpl i |
| 271 | put Ex0 0 get Ps0 0 |
| 272 | put Exn 0 get Psn 0 |
| 273 | ret 1000 |
| 274 | end |
| 275 | |
| 276 | note a terminal: character device (st_mode byte 17) whose st_rdev major (bytes 32..33, |
| 277 | note bits 8..19) is 4 (tty), 5 (/dev/tty, ptmx) or 136..143 (pts); /dev/null (major 1) is not |
| 278 | fn istty fd int to bool |
| 279 | r = fstat fd Sb 0 128 |
| 280 | if lt r 0 |
| 281 | ret false |
| 282 | end |
| 283 | if ne and get Sb 17 240 32 |
| 284 | ret false |
| 285 | end |
| 286 | mj = or ulong get Sb 33 shl and ulong get Sb 34 15 8 |
| 287 | if eq mj 4 |
| 288 | ret true |
| 289 | end |
| 290 | if eq mj 5 |
| 291 | ret true |
| 292 | end |
| 293 | ret and ge mj 136 le mj 143 |
| 294 | end |
| 295 | |
| 296 | note interactive target picker on stdin/stderr |
| 297 | fn picker to ulong |
| 298 | m = mark |
| 299 | bs PkPick1 |
| 300 | bpl get Rt0 0 get Rtn 0 |
| 301 | bs PkPick2 |
| 302 | flush 2 m |
| 303 | r = read 0 Ln 0 len Ln |
| 304 | if le r 0 |
| 305 | ret 0 |
| 306 | end |
| 307 | n = ulong r |
| 308 | while gt n 0 bound 64 |
| 309 | c = get Ln sub n 1 |
| 310 | if gt c 32 |
| 311 | break |
| 312 | end |
| 313 | n = sub n 1 |
| 314 | end |
| 315 | if eq n 1 |
| 316 | d = get Ln 0 |
| 317 | if ge d 49 |
| 318 | if le d 54 |
| 319 | ret pickn sub d 48 |
| 320 | end |
| 321 | end |
| 322 | end |
| 323 | m = mark |
| 324 | for j ulong n |
| 325 | bc get Ln j |
| 326 | end |
| 327 | p = psave m n |
| 328 | reset m |
| 329 | ret langname p n |
| 330 | end |
| 331 | |
| 332 | fn pickn d uchar to ulong |
| 333 | if eq d 1 |
| 334 | ret 2 |
| 335 | end |
| 336 | if eq d 2 |
| 337 | ret 1 |
| 338 | end |
| 339 | if eq d 3 |
| 340 | ret 3 |
| 341 | end |
| 342 | if eq d 4 |
| 343 | ret 6 |
| 344 | end |
| 345 | if eq d 5 |
| 346 | ret 5 |
| 347 | end |
| 348 | ret 4 |
| 349 | end |
| 350 | |
| 351 | note absolute input path (cwd joined, "./" and trailing "/" removed) back into Rt0/Rtn |
| 352 | fn absin to void |
| 353 | m = mark |
| 354 | absob get Rt0 0 get Rtn 0 |
| 355 | while gt sub mark m 1 bound 4096 |
| 356 | if ne get Ob sub mark 1 47 |
| 357 | break |
| 358 | end |
| 359 | put Ol 0 sub mark 1 |
| 360 | end |
| 361 | put Rt0 0 psave m sub mark m |
| 362 | put Rtn 0 sub mark m |
| 363 | reset m |
| 364 | end |
| 365 | |
| 366 | note append the absolute form of the path Pl[o, o+n) to Ob: cwd joined, leading "./" removed |
| 367 | fn absob o ulong n ulong to void |
| 368 | if eq get Pl o 47 |
| 369 | bpl o n |
| 370 | ret |
| 371 | end |
| 372 | r = cwd Ag 0 len Ag |
| 373 | if gt r 1 |
| 374 | for j ulong sub ulong r 1 |
| 375 | bc get Ag j |
| 376 | end |
| 377 | end |
| 378 | k = ulong 0 |
| 379 | while lt add k 1 n bound 4096 |
| 380 | if ne get Pl add o k 46 |
| 381 | break |
| 382 | end |
| 383 | if ne get Pl add o add k 1 47 |
| 384 | break |
| 385 | end |
| 386 | k = add k 2 |
| 387 | end |
| 388 | if lt k n |
| 389 | bc 47 |
| 390 | bpl add o k sub n k |
| 391 | end |
| 392 | end |
| 393 | |
| 394 | note package name from the input's last path component: [a-z0-9_], not starting with a digit |
| 395 | fn pkgname to void |
| 396 | o = get Rt0 0 |
| 397 | n = get Rtn 0 |
| 398 | s = o |
| 399 | for i ulong n |
| 400 | if eq get Pl add o i 47 |
| 401 | s = add add o i 1 |
| 402 | end |
| 403 | end |
| 404 | k = sub add o n s |
| 405 | m = mark |
| 406 | for i ulong k |
| 407 | c = get Pl add s i |
| 408 | if ge c 65 |
| 409 | if le c 90 |
| 410 | c = add c 32 |
| 411 | end |
| 412 | end |
| 413 | bc pkc c |
| 414 | end |
| 415 | if gt sub mark m 0 |
| 416 | if lt get Ob m 58 |
| 417 | put Ol 0 m |
| 418 | bs PkgP |
| 419 | bpkc s k |
| 420 | end |
| 421 | end |
| 422 | if eq sub mark m 0 |
| 423 | bs PkgDef |
| 424 | end |
| 425 | put Pg0 0 psave m sub mark m |
| 426 | put Pgn 0 sub mark m |
| 427 | reset m |
| 428 | end |
| 429 | |
| 430 | fn bpkc s ulong k ulong to void |
| 431 | for i ulong k |
| 432 | c = get Pl add s i |
| 433 | if ge c 65 |
| 434 | if le c 90 |
| 435 | c = add c 32 |
| 436 | end |
| 437 | end |
| 438 | bc pkc c |
| 439 | end |
| 440 | end |
| 441 | |
| 442 | fn pkc c uchar to uchar |
| 443 | if ge c 97 |
| 444 | if le c 122 |
| 445 | ret c |
| 446 | end |
| 447 | end |
| 448 | if ge c 48 |
| 449 | if le c 57 |
| 450 | ret c |
| 451 | end |
| 452 | end |
| 453 | ret 95 |
| 454 | end |
| 455 | |
| 456 | note the output folder <input>.babel and its fixed subfolders |
| 457 | fn outdirs to bool |
| 458 | m = mark |
| 459 | bpl get Rt0 0 get Rtn 0 |
| 460 | bs BabExt |
| 461 | put Ot0 0 psave m sub mark m |
| 462 | put Otn 0 sub mark m |
| 463 | e = mark |
| 464 | r = mkdirs m e |
| 465 | reset m |
| 466 | if lt r 0 |
| 467 | m = mark |
| 468 | bs EOut |
| 469 | bout |
| 470 | bc 10 |
| 471 | flush 2 m |
| 472 | ret false |
| 473 | end |
| 474 | clean DInput |
| 475 | clean DOm |
| 476 | clean DDiff |
| 477 | clean DWk |
| 478 | m = mark |
| 479 | bout |
| 480 | bc 47 |
| 481 | blang get Lg 0 |
| 482 | e = mark |
| 483 | r = rmtree m e |
| 484 | reset m |
| 485 | mkout DOm |
| 486 | mkout DDiff |
| 487 | mkout DWk |
| 488 | g = get Lg 0 |
| 489 | if eq g 2 |
| 490 | mkout DRsU |
| 491 | mkout DRsB |
| 492 | mkout DRsT |
| 493 | end |
| 494 | if eq g 3 |
| 495 | m = mark |
| 496 | bouts DPyR |
| 497 | bc 47 |
| 498 | bpl get Pg0 0 get Pgn 0 |
| 499 | bs DUnits |
| 500 | e = mark |
| 501 | q = mkdirs m e |
| 502 | reset m |
| 503 | end |
| 504 | if eq g 1 |
| 505 | mkout DCU |
| 506 | end |
| 507 | if eq g 6 |
| 508 | mkout DCpU |
| 509 | mkout DCpD |
| 510 | end |
| 511 | if eq g 5 |
| 512 | mkout DZU |
| 513 | end |
| 514 | if eq g 4 |
| 515 | mkout DGo |
| 516 | end |
| 517 | ret true |
| 518 | end |
| 519 | |
| 520 | fn clean s view uchar * to void |
| 521 | m = mark |
| 522 | bouts s |
| 523 | e = mark |
| 524 | r = rmtree m e |
| 525 | reset m |
| 526 | end |
| 527 | |
| 528 | note absolute adapters path; HEAD sha and ref of the adapters checkout |
| 529 | fn adhead to void |
| 530 | m = mark |
| 531 | bpl get Ad0 0 get Adn 0 |
| 532 | bs GitHead |
| 533 | e = mark |
| 534 | r = rfile m e |
| 535 | reset m |
| 536 | if le r 0 |
| 537 | ret |
| 538 | end |
| 539 | n = ulong r |
| 540 | while gt n 0 bound 4096 |
| 541 | if gt get Fb sub n 1 32 |
| 542 | break |
| 543 | end |
| 544 | n = sub n 1 |
| 545 | end |
| 546 | if lt n len RefPfx |
| 547 | ret |
| 548 | end |
| 549 | if fbteq 0 len RefPfx RefPfx |
| 550 | k = len RefPfx |
| 551 | bfb k sub n k |
| 552 | put Ar0 0 psave m sub n k |
| 553 | put Arn 0 sub n k |
| 554 | reset m |
| 555 | bpl get Ad0 0 get Adn 0 |
| 556 | bs GitDir |
| 557 | bpl get Ar0 0 get Arn 0 |
| 558 | e = mark |
| 559 | r = rfile m e |
| 560 | reset m |
| 561 | if le r 0 |
| 562 | ret |
| 563 | end |
| 564 | n = ulong r |
| 565 | while gt n 0 bound 4096 |
| 566 | if gt get Fb sub n 1 32 |
| 567 | break |
| 568 | end |
| 569 | n = sub n 1 |
| 570 | end |
| 571 | end |
| 572 | bfb 0 n |
| 573 | put Ah0 0 psave m n |
| 574 | put Ahn 0 n |
| 575 | reset m |
| 576 | end |
| 577 | |
| 578 | note the adapters' native omc must hash to OmcPin |
| 579 | fn pincheck to bool |
| 580 | m = mark |
| 581 | bomc |
| 582 | e = mark |
| 583 | r = hfile m e |
| 584 | if lt r 0 |
| 585 | reset m |
| 586 | ret false |
| 587 | end |
| 588 | h = mark |
| 589 | bhash |
| 590 | ok = obteq h sub mark h OmcPin |
| 591 | reset m |
| 592 | ret ok |
| 593 | end |
| 594 | |
| 595 | note copy every walked file into input/, hashing it; split C files into units |
| 596 | fn ingest to void |
| 597 | for f ulong get Nf 0 |
| 598 | ingest1 f |
| 599 | end |
| 600 | end |
| 601 | |
| 602 | fn ingest1 f ulong to void |
| 603 | m = mark |
| 604 | bpl get Rd0 0 get Rdn 0 |
| 605 | if gt get Rdn 0 0 |
| 606 | bc 47 |
| 607 | end |
| 608 | bpl get F0 f get Fl f |
| 609 | a = mark |
| 610 | bouts DInput |
| 611 | bc 47 |
| 612 | bpl get F0 f get Fl f |
| 613 | b = mark |
| 614 | k = b |
| 615 | while gt k a bound 4096 |
| 616 | k = sub k 1 |
| 617 | if eq get Ob k 47 |
| 618 | break |
| 619 | end |
| 620 | end |
| 621 | q = mkdirs a k |
| 622 | r = cphash m a a b |
| 623 | reset m |
| 624 | if lt r 0 |
| 625 | put Fsz f 0 |
| 626 | put Fh0 f ptext Zero64 |
| 627 | u = newunit f 5 1 1 |
| 628 | put Ust u 4 |
| 629 | ureason u RsRead |
| 630 | ret |
| 631 | end |
| 632 | put Fsz f ulong r |
| 633 | h = mark |
| 634 | bhash |
| 635 | put Fh0 f psave h 64 |
| 636 | reset h |
| 637 | split1 f |
| 638 | end |
| 639 | |
| 640 | |
| 641 | fn split1 f ulong to void |
| 642 | g = get Flg f |
| 643 | if eq g 0 |
| 644 | ret |
| 645 | end |
| 646 | if ne g 1 |
| 647 | langunit f g |
| 648 | ret |
| 649 | end |
| 650 | if gt get Fsz f len Fb |
| 651 | u = newunit f 5 1 1 |
| 652 | put Ust u 3 |
| 653 | ureason u RsBig |
| 654 | ret |
| 655 | end |
| 656 | m = mark |
| 657 | bpl get Rd0 0 get Rdn 0 |
| 658 | if gt get Rdn 0 0 |
| 659 | bc 47 |
| 660 | end |
| 661 | bpl get F0 f get Fl f |
| 662 | e = mark |
| 663 | r = rfile m e |
| 664 | reset m |
| 665 | if lt r 0 |
| 666 | u = newunit f 5 1 1 |
| 667 | put Ust u 4 |
| 668 | ureason u RsRead |
| 669 | ret |
| 670 | end |
| 671 | csplit f |
| 672 | end |
| 673 | |
| 674 | fn langunit f ulong g ulong to void |
| 675 | u = newunit f 5 1 1 |
| 676 | put Ust u 3 |
| 677 | m = mark |
| 678 | bs RsLang1 |
| 679 | blang g |
| 680 | bs RsLang2 |
| 681 | blang g |
| 682 | bs RsLang3 |
| 683 | blang g |
| 684 | bs RsLang4 |
| 685 | ureasob u m |
| 686 | end |
| 687 | |
| 688 | note generate the target project around the exported units |
| 689 | fn gentarget to void |
| 690 | if eq get Nid 0 0 |
| 691 | ret |
| 692 | end |
| 693 | g = get Lg 0 |
| 694 | if eq g 2 |
| 695 | genrust |
| 696 | end |
| 697 | if eq g 3 |
| 698 | genpy |
| 699 | end |
| 700 | if eq g 1 |
| 701 | genc |
| 702 | end |
| 703 | if eq g 6 |
| 704 | gencpp |
| 705 | end |
| 706 | if eq g 5 |
| 707 | genzig |
| 708 | end |
| 709 | if eq g 4 |
| 710 | gengo |
| 711 | end |
| 712 | end |
| 713 | |
| 714 | fn anyfail to bool |
| 715 | for u ulong get Nu 0 |
| 716 | if eq get Ust u 4 |
| 717 | ret true |
| 718 | end |
| 719 | end |
| 720 | t = get Tsr 0 |
| 721 | if eq t 0 |
| 722 | ret false |
| 723 | end |
| 724 | ret ne t 999 |
| 725 | end |
| 726 | |
| 727 | note the walked root: the input folder, or the parent of a single input file |
| 728 | fn roots to bool |
| 729 | m = mark |
| 730 | bpl get Rt0 0 get Rtn 0 |
| 731 | e = mark |
| 732 | t = ftype m e |
| 733 | if eq t 2 |
| 734 | put Rd0 0 get Rt0 0 |
| 735 | put Rdn 0 get Rtn 0 |
| 736 | c = mark |
| 737 | walk m e c c 0 |
| 738 | reset m |
| 739 | ret true |
| 740 | end |
| 741 | reset m |
| 742 | if ne t 1 |
| 743 | ret false |
| 744 | end |
| 745 | o = get Rt0 0 |
| 746 | n = get Rtn 0 |
| 747 | k = n |
| 748 | while gt k 0 bound 4096 |
| 749 | k = sub k 1 |
| 750 | if eq get Pl add o k 47 |
| 751 | break |
| 752 | end |
| 753 | end |
| 754 | put Rd0 0 o |
| 755 | put Rdn 0 k |
| 756 | m = mark |
| 757 | bpl add o add k 1 sub sub n k 1 |
| 758 | e = mark |
| 759 | addfile m e |
| 760 | reset m |
| 761 | ret true |
| 762 | end |
| 763 | |
| 764 | fn main to int |
| 765 | envinit |
| 766 | put Rtn 0 0 |
| 767 | r = args |
| 768 | if ne r 0 |
| 769 | ret int sub r 1 |
| 770 | end |
| 771 | if eq get Rtn 0 0 |
| 772 | eputs ENoP |
| 773 | ret 2 |
| 774 | end |
| 775 | if eq get Adn 0 0 |
| 776 | if getenv EvAd |
| 777 | put Ad0 0 get Gv0 0 |
| 778 | put Adn 0 get Gvn 0 |
| 779 | end |
| 780 | end |
| 781 | if eq get Adn 0 0 |
| 782 | eputs ENoA |
| 783 | ret 2 |
| 784 | end |
| 785 | absin |
| 786 | if eq get Lg 0 0 |
| 787 | if not istty 0 |
| 788 | eputs ENoTty |
| 789 | ret 64 |
| 790 | end |
| 791 | put Lg 0 picker |
| 792 | if eq get Lg 0 0 |
| 793 | eputs EBadL |
| 794 | ret 2 |
| 795 | end |
| 796 | end |
| 797 | ret int brun |
| 798 | end |
| 799 | |
| 800 | fn brun to ulong |
| 801 | put Col 0 0 |
| 802 | if eq get Jsn 0 0 |
| 803 | if istty 1 |
| 804 | put Col 0 1 |
| 805 | end |
| 806 | if istty 2 |
| 807 | put Tty 0 1 |
| 808 | end |
| 809 | end |
| 810 | if eq get Nocol 0 1 |
| 811 | put Col 0 0 |
| 812 | end |
| 813 | if getenv EvNoc |
| 814 | put Col 0 0 |
| 815 | end |
| 816 | if not pincheck |
| 817 | m = mark |
| 818 | bs EPin1 |
| 819 | bomc |
| 820 | flush 2 m |
| 821 | eputs EPin2 |
| 822 | ret 2 |
| 823 | end |
| 824 | pkgname |
| 825 | if not roots |
| 826 | m = mark |
| 827 | bs ENoIn |
| 828 | bpl get Rt0 0 get Rtn 0 |
| 829 | bc 10 |
| 830 | flush 2 m |
| 831 | ret 2 |
| 832 | end |
| 833 | fsort |
| 834 | sksort |
| 835 | if not exload get Rd0 0 get Rdn 0 |
| 836 | ret 2 |
| 837 | end |
| 838 | if not outdirs |
| 839 | ret 2 |
| 840 | end |
| 841 | adhead |
| 842 | tools |
| 843 | ingest |
| 844 | pipeline |
| 845 | gentarget |
| 846 | difftest |
| 847 | progend |
| 848 | cwalk 0 |
| 849 | reports |
| 850 | if eq get Cap 0 1 |
| 851 | eputs ECap |
| 852 | end |
| 853 | if eq get Jsn 0 1 |
| 854 | jsonout |
| 855 | else |
| 856 | summary |
| 857 | end |
| 858 | if eq get Cpl 0 1 |
| 859 | ret cexit |
| 860 | end |
| 861 | if anyfail |
| 862 | ret 1 |
| 863 | end |
| 864 | ret 0 |
| 865 | end |