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/seed/modules/driver.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 / seed / modules / driver.om` 1437 lines ยท 28468 bytes Raw Blame History 1 note Native module driver. SHA256 compression supplied by seed/ng/sha256.om. 2 global mb uchar * 3 global mt ulong * 4 global ms ulong 8 5 global ma uchar 4096 6 global mp uchar 4096 7 global mx uchar 4096 8 global mh uchar 64 9 global mc uchar 64 10 global mz uchar 128 11 global mv uchar 512 12 global mw uchar 4 13 global mn uchar 128 14 global mm ulong * 15 global mg ulong 12 16 text mmagic "OMMOD001" 17 text omagic "OMOBJ001" 18 text err "ommod: refused (code below)\n" 19 text digits "`0123456789abcdef`" 20 text tpnames "bool uchar ushort uint ulong byte short int long f32 f64 void qty" 21 text objectline "object\n" 22 text omline "om2\n" 23 text relline "om2 release\n" 24 text extline "extern fn " 25 text toline " to " 26 text vwline " view " 27 text edline " edit " 28 text spline " " 29 text newln "\n" 30 text starline "*" 31 text paramline " p" 32 text tmptext ".ommod-" 33 text dotmod ".mod" 34 text dotref ".ref" 35 text dottext "." 36 text importnm "import" 37 text externnm "extern" 38 text modcmd "build" 39 text linkcmd "link" 40 text checkcmd "check" 41 text progcmd "program" 42 text funccmd "function" 43 text targetnm "aarch64-linux" 44 text debugnm "debug" 45 text releasenm "release" 46 text hittext "CACHE " 47 text builttext "BUILT " 48 note ms: byte used, table used, module count. mg: profile, root, import counter, cwd fd. 49 fn cell p ulong k ulong to ulong 50 ret get mt add p k 51 end 52 fn die code int to void 53 r = write 2 err 0 len err 54 put mw 0 uchar add 48 div code 10 55 put mw 1 uchar add 48 rem code 10 56 put mw 2 10 57 r = write 2 mw 0 3 58 exit code 59 end 60 fn need ok bool code int to void 61 if not ok 62 die code 63 end 64 end 65 note Length arithmetic is bounded by signed host address space, not an application quota. 66 fn sizeadd a ulong b ulong to ulong 67 need le a `9223372036854775807` 20 68 need le b sub `9223372036854775807` a 20 69 ret add a b 70 end 71 fn sizemul a ulong b ulong to ulong 72 if ne a 0 73 need le b div `9223372036854775807` a 20 74 end 75 ret mul a b 76 end 77 fn growto n ulong extra ulong limit ulong to ulong 78 need le n limit 20 79 if le extra sub limit n 80 ret add n extra 81 end 82 ret n 83 end 84 fn ba n ulong to ulong 85 p = get ms 0 86 need le n sub `9223372036854775807` p 20 87 q = add p n 88 if gt q len mb 89 r = enlarge mb growto q 4096 `9223372036854775807` 90 need ge r 0 21 91 end 92 put ms 0 q 93 ret p 94 end 95 fn ta n ulong to ulong 96 p = get ms 1 97 need le n sub `1152921504606846975` p 20 98 if gt add p n len mt 99 r = enlarge mt growto add p n 512 `1152921504606846975` 100 need ge r 0 21 101 end 102 put ms 1 add p n 103 ret p 104 end 105 fn rd p ulong lim ulong to ulong 106 need le p lim 22 107 need ge sub lim p 8 22 108 v = ulong 0 109 for j ulong 8 110 v = or v shl ulong get mb add p j mul j 8 111 end 112 ret v 113 end 114 fn wr p ulong v ulong to void 115 for j ulong 8 116 put mb add p j uchar and shr v mul j 8 255 117 end 118 end 119 fn word p ulong v ulong to void 120 for j ulong 4 121 put mb add p j uchar and shr v mul j 8 255 122 end 123 end 124 fn rw p ulong to ulong 125 v = ulong 0 126 for j ulong 4 127 v = or v shl ulong get mb add p j mul j 8 128 end 129 ret v 130 end 131 fn copy p ulong q ulong n ulong to void 132 for j ulong n bound `9223372036854775807` 133 put mb add p j get mb add q j 134 end 135 end 136 fn same p ulong q ulong n ulong to bool 137 for j ulong n bound `9223372036854775807` 138 if ne get mb add p j get mb add q j 139 ret false 140 end 141 end 142 ret true 143 end 144 fn lit p ulong n ulong txt view uchar * to bool 145 if ne n len txt 146 ret false 147 end 148 for j ulong n bound `9223372036854775807` 149 if ne get mb add p j get txt j 150 ret false 151 end 152 end 153 ret true 154 end 155 fn append txt view uchar * to ulong 156 p = ba len txt 157 for j ulong len txt bound `9223372036854775807` 158 put mb add p j get txt j 159 end 160 ret p 161 end 162 fn nmvalid p ulong n ulong to bool 163 if or eq n 0 gt n 63 164 ret false 165 end 166 for j ulong n bound 64 167 c = get mb add p j 168 if not or or and ge c 65 le c 90 and ge c 97 le c 122 eq c 95 169 if or eq j 0 not and ge c 48 le c 57 170 ret false 171 end 172 end 173 end 174 ret true 175 end 176 fn hxvalid p ulong to void 177 for j ulong 64 178 c = get mb add p j 179 need or and ge c 48 le c 57 and ge c 97 le c 102 23 180 end 181 end 182 fn hash p ulong n ulong to void 183 note SHA256 encodes message length in 64 bits, measured in bits. 184 need le n `2305843009213693951` 20 185 sh_init 186 for j ulong 8 187 put sh_h j get sh_k add j 64 188 end 189 nb = div n 64 190 for k ulong nb bound `9223372036854775807` 191 for j ulong 64 192 put sh_dat j get mb add add p mul k 64 j 193 end 194 sh_blk 0 0 195 end 196 for j ulong 128 197 put sh_pad j 0 198 end 199 r = rem n 64 200 for j ulong r bound 64 201 put sh_pad j get mb add add p mul nb 64 j 202 end 203 put sh_pad r 128 204 e = ulong 64 205 if ge r 56 206 e = 128 207 end 208 for j ulong 8 209 put sh_pad sub sub e 1 j uchar and shr mul n 8 mul j 8 255 210 end 211 sh_blk 1 0 212 if eq e 128 213 sh_blk 1 64 214 end 215 sh_out 216 for j ulong 32 217 v = uint get sh_dig j 218 put mh mul j 2 sh_hexd shr v 4 219 put mh add mul j 2 1 sh_hexd and v 15 220 end 221 end 222 fn hashis p ulong to void 223 for j ulong 64 224 need eq get mb add p j get mh j 24 225 end 226 end 227 fn hashput p ulong to void 228 for j ulong 64 229 put mb add p j get mh j 230 end 231 end 232 fn arg i ulong to ulong 233 n = argread i ma 0 4096 234 need and ge n 0 lt n 4096 10 235 p = ba ulong n 236 for j ulong ulong n bound 4096 237 put mb add p j get ma j 238 end 239 put mg 10 ulong n 240 ret p 241 end 242 fn path p ulong n ulong to void 243 need and gt n 0 lt n 4096 10 244 for j ulong n bound 4096 245 need ne get mb add p j 0 10 246 put mp j get mb add p j 247 end 248 end 249 note Walk every directory component with O_NOFOLLOW; cwd always restored by callers. 250 fn parent p ulong n ulong to ulong 251 path p n 252 s = ulong 0 253 if eq get mp 0 47 254 fd = fopen mp 0 1 49152 0 255 need ge fd 0 25 256 r = fchdir int fd 257 c = fclose int fd 258 need and eq r 0 eq c 0 25 259 s = 1 260 end 261 for i ulong n bound 4096 262 if and ge i s eq get mp i 47 263 if gt i s 264 fd = fopen mp s sub i s 49152 0 265 need ge fd 0 25 266 r = fchdir int fd 267 c = fclose int fd 268 need and eq r 0 eq c 0 25 269 end 270 s = add i 1 271 end 272 end 273 need lt s n 25 274 ret s 275 end 276 fn restore to void 277 r = fchdir int get mg 3 278 need eq r 0 25 279 end 280 note Open read-only regular file, no symbolic links in any component. Returns -2 for absent. 281 fn readpath p ulong n ulong to long 282 restore 283 s = parent p n 284 fd = fopen mp s sub n s 34816 0 285 restore 286 ret fd 287 end 288 fn load fd int to ulong 289 r = fstat fd mz 0 128 290 need eq r 0 26 291 mode = or ulong get mz 16 shl ulong get mz 17 8 292 need eq and mode 61440 32768 26 293 sz = ulong 0 294 for j ulong 8 295 sz = or sz shl ulong get mz add 48 j mul j 8 296 end 297 p = ba sz 298 k = ulong 0 299 while lt k sz bound `9223372036854775807` 300 r = read fd mb add p k sub sz k 301 need gt r 0 26 302 k = add k ulong r 303 end 304 r = read fd mw 0 1 305 need eq r 0 26 306 r = fclose fd 307 need eq r 0 26 308 put mg 10 sz 309 ret p 310 end 311 fn writeall fd int p ulong n ulong to void 312 k = ulong 0 313 while lt k n bound `9223372036854775807` 314 r = write fd mb add p k sub n k 315 need gt r 0 27 316 k = add k ulong r 317 end 318 end 319 note Module record: blob,size,source,size,object,size,imports,count,functions,count,calls,count, 320 note code end, output code base, digest, dependency traversal flag. 16 cells. 321 note Import record: alias pos,len,source hash,export pos,len,target function,module,expected digest. 322 fn uniqueimports m ulong to void 323 for i ulong cell m 7 bound `9223372036854775807` 324 a = add cell m 6 mul i 8 325 for j ulong i bound `9223372036854775807` 326 b = add cell m 6 mul j 8 327 if eq cell a 1 cell b 1 328 need not same get mt a get mt b cell a 1 28 329 end 330 end 331 end 332 end 333 fn parseline m ulong ls ulong lineend ulong to void 334 q = ls 335 while lt q lineend bound `9223372036854775807` 336 if ne get mb q 32 337 break 338 end 339 q = add q 1 340 end 341 w = q 342 while lt q lineend bound `9223372036854775807` 343 if eq get mb q 32 344 break 345 end 346 q = add q 1 347 end 348 need not lit w sub q w externnm 28 349 if lit w sub q w importnm 350 need lt q lineend 28 351 q = add q 1 352 a = q 353 while lt q lineend bound `9223372036854775807` 354 if eq get mb q 32 355 break 356 end 357 q = add q 1 358 end 359 need nmvalid a sub q a 28 360 need lt q lineend 28 361 h = add q 1 362 need ge sub lineend h 66 28 363 hxvalid h 364 need eq get mb add h 64 32 28 365 x = add h 65 366 need nmvalid x sub lineend x 28 367 ls = ta 8 368 put mt ls a 369 put mt add ls 1 sub q a 370 put mt add ls 2 h 371 put mt add ls 3 x 372 put mt add ls 4 sub lineend x 373 put mt add ls 5 0 374 put mt add ls 6 0 375 put mt add ls 7 0 376 put mt add m 7 add cell m 7 1 377 end 378 end 379 fn parse m ulong to void 380 s = cell m 2 381 e = add s cell m 3 382 p = s 383 while lt p e bound `9223372036854775807` 384 if eq get mb p 10 385 break 386 end 387 p = add p 1 388 end 389 need lt p e 28 390 if eq get mg 0 0 391 need lit s sub add p 1 s omline 28 392 else 393 need lit s sub add p 1 s relline 28 394 end 395 put mt add m 6 get ms 1 396 p = add p 1 397 while lt p e bound `9223372036854775807` 398 ls = p 399 while lt p e bound `9223372036854775807` 400 if eq get mb p 10 401 break 402 end 403 p = add p 1 404 end 405 lineend = p 406 if lt p e 407 p = add p 1 408 end 409 parseline m ls lineend 410 end 411 uniqueimports m 412 end 413 note Function record: flag,address,result,nparams,stack,name,len,params,module,resolved,state,need. 414 fn br s ulong d ulong op ulong to ulong 415 v = sub long d long s 416 need eq rem v 4 0 30 417 need and ge v -`134217728` lt v `134217728` 30 418 if lt v 0 419 v = add v `268435456` 420 end 421 ret or op div ulong v 4 422 end 423 fn func m ulong i ulong to ulong 424 need lt i cell m 9 31 425 ret add cell m 8 mul i 12 426 end 427 fn fend m ulong f ulong to ulong 428 last = cell m 12 429 for i ulong cell m 9 bound `9223372036854775807` 430 g = func m i 431 if ne get mt g 2 432 a = cell g 1 433 if and gt a cell f 1 lt a last 434 last = a 435 end 436 end 437 end 438 ret last 439 end 440 fn validateparam pp ulong e ulong flag ulong to ulong 441 ty = rd pp e 442 ki = rd add pp 8 e 443 sz = rd add pp 16 e 444 fr = rd add pp 32 e 445 need and ge ty 1 le ty 13 31 446 need ne ty 12 31 447 need or eq ki 0 or eq ki 2 eq ki 3 31 448 need and eq rd add pp 24 e 0 le fr 1 31 449 if eq ki 0 450 need and eq sz 0 eq fr 0 31 451 else 452 need le sz `16777216` 31 453 if ne fr 0 454 need and and eq ki 3 gt sz 0 ne flag 2 31 455 end 456 end 457 if and ne ki 0 eq sz 0 458 ret 2 459 end 460 ret 1 461 end 462 fn validatename m ulong f ulong i ulong to void 463 for j ulong i bound `9223372036854775807` 464 g = func m j 465 if eq cell f 6 cell g 6 466 need not same cell f 5 cell g 5 cell f 6 31 467 end 468 end 469 end 470 fn validateaddr m ulong f ulong to void 471 b = cell m 4 472 addr = cell f 1 473 if eq get mt f 2 474 need and eq addr 0 eq cell f 4 0 31 475 put mt add m 19 add cell m 19 1 476 else 477 need and ge addr 176 lt addr sub cell m 12 b 31 478 need eq rem addr 4 0 31 479 addr = add b addr 480 need ge addr cell m 17 31 481 if eq cell m 17 add add b 176 mul cell m 20 4 482 need eq addr cell m 17 31 483 end 484 put mt add f 1 addr 485 put mt add m 17 add addr 4 486 if eq get mt f 1 487 site = add add b 176 mul cell m 18 4 488 need eq rw site br site addr `335544320` 31 489 put mt add m 18 add cell m 18 1 490 end 491 end 492 end 493 fn validatefn m ulong i ulong to void 494 f = func m i 495 pos = cell m 16 496 e = add cell m 4 cell m 5 497 need le pos e 31 498 need ge sub e pos 48 31 499 for j ulong 6 500 put mt add f j rd add pos mul j 8 e 501 end 502 need le get mt f 2 31 503 need and ge cell f 2 1 le cell f 2 13 31 504 need le cell f 3 6 31 505 need le cell f 4 `8388608` 31 506 pos = add pos 48 507 nl = cell f 5 508 need le nl sub e pos 31 509 need nmvalid pos nl 31 510 put mt add f 5 pos 511 put mt add f 6 nl 512 put mt add f 8 m 513 put mt add f 9 f 514 validatename m f i 515 pos = add pos nl 516 while ne rem sub pos cell m 4 8 0 bound 8 517 need lt pos e 31 518 need eq get mb pos 0 31 519 pos = add pos 1 520 end 521 put mt add f 7 pos 522 need le cell f 3 div sub e pos 40 31 523 pc = ulong 0 524 for j ulong cell f 3 bound 6 525 pc = add pc validateparam add pos mul j 40 e get mt f 526 end 527 need le pc 6 31 528 put mt add m 16 add pos mul cell f 3 40 529 validateaddr m f 530 end 531 fn uniquecalls m ulong i ulong site ulong to void 532 for j ulong i bound `9223372036854775807` 533 need ne site get mt add cell m 10 mul j 4 32 534 end 535 end 536 fn validatecall m ulong i ulong to void 537 e = add cell m 4 cell m 5 538 p = add cell m 16 mul i 32 539 c = add cell m 10 mul i 4 540 site = rd p e 541 src = func m rd add p 8 e 542 dst = func m rd add p 16 e 543 need and ge site 176 lt site sub cell m 12 cell m 4 32 544 need eq rem site 4 0 32 545 site = add site cell m 4 546 need ne get mt src 2 32 547 need and ge site cell src 1 lt site fend m src 32 548 need le rd add p 24 e `8388608` 32 549 need eq rem rd add p 24 e 16 0 32 550 uniquecalls m i site 551 want = ulong `2483027968` 552 if ne get mt dst 2 553 want = br site cell dst 1 want 554 end 555 need eq rw site want 32 556 put mt c site 557 put mt add c 1 src 558 put mt add c 2 dst 559 put mt add c 3 rd add p 24 e 560 end 561 fn validatescan m ulong to void 562 p = add add cell m 4 176 mul cell m 20 4 563 while lt p cell m 12 bound `9223372036854775807` 564 if eq shr rw p 26 37 565 seen = ulong 0 566 for i ulong cell m 11 bound `9223372036854775807` 567 if eq p get mt add cell m 10 mul i 4 568 seen = add seen 1 569 end 570 end 571 need eq seen 1 32 572 end 573 p = add p 4 574 end 575 end 576 fn validate m ulong to void 577 b = cell m 4 578 n = cell m 5 579 e = add b n 580 need ge n 180 31 581 need lit b 8 omagic 31 582 need eq rd add b 8 e 1 31 583 need eq rd add b 16 e 1 31 584 need eq rd add b 24 e get mg 0 31 585 need eq rd add b 32 e 176 31 586 ce = rd add b 40 e 587 need and ge ce 180 le ce n 31 588 need eq rem ce 4 0 31 589 put mt add m 12 add b ce 590 nf = rd add b 48 e 591 nc = rd add b 56 e 592 nx = rd add b 64 e 593 need and gt nf 0 le nf div sub n ce 48 31 594 need le nc div sub n ce 32 31 595 need le nx nf 31 596 for j ulong 104 597 need eq get mb add add b 72 j 0 31 598 end 599 put mt add m 8 ta mul nf 12 600 put mt add m 9 nf 601 put mt add m 16 add b ce 602 put mt add m 20 nx 603 if eq nx 0 604 put mt add m 20 1 605 end 606 need le cell m 20 div sub ce 176 4 31 607 put mt add m 17 add add b 176 mul cell m 20 4 608 for i ulong nf bound `9223372036854775807` 609 validatefn m i 610 end 611 need eq nx cell m 18 31 612 need eq cell m 19 cell m 7 31 613 need eq mul nc 32 sub e cell m 16 31 614 put mt add m 10 ta mul nc 4 615 put mt add m 11 nc 616 for i ulong nc bound `9223372036854775807` 617 validatecall m i 618 end 619 validatescan m 620 end 621 fn signature a ulong b ulong to bool 622 if or ne cell a 2 cell b 2 ne cell a 3 cell b 3 623 ret false 624 end 625 ret same cell a 7 cell b 7 mul cell a 3 40 626 end 627 fn exported m ulong p ulong n ulong to ulong 628 for i ulong cell m 9 bound `9223372036854775807` 629 f = func m i 630 if and eq get mt f 1 eq cell f 6 n 631 if same p cell f 5 n 632 ret f 633 end 634 end 635 end 636 die 33 637 ret 0 638 end 639 fn newmod to ulong 640 m = ta 24 641 k = get ms 2 642 if ge k len mm 643 r = enlarge mm growto sizeadd k 1 127 `1152921504606846975` 644 need ge r 0 21 645 end 646 put mm k m 647 put ms 2 add k 1 648 ret m 649 end 650 note Store key hashes domain tag + compiler digest + source digest + profile + target. 651 fn key srchash ulong to void 652 p = ba 152 653 for j ulong 8 654 put mb add p j get mmagic j 655 end 656 for j ulong 64 657 put mb add add p 8 j get mc j 658 put mb add add p 72 j get mb add srchash j 659 end 660 wr add p 136 get mg 0 661 wr add p 144 1 662 hash p 152 663 for j ulong 64 664 put mp j get mh j 665 end 666 for j ulong 4 667 put mp add j 64 get dotref j 668 end 669 end 670 note Read and verify a complete cached artifact. Its source digest, compiler, profile and target 671 note are checked before metadata, and dependencies are verified before any executable is written. 672 fn decodeimports m ulong to void 673 dp = add cell m 4 cell m 5 674 for i ulong cell m 7 bound `9223372036854775807` 675 imp = add cell m 6 mul i 8 676 put mt add imp 7 add dp mul i 64 677 end 678 end 679 fn decode b ulong n ulong srchash ulong expected ulong to ulong 680 need ge n 176 34 681 hash b n 682 if ne expected 0 683 hashis expected 684 end 685 h = ba 64 686 hashput h 687 need lit b 8 mmagic 34 688 for j ulong 64 689 need eq get mb add add b 8 j get mc j 34 690 end 691 need same add b 72 srchash 64 34 692 need eq rd add b 136 add b n get mg 0 34 693 need eq rd add b 144 add b n 1 34 694 sn = rd add b 152 add b n 695 on = rd add b 160 add b n 696 dn = rd add b 168 add b n 697 need le sn sub n 176 34 698 need le on sub sub n 176 sn 34 699 need eq dn div sub sub sub n 176 sn on 64 34 700 need eq rem sub sub sub n 176 sn on 64 0 34 701 hash add b 176 sn 702 hashis add b 72 703 m = newmod 704 put mt m b 705 put mt add m 1 n 706 put mt add m 2 add b 176 707 put mt add m 3 sn 708 put mt add m 4 add add b 176 sn 709 put mt add m 5 on 710 put mt add m 14 h 711 parse m 712 need eq dn cell m 7 34 713 decodeimports m 714 validate m 715 ret m 716 end 717 fn reference srchash ulong to ulong 718 key srchash 719 r = fchdir int get mg 4 720 need eq r 0 25 721 fd = fopen mp 0 68 34816 0 722 restore 723 need ge fd 0 34 724 p = load int fd 725 need eq get mg 10 64 34 726 hxvalid p 727 ret p 728 end 729 fn cached srchash ulong expected ulong to ulong 730 for k ulong get ms 2 bound `9223372036854775807` 731 m = get mm k 732 if ne get mt m 0 733 if same add get mt m 72 srchash 64 734 if ne expected 0 735 need same cell m 14 expected 64 24 736 end 737 ret m 738 end 739 end 740 end 741 h = reference srchash 742 if ne expected 0 743 need same h expected 64 24 744 end 745 for j ulong 64 746 put mp j get mb add h j 747 end 748 for j ulong 4 749 put mp add j 64 get dotmod j 750 end 751 r = fchdir int get mg 4 752 need eq r 0 25 753 fd = fopen mp 0 68 34816 0 754 restore 755 need ge fd 0 34 756 b = load int fd 757 ret decode b get mg 10 srchash h 758 end 759 760 fn resolveone m ulong i ulong to void 761 imp = add cell m 6 mul i 8 762 i = cached cell imp 2 cell imp 7 763 put mt add imp 5 exported i cell imp 3 cell imp 4 764 put mt add imp 6 i 765 found = ulong 0 766 for j ulong cell m 9 bound `9223372036854775807` 767 g = func m j 768 if and eq get mt g 2 eq cell g 6 cell imp 1 769 if same cell g 5 get mt imp cell imp 1 770 need signature cell imp 5 g 35 771 put mt add g 9 cell imp 5 772 found = add found 1 773 end 774 end 775 end 776 need eq found 1 35 777 end 778 fn resolveall to void 779 k = ulong 0 780 while lt k get ms 2 bound `9223372036854775807` 781 m = get mm k 782 for i ulong cell m 7 bound `9223372036854775807` 783 resolveone m i 784 end 785 k = add k 1 786 end 787 end 788 note Iterative DAG check over module dependencies, including unused imports. 789 fn modready m ulong to bool 790 for i ulong cell m 7 bound `9223372036854775807` 791 imp = add cell m 6 mul i 8 792 d = cell imp 6 793 if eq cell d 15 0 794 ret false 795 end 796 end 797 ret true 798 end 799 fn stepmods to ulong 800 count = ulong 0 801 for k ulong get ms 2 bound `9223372036854775807` 802 m = get mm k 803 if eq cell m 15 0 804 if modready m 805 put mt add m 15 1 806 count = add count 1 807 end 808 end 809 end 810 ret count 811 end 812 fn fnready m ulong f ulong to bool 813 cost = cell f 4 814 for i ulong cell m 11 bound `9223372036854775807` 815 c = add cell m 10 mul i 4 816 if eq cell c 1 f 817 g = cell cell c 2 9 818 if eq cell g 10 0 819 ret false 820 end 821 v = add cell c 3 cell g 11 822 if gt v cost 823 cost = v 824 end 825 end 826 end 827 need le cost `8388608` 37 828 put mt add f 11 cost 829 put mt add f 10 1 830 ret true 831 end 832 fn stepfuncs countonly bool to ulong 833 count = ulong 0 834 for k ulong get ms 2 bound `9223372036854775807` 835 m = get mm k 836 for j ulong cell m 9 bound `9223372036854775807` 837 f = func m j 838 if ne get mt f 2 839 if eq cell f 10 0 840 if countonly 841 count = add count 1 842 else 843 if fnready m f 844 count = add count 1 845 end 846 end 847 end 848 end 849 end 850 end 851 ret count 852 end 853 fn graph to void 854 left = get ms 2 855 while gt left 0 bound `9223372036854775807` 856 progress = stepmods 857 need gt progress 0 36 858 left = sub left progress 859 end 860 left = stepfuncs true 861 while gt left 0 bound `9223372036854775807` 862 progress = stepfuncs false 863 need gt progress 0 36 864 left = sub left progress 865 end 866 end 867 fn decimal x ulong to void 868 q = x 869 start = ulong 24 870 while true bound 24 871 start = sub start 1 872 put mn start uchar add rem q 10 48 873 q = div q 10 874 if eq q 0 875 break 876 end 877 end 878 p = ba sub 24 start 879 for j ulong sub 24 start bound 24 880 put mb add p j get mn add start j 881 end 882 end 883 fn typename ty ulong to void 884 p = ulong 0 885 idx = ulong 1 886 for j ulong len tpnames 887 if eq get tpnames j 32 888 if eq idx ty 889 r = append part tpnames p sub j p 890 ret 891 end 892 p = add j 1 893 idx = add idx 1 894 end 895 end 896 need eq ty 13 31 897 r = append part tpnames p sub len tpnames p 898 end 899 fn externs m ulong to void 900 for i ulong cell m 7 bound `9223372036854775807` 901 imp = add cell m 6 mul i 8 902 f = cell imp 5 903 r = append extline 904 p = ba cell imp 1 905 copy p get mt imp cell imp 1 906 for j ulong cell f 3 bound 6 907 pp = add cell f 7 mul j 40 908 e = get ms 0 909 r = append paramline 910 decimal j 911 ki = rd add pp 8 e 912 if eq ki 0 913 r = append spline 914 else 915 if eq ki 2 916 r = append vwline 917 else 918 r = append edline 919 end 920 end 921 typename rd pp e 922 if ne ki 0 923 r = append spline 924 sz = rd add pp 16 e 925 if eq sz 0 926 r = append starline 927 else 928 decimal sz 929 end 930 end 931 need eq rd add pp 32 e 0 35 932 end 933 r = append toline 934 typename cell f 2 935 r = append newln 936 end 937 end 938 fn copyline ls ulong p ulong to void 939 q = ls 940 while lt q p bound `9223372036854775807` 941 if ne get mb q 32 942 break 943 end 944 q = add q 1 945 end 946 w = q 947 while lt q p bound `9223372036854775807` 948 if or eq get mb q 32 eq get mb q 10 949 break 950 end 951 q = add q 1 952 end 953 if not lit w sub q w importnm 954 r = ba sub p ls 955 copy r ls sub p ls 956 end 957 end 958 fn compiletext m ulong to ulong 959 start = get ms 0 960 r = append objectline 961 if eq get mg 0 0 962 r = append omline 963 else 964 r = append relline 965 end 966 externs m 967 p = cell m 2 968 e = add p cell m 3 969 while lt p e bound `9223372036854775807` 970 if eq get mb p 10 971 p = add p 1 972 break 973 end 974 p = add p 1 975 end 976 while lt p e bound `9223372036854775807` 977 ls = p 978 while lt p e bound `9223372036854775807` 979 if eq get mb p 10 980 p = add p 1 981 break 982 end 983 p = add p 1 984 end 985 copyline ls p 986 end 987 ret start 988 end 989 note Unique temporary name in mx; O_EXCL is still mandatory, so collisions refuse safely. 990 fn tempname to void 991 r = random mn 0 16 0 992 need eq r 16 27 993 for j ulong 7 994 put mx j get tmptext j 995 end 996 for j ulong 16 997 b = uint get mn j 998 put mx add 7 mul j 2 sh_hexd shr b 4 999 put mx add 8 mul j 2 sh_hexd and b 15 1000 end 1001 end 1002 fn tempfile p ulong n ulong mode int to long 1003 tempname 1004 fd = fopen mx 0 39 32961 mode 1005 need ge fd 0 27 1006 writeall int fd p n 1007 r = fsync int fd 1008 need eq r 0 27 1009 r = fclose int fd 1010 need eq r 0 27 1011 ret 0 1012 end 1013 fn packet to ulong 1014 put mv 0 1 1015 put mv 1 0 1016 put mv 2 39 1017 put mv 3 0 1018 for j ulong 39 1019 put mv add 4 j get mx j 1020 end 1021 ret 43 1022 end 1023 fn compiler cp ulong cn ulong textpos ulong textlen ulong to ulong 1024 r = fchdir int get mg 4 1025 need eq r 0 25 1026 r = tempfile cp cn 448 1027 pn = packet 1028 fi = memfd tmptext 0 7 0 1029 fo = memfd tmptext 0 7 0 1030 need and ge fi 0 ge fo 0 27 1031 writeall int fi textpos textlen 1032 r = fseek int fi 0 0 1033 need eq r 0 27 1034 pid = fork 1035 need ge pid 0 27 1036 if eq pid 0 1037 r = dupfd int fi 0 0 1038 if ne r 0 1039 exit 127 1040 end 1041 r = dupfd int fo 1 0 1042 if ne r 1 1043 exit 127 1044 end 1045 r = execprog mv 0 pn 1046 exit 127 1047 end 1048 r = waitpid int pid mw 0 4 0 1049 need eq r pid 27 1050 r = unlink mx 0 39 1051 need eq r 0 27 1052 need and eq get mw 0 0 eq get mw 1 0 39 1053 r = fclose int fi 1054 need eq r 0 27 1055 r = fseek int fo 0 0 1056 need eq r 0 27 1057 cp = load int fo 1058 restore 1059 ret cp 1060 end 1061 note Atomic no-replace publication. Caller has selected a safe parent directory. 1062 fn publish p ulong n ulong dest ulong dn ulong mode int to void 1063 path dest dn 1064 for j ulong dn bound 4096 1065 put ma j get mp j 1066 end 1067 r = tempfile p n mode 1068 put mv 0 2 1069 put mv 1 0 1070 put mv 2 39 1071 put mv 3 0 1072 for j ulong 39 1073 put mv add 4 j get mx j 1074 end 1075 need le dn 255 25 1076 put mv 43 uchar dn 1077 put mv 44 0 1078 for j ulong dn bound 255 1079 put mv add 45 j get ma j 1080 end 1081 r = renames mv 0 add 45 dn 1 1082 if ne r 0 1083 x = unlink mx 0 39 1084 die 38 1085 end 1086 r = fopen dottext 0 1 16384 0 1087 need ge r 0 27 1088 x = fsync int r 1089 y = fclose int r 1090 need and eq x 0 eq y 0 27 1091 end 1092 fn builddeps m ulong to void 1093 for i ulong cell m 7 bound `9223372036854775807` 1094 imp = add cell m 6 mul i 8 1095 d = cached cell imp 2 0 1096 put mt add imp 6 d 1097 put mt add imp 5 exported d cell imp 3 cell imp 4 1098 end 1099 end 1100 fn compilemod cp ulong cn ulong m ulong to void 1101 src = compiletext m 1102 sz = sub get ms 0 src 1103 op = compiler cp cn src sz 1104 on = get mg 10 1105 put mt add m 4 op 1106 put mt add m 5 on 1107 end 1108 fn ensureblob m ulong name ulong to void 1109 path name 68 1110 fd = fopen mp 0 68 34816 0 1111 if ge fd 0 1112 p = load int fd 1113 need eq get mg 10 cell m 1 24 1114 hash p get mg 10 1115 hashis cell m 14 1116 ret 1117 end 1118 need eq fd -2 34 1119 publish get mt m cell m 1 name 68 292 1120 end 1121 fn publishstore m ulong sh ulong to void 1122 h = cell m 14 1123 name = ba 68 1124 copy name h 64 1125 for j ulong 4 1126 put mb add add name 64 j get dotmod j 1127 end 1128 r = fchdir int get mg 4 1129 need eq r 0 25 1130 ensureblob m name 1131 key sh 1132 for j ulong 68 1133 put mb add name j get mp j 1134 end 1135 publish h 64 name 68 292 1136 end 1137 fn package m ulong sh ulong to ulong 1138 b = ba sizeadd sizeadd sizeadd 176 cell m 3 cell m 5 sizemul cell m 7 64 1139 for j ulong 8 1140 put mb add b j get mmagic j 1141 end 1142 for j ulong 64 1143 put mb add add b 8 j get mc j 1144 end 1145 copy add b 72 sh 64 1146 wr add b 136 get mg 0 1147 wr add b 144 1 1148 wr add b 152 cell m 3 1149 wr add b 160 cell m 5 1150 wr add b 168 cell m 7 1151 copy add b 176 cell m 2 cell m 3 1152 copy add add b 176 cell m 3 cell m 4 cell m 5 1153 dp = add add add b 176 cell m 3 cell m 5 1154 for i ulong cell m 7 bound `9223372036854775807` 1155 imp = add cell m 6 mul i 8 1156 d = cell imp 6 1157 copy add dp mul i 64 cell d 14 64 1158 end 1159 n = sub get ms 0 b 1160 hash b n 1161 h = ba 64 1162 hashput h 1163 put mt m b 1164 put mt add m 1 n 1165 put mt add m 14 h 1166 publishstore m sh 1167 restore 1168 r = write 1 builttext 0 len builttext 1169 ret m 1170 end 1171 fn cachehit sh ulong to ulong 1172 key sh 1173 r = fchdir int get mg 4 1174 need eq r 0 25 1175 fd = fopen mp 0 68 34816 0 1176 restore 1177 if ge fd 0 1178 r = fclose int fd 1179 need eq r 0 26 1180 m = cached sh 0 1181 resolveall 1182 graph 1183 r = write 1 hittext 0 len hittext 1184 ret m 1185 end 1186 need eq fd -2 34 1187 ret 0 1188 end 1189 fn build cp ulong cn ulong sp ulong sn ulong sh ulong to ulong 1190 m = cachehit sh 1191 if ne m 0 1192 ret m 1193 end 1194 m = newmod 1195 put mt add m 2 sp 1196 put mt add m 3 sn 1197 parse m 1198 builddeps m 1199 compilemod cp cn m 1200 validate m 1201 resolveall 1202 graph 1203 ret package m sh 1204 end 1205 text abimagic "OMLINK01" 1206 fn placed f ulong to ulong 1207 m = cell f 8 1208 ret add cell m 13 sub cell f 1 add cell m 4 176 1209 end 1210 fn descriptor root ulong start ulong to void 1211 p = ba 8 1212 count = ulong 0 1213 for j ulong cell root 9 bound `9223372036854775807` 1214 f = func root j 1215 if eq get mt f 1 1216 count = add count 1 1217 end 1218 end 1219 wr p count 1220 for j ulong cell root 9 bound `9223372036854775807` 1221 f = func root j 1222 if eq get mt f 1 1223 q = ba 40 1224 wr q sub placed f start 1225 wr add q 8 cell f 11 1226 wr add q 16 cell f 2 1227 wr add q 24 cell f 3 1228 wr add q 32 cell f 6 1229 q = ba cell f 6 1230 copy q cell f 5 cell f 6 1231 q = ba mul cell f 3 40 1232 copy q cell f 7 mul cell f 3 40 1233 end 1234 end 1235 q = ba 8 1236 wr q sub q p 1237 q = append abimagic 1238 end 1239 fn relocate m ulong i ulong to void 1240 c = add cell m 10 mul i 4 1241 site = add cell m 13 sub get mt c add cell m 4 176 1242 f = get mt add cell c 2 9 1243 word site br site placed f `2483027968` 1244 end 1245 fn placemodules to void 1246 for k ulong get ms 2 bound `9223372036854775807` 1247 m = get mm k 1248 n = sub cell m 12 add cell m 4 176 1249 q = ba n 1250 put mt add m 13 q 1251 copy q add cell m 4 176 n 1252 end 1253 for k ulong get ms 2 bound `9223372036854775807` 1254 m = get mm k 1255 for i ulong cell m 11 bound `9223372036854775807` 1256 relocate m i 1257 end 1258 end 1259 end 1260 fn programwrap start ulong entry ulong to void 1261 word start `1179403647` 1262 word add start 4 65794 1263 word add start 16 `11993090` 1264 word add start 20 1 1265 wr add start 24 `4194480` 1266 wr add start 32 64 1267 word add start 52 `3670080` 1268 word add start 56 2 1269 word add start 64 1 1270 word add start 68 5 1271 wr add start 80 `4194304` 1272 wr add start 88 `4194304` 1273 wr add start 96 sub get ms 0 start 1274 wr add start 104 sub get ms 0 start 1275 wr add start 112 4096 1276 word add start 120 1 1277 word add start 124 6 1278 wr add start 136 `268435456` 1279 wr add start 144 `268435456` 1280 wr add start 160 `8392704` 1281 wr add start 168 4096 1282 word add start 176 `3533832199` 1283 word add start 180 `3533836304` 1284 word add start 184 `2436892176` 1285 word add start 188 `2432696863` 1286 word add start 192 `268435664` 1287 word add start 196 `4177529072` 1288 word add start 200 br add start 200 placed entry `2483027968` 1289 word add start 204 `3573751839` 1290 if eq cell entry 2 12 1291 word add start 204 `3531603968` 1292 end 1293 word add start 208 `3531606952` 1294 word add start 212 `3556769793` 1295 word add start 216 `2432798752` 1296 word add start 220 `3531606952` 1297 word add start 224 `3556769793` 1298 end 1299 fn functionwrap start ulong root ulong to void 1300 idx = ulong 0 1301 for j ulong cell root 9 bound `9223372036854775807` 1302 f = func root j 1303 if eq get mt f 1 1304 site = add start mul idx 4 1305 word site br site placed f `335544320` 1306 idx = add idx 1 1307 end 1308 end 1309 descriptor root start 1310 end 1311 fn linkimage root ulong mode bool ep ulong en ulong to ulong 1312 entry = ulong 0 1313 count = ulong 0 1314 for j ulong cell root 9 bound `9223372036854775807` 1315 f = func root j 1316 if eq get mt f 1 1317 count = add count 1 1318 end 1319 end 1320 need gt count 0 40 1321 if mode 1322 entry = exported root ep en 1323 need eq cell entry 3 0 40 1324 need or eq cell entry 2 8 eq cell entry 2 12 40 1325 end 1326 start = get ms 0 1327 if mode 1328 p = ba 228 1329 else 1330 p = ba mul count 4 1331 end 1332 placemodules 1333 if mode 1334 programwrap start entry 1335 else 1336 functionwrap start root 1337 end 1338 put mg 10 sub get ms 0 start 1339 ret start 1340 end 1341 fn argpos args ulong i ulong to ulong 1342 ret get mt add args mul i 2 1343 end 1344 fn arglen args ulong i ulong to ulong 1345 ret get mt add add args mul i 2 1 1346 end 1347 fn runbuild args ulong to void 1348 need eq arglen args 8 64 10 1349 sh = argpos args 8 1350 hxvalid sh 1351 fd = readpath argpos args 7 arglen args 7 1352 need ge fd 0 26 1353 sp = load int fd 1354 sn = get mg 10 1355 hash sp sn 1356 hashis sh 1357 fd = readpath argpos args 2 arglen args 2 1358 need ge fd 0 26 1359 cp = load int fd 1360 cn = get mg 10 1361 hash cp cn 1362 hashis argpos args 3 1363 root = build cp cn sp sn sh 1364 r = write 1 mb cell root 14 64 1365 r = write 1 newln 0 1 1366 end 1367 fn runlink args ulong to void 1368 need and eq arglen args 6 64 eq arglen args 7 64 10 1369 hxvalid argpos args 6 1370 hxvalid argpos args 7 1371 root = cached argpos args 6 argpos args 7 1372 resolveall 1373 graph 1374 mode = lit argpos args 8 arglen args 8 progcmd 1375 need or mode lit argpos args 8 arglen args 8 funccmd 10 1376 p = linkimage root mode argpos args 9 arglen args 9 1377 n = get mg 10 1378 restore 1379 dest = argpos args 10 1380 dn = arglen args 10 1381 s = parent dest dn 1382 perm = int 292 1383 if mode 1384 perm = 365 1385 end 1386 publish p n add dest s sub dn s perm 1387 restore 1388 end 1389 fn main to int 1390 r = ta 1 1391 r = ba 1 1392 cwdfile = fopen dottext 0 1 16384 0 1393 need ge cwdfile 0 25 1394 put mg 3 ulong cwdfile 1395 ac = argcnt 1396 need or eq ac 9 eq ac 11 10 1397 args = ta mul ulong ac 2 1398 for i ulong ulong ac bound 11 1399 p = arg i 1400 put mt add args mul i 2 p 1401 put mt add add args mul i 2 1 get mg 10 1402 end 1403 isbuild = lit argpos args 1 arglen args 1 modcmd 1404 islink = lit argpos args 1 arglen args 1 linkcmd 1405 need or and isbuild eq ac 9 and islink eq ac 11 10 1406 need eq arglen args 3 64 10 1407 hxvalid argpos args 3 1408 for j ulong 64 1409 put mc j get mb add argpos args 3 j 1410 end 1411 prof = argpos args 4 1412 profn = arglen args 4 1413 if lit prof profn debugnm 1414 put mg 0 0 1415 else 1416 need lit prof profn releasenm 10 1417 put mg 0 1 1418 end 1419 need lit argpos args 5 arglen args 5 targetnm 10 1420 si = ulong 2 1421 if isbuild 1422 si = 6 1423 end 1424 p = argpos args si 1425 n = arglen args si 1426 s = parent p n 1427 fd = fopen mp s sub n s 49152 0 1428 need ge fd 0 25 1429 put mg 4 ulong fd 1430 restore 1431 if isbuild 1432 runbuild args 1433 else 1434 runlink args 1435 end 1436 ret 0 1437 end