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/omc/pinned.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 / omc / pinned.om` 3986 lines ยท 68349 bytes Raw Blame History 1 note omc: the Omega compiler written in Omega (the om4 subset). Reads Omegese on stdin, writes a runnable 2 note AArch64 Linux program (or bare function words) on stdout. Built first by om4; its codegen matches om4 3 note byte for byte on the original subset (seed chain rung 5, ledger L408). Native host operations 4 note extend that subset; om4 still builds this compiler, and the compiler rebuilds itself identically. 5 note All compiler state lives in fixed global pools (decision 24: no heap). Every working value is a ulong 6 note (raw 64 bits) so the language's checked conversions never fire on om4's untyped-register logic. 7 8 note ---- input, output, token ---- 9 global inp uchar `8388608` 10 global inlen ulong 1 11 global cur ulong 1 12 global line ulong 1 13 global tk ulong 1 14 global tw ulong 1 15 global tl ulong 1 16 global ts ulong 1 17 global tbig ulong 1 18 global out uchar `8388608` 19 global oc ulong 1 20 21 note ---- name table (1024 names in scope): packed name, register, type, length, kind, address ---- 22 global nm_name ulong 1024 23 global nm_reg uchar 1024 24 global nm_type uchar 1024 25 global nm_len ulong 1024 26 global nm_kind uchar 1024 27 global nm_addr ulong 1024 28 global nn ulong 1 29 30 note ---- function table (512): name, address (byte offset in out), return type, parameter count, 31 note per-parameter type/length/kind (6 each), name length, name offset in the input ---- 32 global fn_name ulong 512 33 global fn_addr ulong 512 34 global fn_ret uchar 512 35 global fn_np uchar 512 36 global fn_pt uchar 3072 37 global fn_pl ulong 3072 38 global fn_pk uchar 3072 39 global fn_nmlen ulong 512 40 global fn_off ulong 512 41 global nf ulong 1 42 global lastfn ulong 1 43 global scanning ulong 1 44 global ncalls ulong 1 45 global callsite ulong 65536 46 global callfrom ulong 65536 47 global callto ulong 65536 48 global settled uchar 512 49 50 51 note ---- compiler state ---- 52 global npar ulong 1 53 global held ulong 1 54 global nslot ulong 1 55 global curret ulong 1 56 global progmode ulong 1 57 global nglob ulong 1 58 global hostargs ulong 1 59 global stkbytes ulong 1 60 global dead ulong 1 61 global poolb ulong 1 62 63 note ======== leaf helpers ======== 64 65 note poolc: the i-th register of the pool x0..x6, x8..x15, x17 (x7 is the runtime, x16 scratch) 66 fn poolc i ulong to ulong 67 if lt i 7 68 ret i 69 end 70 if lt i 15 71 ret add i 1 72 end 73 ret 17 74 end 75 76 note ---- error reporting ---- 77 global msg uchar 64 78 global mc ulong 1 79 80 fn mputb b uchar to void 81 m = get mc 0 82 put msg m b 83 put mc 0 add m 1 84 end 85 86 fn mputn v ulong to void 87 d = new uchar 20 0 88 i = ulong 0 89 x = v 90 put d 0 uchar add rem x 10 48 91 x = div x 10 92 i = add i 1 93 while gt x 0 94 put d i uchar add rem x 10 48 95 x = div x 10 96 i = add i 1 97 end 98 j = i 99 while gt j 0 100 j = sub j 1 101 mputb get d j 102 end 103 end 104 105 note fail: write "omc: line N: error E" to stderr (fd 2) and exit with the code 106 fn fail code ulong to void 107 put mc 0 0 108 mputb 111 109 mputb 109 110 mputb 99 111 mputb 58 112 mputb 32 113 mputb 108 114 mputb 105 115 mputb 110 116 mputb 101 117 mputb 32 118 mputn get line 0 119 mputb 58 120 mputb 32 121 mputb 101 122 mputb 114 123 mputb 114 124 mputb 111 125 mputb 114 126 mputb 32 127 mputn code 128 mputb 10 129 w = write 2 msg 0 get mc 0 130 exit int code 131 end 132 133 note emitb / emit: one byte / one 32-bit word (little-endian) to the output; error 14 when it is full 134 note (om4 EMIT, EMITB: the 8 MiB output area) 135 fn emitb b uchar to void 136 o = get oc 0 137 if ge o `8388608` 138 fail 14 139 end 140 put out o b 141 put oc 0 add o 1 142 end 143 144 fn emit w ulong to void 145 if ge get oc 0 `8388608` 146 fail 14 147 end 148 emitb uchar and w 255 149 emitb uchar and shr w 8 255 150 emitb uchar and shr w 16 255 151 emitb uchar and shr w 24 255 152 end 153 154 note tok_num: the word at [ts,cur) is [-]decimal, at most 20 digits, from -2^63 to 2^64 - 1 (error 6 155 note bad number, 8 out of range). tw = its raw 64 bits (a negative one as two's complement); tbig = 1 156 note when it is 2^63 or more (only a ulong holds it), else 0. As om4's TK_NUM. 157 fn tok_num to void 158 p = get ts 0 159 e = get cur 0 160 minus = false 161 if eq get inp p 45 162 minus = true 163 p = add p 1 164 end 165 ndig = sub e p 166 if eq ndig 0 167 fail 6 168 end 169 if gt ndig 20 170 fail 6 171 end 172 v = ulong 0 173 lim = ulong `1844674407370955161` 174 i = p 175 while lt i e 176 d = sub ulong get inp i 48 177 if gt d 9 178 fail 6 179 end 180 if gt v lim 181 fail 8 182 end 183 if and eq v lim gt d 5 184 fail 8 185 end 186 v = add mul v 10 d 187 i = add i 1 188 end 189 half = shl ulong 1 63 190 put tbig 0 0 191 if minus 192 if gt v half 193 fail 8 194 end 195 put tw 0 sub ulong 0 v 196 else 197 if ge v half 198 put tbig 0 1 199 end 200 put tw 0 v 201 end 202 put tk 0 2 203 end 204 205 note tok_text: a text literal starting at the opening quote. tw = first byte offset, tl = source length 206 note (escapes not yet decoded). Ends at an unescaped '"' on the same line, followed by a blank/end. Err 22. 207 note (Loops over the input are two loops, the inner under `1000000` passes: om4 has no pass limit.) 208 fn tok_text to void 209 put cur 0 add get cur 0 1 210 put tw 0 get cur 0 211 go = true 212 while go 213 n = ulong 0 214 while and go lt n 999999 215 if ge get cur 0 get inlen 0 216 fail 22 217 end 218 b = get inp get cur 0 219 if eq b 10 220 fail 22 221 end 222 if eq b 34 223 go = false 224 else 225 put cur 0 add get cur 0 1 226 if eq b 92 227 if ge get cur 0 get inlen 0 228 fail 22 229 end 230 if eq get inp get cur 0 10 231 fail 22 232 end 233 put cur 0 add get cur 0 1 234 end 235 end 236 n = add n 1 237 end 238 end 239 put tl 0 sub get cur 0 get tw 0 240 put cur 0 add get cur 0 1 241 put tk 0 4 242 if lt get cur 0 get inlen 0 243 if gt get inp get cur 0 32 244 fail 22 245 end 246 end 247 end 248 249 note tok2: a word at cur with first byte c; packs 8 bytes into tw, sets tl and ts. A '"' is a text; a 250 note first byte '-' or a digit is a number. 251 fn tok2 c uchar to void 252 if eq c 34 253 tok_text 254 ret 255 end 256 put ts 0 get cur 0 257 w = ulong 0 258 sh = ulong 0 259 n = ulong 0 260 go = true 261 while go 262 m = ulong 0 263 while and go lt m 999999 264 if ge get cur 0 get inlen 0 265 go = false 266 else 267 b = get inp get cur 0 268 if le b 32 269 go = false 270 else 271 if lt n 8 272 w = or w shl ulong b sh 273 sh = add sh 8 274 end 275 n = add n 1 276 put cur 0 add get cur 0 1 277 end 278 end 279 m = add m 1 280 end 281 end 282 put tw 0 w 283 put tl 0 n 284 f = get inp get ts 0 285 isnum = false 286 if eq f 45 287 isnum = true 288 end 289 if and ge f 48 le f 57 290 isnum = true 291 end 292 if isnum 293 tok_num 294 else 295 put tk 0 1 296 end 297 end 298 299 note tok: next word, skipping blanks (space, tab, carriage return); newline is end of line (kind 0) and 300 note bumps the line number; another byte below 32 is error 16; the end of the input is kind 3. om4 TOK. 301 fn tok to void 302 go = true 303 while go 304 n = ulong 0 305 while and go lt n 999999 306 if ge get cur 0 get inlen 0 307 go = false 308 else 309 c = get inp get cur 0 310 if or or eq c 32 eq c 9 eq c 13 311 put cur 0 add get cur 0 1 312 else 313 if eq c 10 314 put cur 0 add get cur 0 1 315 put line 0 add get line 0 1 316 put tk 0 0 317 ret 318 end 319 if lt c 32 320 fail 16 321 end 322 tok2 c 323 ret 324 end 325 end 326 n = add n 1 327 end 328 end 329 put tk 0 3 330 end 331 332 note ======== keyword lookup (original om4 KWTAB plus hand-maintained native host words 100..134) ======== 333 note genkw.awk describes the original om4 table only; retain the native host extension on regeneration. 334 fn kw w ulong to ulong 335 if eq w `6584163` 336 ret 132 337 end 338 packed = or ulong 114 shl ulong 101 8 339 packed = or packed shl ulong 97 16 340 packed = or packed shl ulong 100 24 341 packed = or packed shl ulong 108 32 342 packed = or packed shl ulong 110 40 343 packed = or packed shl ulong 107 48 344 if eq w packed 345 ret 133 346 end 347 packed = or ulong 115 shl ulong 111 8 348 packed = or packed shl ulong 99 16 349 packed = or packed shl ulong 107 24 350 packed = or packed shl ulong 111 32 351 packed = or packed shl ulong 112 40 352 packed = or packed shl ulong 116 48 353 if eq w packed 354 ret 134 355 end 356 if eq w `1819242338` 357 ret 1 358 end 359 if eq w `491260502901` 360 ret 2 361 end 362 if eq w 14453 363 ret 2 364 end 365 if eq w `128034844210037` 366 ret 3 367 end 368 if eq w `3551605` 369 ret 3 370 end 371 if eq w `1953393013` 372 ret 4 373 end 374 if eq w `3289973` 375 ret 4 376 end 377 if eq w `444234427509` 378 ret 5 379 end 380 if eq w `3421813` 381 ret 5 382 end 383 if eq w `1702132066` 384 ret 6 385 end 386 if eq w 14441 387 ret 6 388 end 389 if eq w `500136110195` 390 ret 7 391 end 392 if eq w `3551593` 393 ret 7 394 end 395 if eq w `7630441` 396 ret 8 397 end 398 if eq w `3289961` 399 ret 8 400 end 401 if eq w `1735290732` 402 ret 9 403 end 404 if eq w `3421801` 405 ret 9 406 end 407 if eq w `6579297` 408 ret 33 409 end 410 if eq w `6452595` 411 ret 34 412 end 413 if eq w `7107949` 414 ret 35 415 end 416 if eq w `7760228` 417 ret 36 418 end 419 if eq w `7169394` 420 ret 37 421 end 422 if eq w `6581857` 423 ret 38 424 end 425 if eq w 29295 426 ret 39 427 end 428 if eq w `7499640` 429 ret 40 430 end 431 if eq w `7104627` 432 ret 41 433 end 434 if eq w `7497843` 435 ret 42 436 end 437 if eq w 29029 438 ret 43 439 end 440 if eq w 25966 441 ret 44 442 end 443 if eq w 29804 444 ret 45 445 end 446 if eq w 25964 447 ret 46 448 end 449 if eq w 29799 450 ret 47 451 end 452 if eq w 25959 453 ret 48 454 end 455 if eq w `6776174` 456 ret 49 457 end 458 if eq w `7630702` 459 ret 50 460 end 461 if eq w `7628135` 462 ret 51 463 end 464 if eq w `7234924` 465 ret 52 466 end 467 if eq w `1684104562` 468 ret 53 469 end 470 if eq w `435744764535` 471 ret 54 472 end 473 if eq w `1702195828` 474 ret 55 475 end 476 if eq w `435728179558` 477 ret 56 478 end 479 if eq w `2003134838` 480 ret 57 481 end 482 if eq w `1953064037` 483 ret 58 484 end 485 if eq w 28262 486 ret 64 487 end 488 if eq w 28532 489 ret 65 490 end 491 if eq w `6581861` 492 ret 66 493 end 494 if eq w 26217 495 ret 67 496 end 497 if eq w `1702063205` 498 ret 68 499 end 500 if eq w `435610544247` 501 ret 69 502 end 503 if eq w `431349919586` 504 ret 70 505 end 506 if eq w `7499622` 507 ret 71 508 end 509 if eq w `7628146` 510 ret 72 511 end 512 if eq w 61 513 ret 73 514 end 515 if eq w 40 516 ret 74 517 end 518 if eq w 41 519 ret 75 520 end 521 if eq w `1684631414` 522 ret 76 523 end 524 if eq w `119165519096935` 525 ret 78 526 end 527 if eq w `1954047348` 528 ret 79 529 end 530 if eq w `7632240` 531 ret 80 532 end 533 if eq w `1701147238` 534 ret 81 535 end 536 if eq w `1953069157` 537 ret 82 538 end 539 if eq w `1702129518` 540 ret 83 541 end 542 if eq w `7824750` 543 ret 84 544 end 545 if eq w `461195539042` 546 ret 77 547 end 548 if eq w `1885434484` 549 ret 77 550 end 551 if eq w `7239535` 552 ret 77 553 end 554 if eq w `7308604897168158579` 555 ret 131 556 end 557 if eq w `126918101919090` 558 ret 130 559 end 560 if eq w `7453301735350958181` 561 ret 124 562 end 563 if eq w `32481142782190962` 564 ret 125 565 end 566 if eq w `491394461042` 567 ret 126 568 end 569 if eq w `28263429247363435` 570 ret 127 571 end 572 if eq w `32480013273033072` 573 ret 128 574 end 575 if eq w `110404021020007` 576 ret 129 577 end 578 if eq w `122498715312503` 579 ret 123 580 end 581 if eq w `32497639802299751` 582 ret 113 583 end 584 if eq w `32760384594014051` 585 ret 114 586 end 587 if eq w `1684957538` 588 ret 115 589 end 590 if eq w `28263429381382519` 591 ret 116 592 end 593 if eq w `499851228006` 594 ret 117 595 end 596 if eq w `1986225522` 597 ret 118 598 end 599 if eq w `1684956531` 600 ret 119 601 end 602 if eq w `32491051338263667` 603 ret 120 604 end 605 if eq w `128017462948449` 606 ret 121 607 end 608 if eq w `28254586010038881` 609 ret 122 610 end 611 if eq w `111546465018726` 612 ret 100 613 end 614 if eq w `427055215462` 615 ret 101 616 end 617 if eq w `110429739705190` 618 ret 102 619 end 620 if eq w `461262648166` 621 ret 103 622 end 623 if eq w `33607047151054707` 624 ret 104 625 end 626 if eq w `121382024472940` 627 ret 105 628 end 629 if eq w `128026086171489` 630 ret 106 631 end 632 if eq w `1802661734` 633 ret 107 634 end 635 if eq w `431215375716` 636 ret 108 637 end 638 if eq w `126918153105261` 639 ret 109 640 end 641 if eq w `474148269926` 642 ret 110 643 end 644 if eq w `118121959288437` 645 ret 111 646 end 647 if eq w `32204027264196973` 648 ret 112 649 end 650 ret 0 651 end 652 653 note ======== om4's small tables, as functions ======== 654 note twid: width in bits by type 0..9 (bool 1; uchar ushort uint ulong; byte short int long) 655 fn twid t ulong to ulong 656 if eq t 1 657 ret 1 658 end 659 if or eq t 2 eq t 6 660 ret 8 661 end 662 if or eq t 3 eq t 7 663 ret 16 664 end 665 if or eq t 4 eq t 8 666 ret 32 667 end 668 if or eq t 5 eq t 9 669 ret 64 670 end 671 ret 0 672 end 673 674 note tlog: log2 of the element size by type 675 fn tlog t ulong to ulong 676 if or eq t 3 eq t 7 677 ret 1 678 end 679 if or eq t 4 eq t 8 680 ret 2 681 end 682 if or eq t 5 eq t 9 683 ret 3 684 end 685 ret 0 686 end 687 688 note regidx: the pool index of register r (the inverse of poolc; 255 for x7 and x16) 689 fn regidx r ulong to ulong 690 if lt r 7 691 ret r 692 end 693 if eq r 7 694 ret 255 695 end 696 if lt r 16 697 ret sub r 1 698 end 699 if eq r 16 700 ret 255 701 end 702 ret 15 703 end 704 705 note conds: the condition for eq ne lt le gt ge (i = 2 (op - 43) + 1 when signed): EQ 0, NE 1, LO 3 / LT 11, 706 note LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10 (Arm ARM Table C1-1). The opposite condition is cond xor 1. 707 fn conds i ulong to ulong 708 if lt i 2 709 ret 0 710 end 711 if lt i 4 712 ret 1 713 end 714 if eq i 4 715 ret 3 716 end 717 if eq i 5 718 ret 11 719 end 720 if eq i 6 721 ret 9 722 end 723 if eq i 7 724 ret 13 725 end 726 if eq i 8 727 ret 8 728 end 729 if eq i 9 730 ret 12 731 end 732 if eq i 10 733 ret 2 734 end 735 ret 10 736 end 737 738 note ldop / stop: register-offset load / store by element type (om4 LDOP, STOP tables) 739 fn ldop t ulong to ulong 740 note LDRB 0x38606800, LDRH 0x78607800, LDR w 0xb8607800, LDR x 0xf8607800, LDRSB 0x38a06800, 741 note LDRSH 0x78a07800, LDRSW 0xb8a07800 742 if eq t 2 743 ret `945842176` 744 end 745 if eq t 3 746 ret `2019588096` 747 end 748 if eq t 4 749 ret `3093329920` 750 end 751 if or eq t 5 eq t 9 752 ret `4167071744` 753 end 754 if eq t 6 755 ret `950036480` 756 end 757 if eq t 7 758 ret `2023782400` 759 end 760 if eq t 8 761 ret `3097524224` 762 end 763 ret 0 764 end 765 766 fn stop t ulong to ulong 767 note STRB 0x38206800, STRH 0x78207800, STR w 0xb8207800, STR x 0xf8207800 768 if or eq t 2 eq t 6 769 ret `941647872` 770 end 771 if or eq t 3 eq t 7 772 ret `2015393792` 773 end 774 if or eq t 4 eq t 8 775 ret `3089135616` 776 end 777 if or eq t 5 eq t 9 778 ret `4162877440` 779 end 780 ret 0 781 end 782 783 note ---- trap list (8192 sites per function): output offset of the branch, trap code ---- 784 global tsite ulong 8192 785 global tcode ulong 8192 786 global nt ulong 1 787 note ---- block stack (512): kind (1 if, 2 else, 3 while, 4 for), branch to patch, loop head, loop 788 note register, its type, names and held pool slots to restore at end, then-part ended (for else) ---- 789 global bkind ulong 512 790 global bbr ulong 512 791 global bhead ulong 512 792 global breg ulong 512 793 global btyp ulong 512 794 global bnames ulong 512 795 global bheld ulong 512 796 global bdead ulong 512 797 global nb ulong 1 798 global curfn ulong 1 799 800 note ======== names and functions ======== 801 note findname: packed name -> its index + 1 among the names in scope (0 none). om4 FINDNAME. 802 fn findname w ulong to ulong 803 i = ulong 0 804 n = get nn 0 805 while lt i n 806 if eq get nm_name i w 807 ret add i 1 808 end 809 i = add i 1 810 end 811 ret 0 812 end 813 814 note findfn: packed name w (first 8 bytes), length l (any value up to 8 for a short name), start s in the 815 note input (read only for a name over 8 bytes) -> function index + 1 (0 none). om4 FINDFN. 816 fn findfn w ulong l ulong s ulong to ulong 817 j = ulong 0 818 while lt j get nf 0 819 if eq get fn_name j w 820 fl = get fn_nmlen j 821 if le l 8 822 if le fl 8 823 ret add j 1 824 end 825 else 826 if eq fl l 827 o = get fn_off j 828 k = ulong 8 829 same = true 830 while and same lt k l 831 a = get inp add o k 832 if ne a get inp add s k 833 same = false 834 end 835 k = add k 1 836 end 837 if same 838 ret add j 1 839 end 840 end 841 end 842 end 843 j = add j 1 844 end 845 ret 0 846 end 847 848 note newname: the name must not be in use (a name in scope when 8 bytes or fewer, or a function): error 10 849 fn newname w ulong l ulong s ulong to void 850 if le l 8 851 if ne findname w 0 852 fail 10 853 end 854 end 855 if ne findfn w l s 0 856 fail 10 857 end 858 end 859 860 note addname: packed name, register, type, length, kind, address. om4 ADDNAME. 861 fn addname w ulong r ulong t ulong ln ulong k ulong a ulong to void 862 n = get nn 0 863 if ge n 1024 864 fail 14 865 end 866 put nm_name n w 867 put nm_reg n uchar r 868 put nm_type n uchar t 869 put nm_len n ln 870 put nm_kind n uchar k 871 put nm_addr n a 872 put nn 0 add n 1 873 end 874 875 note ======== registers and words ======== 876 note alloc: the next free register of the pool (after the parameters); error 12 when none is left 877 fn alloc to ulong 878 i = add get npar 0 get nslot 0 879 if ge i 16 880 fail 12 881 end 882 put nslot 0 add get nslot 0 1 883 ret poolc i 884 end 885 886 note destreg: d, or a new temporary when d is 255 887 fn destreg d ulong to ulong 888 if eq d 255 889 ret alloc 890 end 891 ret d 892 end 893 894 note e3: emit op | d | n << 5 | m << 16 895 fn e3 op ulong d ulong n ulong m ulong to void 896 emit or or or op d shl n 5 shl m 16 897 end 898 899 note trapsite: note the place and code of a branch to the trap stub, then emit it. trapc: B.cond, as om4. 900 fn trapsite w ulong code ulong to void 901 n = get nt 0 902 if ge n 8192 903 fail 14 904 end 905 put tsite n get oc 0 906 put tcode n code 907 put nt 0 add n 1 908 emit w 909 end 910 911 fn trapc cc ulong code ulong to void 912 trapsite or `1409286144` cc code 913 end 914 915 fn rdword at ulong to ulong 916 a = ulong get out at 917 b = shl ulong get out add at 1 8 918 c = shl ulong get out add at 2 16 919 d = shl ulong get out add at 3 24 920 ret or or or a b c d 921 end 922 923 fn wrword at ulong w ulong to void 924 put out at uchar and w 255 925 put out add at 1 uchar and shr w 8 255 926 put out add at 2 uchar and shr w 16 255 927 put out add at 3 uchar and shr w 24 255 928 end 929 930 note patch19: the word distance from a B.cond / CBZ / CBNZ at `at` to `target`, into bits 5..23 931 fn patch19 at ulong target ulong to void 932 d = and shr sub target at 2 524287 933 wrword at or rdword at shl d 5 934 end 935 936 note patch26: the word distance from a B at `at` to `target`, into bits 0..25 937 fn patch26 at ulong target ulong to void 938 d = and shr sub target at 2 `67108863` 939 wrword at or rdword at d 940 end 941 942 note back: emit B to an earlier place (C6.2.35) 943 fn back addr ulong to void 944 emit or `335544320` and shr sub addr get oc 0 2 `67108863` 945 end 946 947 note matconst: put a 64-bit value in register r: MOVZ (C6.2.285) or, for a value with the top bit set, 948 note MOVN (C6.2.284) with the first halfword that differs from the fill, then MOVK (C6.2.283) for each 949 note other such halfword. om4 MATCONST. 950 fn matconst r ulong v ulong to void 951 fill = ulong 0 952 mop = ulong `3531603968` 953 if ne shr v 63 0 954 fill = ulong 65535 955 mop = ulong `2457862144` 956 end 957 started = false 958 hw = ulong 0 959 while lt hw 4 960 h = and shr v shl hw 4 65535 961 if ne h fill 962 if started 963 emit or or or `4068474880` shl h 5 shl hw 21 r 964 else 965 emit or or or mop shl xor h fill 5 shl hw 21 r 966 started = true 967 end 968 end 969 hw = add hw 1 970 end 971 if not started 972 emit or mop r 973 end 974 end 975 976 note canon: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355); else nothing 977 fn canon r ulong t ulong to void 978 if lt t 2 979 ret 980 end 981 if eq t 5 982 ret 983 end 984 if eq t 9 985 ret 986 end 987 base = ulong `3544186880` 988 if gt t 5 989 base = ulong `2470445056` 990 end 991 emit or or or base shl sub twid t 1 10 r shl r 5 992 end 993 994 note chkext: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended, C6.2.463), then B.NE trap code 995 fn chkext r ulong t ulong code ulong to void 996 emit or or or `3944742943` shl sub t 2 13 shl r 16 shl r 5 997 trapc 1 code 998 end 999 1000 note range: error 8 unless v is a value of type t; big = the number was written as 2^63 or more 1001 fn range v ulong t ulong big ulong to void 1002 w = twid t 1003 if eq w 64 1004 if eq t 9 1005 if ne big 0 1006 fail 8 1007 end 1008 ret 1009 end 1010 if ne big 0 1011 ret 1012 end 1013 if ne shr v 63 0 1014 fail 8 1015 end 1016 ret 1017 end 1018 if ne big 0 1019 fail 8 1020 end 1021 lim = shl ulong 1 w 1022 if lt t 6 1023 if ge v lim 1024 fail 8 1025 end 1026 ret 1027 end 1028 half = shr lim 1 1029 if ge add v half lim 1030 fail 8 1031 end 1032 end 1033 1034 note cset: CSET Xr, cond = CSINC Xr, XZR, XZR, opposite cond (C6.2.141) 1035 fn cset r ulong cc ulong to void 1036 emit or or `2594113504` r shl xor cc 1 12 1037 end 1038 1039 note force: put a value (kind 1 register, 3 number, 4 flags) in register r; a bare number is error 11 1040 fn force k ulong v ulong t ulong r ulong to void 1041 if eq k 1 1042 if ne v r 1043 emit or or `2852127712` r shl v 16 1044 end 1045 ret 1046 end 1047 if eq k 3 1048 matconst r v 1049 ret 1050 end 1051 if eq k 4 1052 cset r v 1053 ret 1054 end 1055 fail 11 1056 end 1057 1058 note matreg: a register holding the value 1059 fn matreg k ulong v ulong t ulong to ulong 1060 if eq k 1 1061 ret v 1062 end 1063 r = alloc 1064 force k v t r 1065 ret r 1066 end 1067 1068 note spop: ADD (C6.2.5) / SUB (C6.2.457) SP, SP by a multiple of 16 below 2^24: low 12 bits, then the 1069 note high 12 bits LSL 12; nothing for a zero part 1070 fn spop base ulong bytes ulong to void 1071 lo = and bytes 4095 1072 if ne lo 0 1073 emit or or base 1023 shl lo 10 1074 end 1075 hi = and shr bytes 12 4095 1076 if ne hi 0 1077 emit or or base `4195327` shl hi 10 1078 end 1079 end 1080 1081 fn spadd bytes ulong to void 1082 spop `2432696320` bytes 1083 end 1084 1085 fn spsub bytes ulong to void 1086 spop `3506438144` bytes 1087 end 1088 1089 note stkchk: program mode only: CMP SP, X28 (C6.2.463); B.LO trap 6 1090 fn stkchk to void 1091 if ne get progmode 0 0 1092 emit `3946603519` 1093 trapc 3 6 1094 end 1095 end 1096 1097 note epi: give back the stack of the local arrays, then RET (C6.2.338) 1098 fn epi to void 1099 spadd get stkbytes 0 1100 emit `3596551104` 1101 end 1102 1103 fn dead1 to void 1104 put dead 0 1 1105 end 1106 1107 note pushb / pushnh: open a block (om4 PUSHB, split in two because a call takes at most 6 values) 1108 fn pushb br ulong k ulong head ulong reg ulong ty ulong to void 1109 n = get nb 0 1110 if ge n 512 1111 fail 14 1112 end 1113 put bkind n k 1114 put bbr n br 1115 put bhead n head 1116 put breg n reg 1117 put btyp n ty 1118 put bdead n 0 1119 put nb 0 add n 1 1120 end 1121 1122 fn pushnh names ulong hd ulong to void 1123 n = sub get nb 0 1 1124 put bnames n names 1125 put bheld n hd 1126 end 1127 1128 note ======== small readers ======== 1129 fn elemtype t ulong to void 1130 if lt t 2 1131 fail 9 1132 end 1133 end 1134 1135 note arrlen: an array length 1 .. `16777216` (error 8 below, 23 above, 23 when written as 2^63 or more) 1136 fn arrlen v ulong to void 1137 if ne get tbig 0 0 1138 fail 23 1139 end 1140 if or eq v 0 ne shr v 63 0 1141 fail 8 1142 end 1143 if gt v `16777216` 1144 fail 23 1145 end 1146 end 1147 1148 note typeword: read a type name -> 1..9 1149 fn typeword to ulong 1150 tok 1151 k = get tk 0 1152 if eq k 0 1153 fail 4 1154 end 1155 if ne k 1 1156 fail 16 1157 end 1158 if gt get tl 0 8 1159 fail 16 1160 end 1161 c = kw get tw 0 1162 if eq c 76 1163 fail 9 1164 end 1165 if gt sub c 1 8 1166 fail 16 1167 end 1168 ret c 1169 end 1170 1171 note eol: the line must end here 1172 fn eol to void 1173 tok 1174 k = get tk 0 1175 if and ne k 0 ne k 3 1176 fail 5 1177 end 1178 end 1179 1180 note arrname: read an array name -> its index + 1 1181 fn arrname to ulong 1182 tok 1183 k = get tk 0 1184 if eq k 0 1185 fail 4 1186 end 1187 if eq k 3 1188 fail 4 1189 end 1190 if ne k 1 1191 fail 16 1192 end 1193 if gt get tl 0 8 1194 fail 13 1195 end 1196 e = findname get tw 0 1197 if eq e 0 1198 fail 3 1199 end 1200 if eq get nm_kind sub e 1 0 1201 fail 7 1202 end 1203 ret e 1204 end 1205 1206 note topname: read a new name for a global or a text -> its packed word 1207 fn topname to ulong 1208 tok 1209 if ne get tk 0 1 1210 fail 16 1211 end 1212 if gt get tl 0 8 1213 fail 13 1214 end 1215 w = get tw 0 1216 if ne kw w 0 1217 fail 16 1218 end 1219 newname w get tl 0 get ts 0 1220 ret w 1221 end 1222 1223 note ---- value results (om4 x0 kind 1 register / 2 bare number / 3 typed number / 4 flags, x1 register, 1224 note number or condition, x2 type). fr: 32 cells per value nesting depth 0..1024: 0..5 the two operands of 1225 note a binary op (kind, value, type each), 8..25 a call's arguments (kind, value, array name each) ---- 1226 global rk ulong 1 1227 global rv ulong 1 1228 global rt ulong 1 1229 global fr ulong 32800 1230 global depth ulong 1 1231 1232 note ======== BINOP (om4 BINOP and its BO_* parts): two values already read, types settled ======== 1233 note bo_w3: emit fx | rd | ra << 5 | (imm12 << 10, or rb << 16) 1234 fn bo_w3 fx ulong rd ulong ra ulong rb ulong imm ulong to void 1235 if ne imm 0 1236 emit or or or fx rd shl ra 5 shl rb 10 1237 else 1238 emit or or or fx rd shl ra 5 shl rb 16 1239 end 1240 end 1241 1242 note bo_fix: after a 64-bit op on rd: u8/u16/u32 wrap (canon), i8/i16/i32 overflow check (trap 1) 1243 fn bo_fix rd ulong ty ulong to void 1244 if lt ty 6 1245 canon rd ty 1246 ret 1247 end 1248 if eq ty 9 1249 ret 1250 end 1251 chkext rd ty 1 1252 end 1253 1254 note bo_schk: a shift amount in a register must be below the width: CMP Xb, #w; B.HS trap 7 1255 fn bo_schk ty ulong rb ulong to void 1256 emit or or `4043309087` shl twid ty 10 shl rb 5 1257 trapc 2 7 1258 end 1259 1260 note add, sub: u32 the 32-bit form; i64 ADDS/SUBS + B.VS trap 1; others 64-bit then bo_fix (om4 BO_ADD) 1261 fn bo_add op ulong ty ulong ra ulong rb ulong imm ulong rd ulong to void 1262 fx = ulong `2332033024` 1263 if eq op 34 1264 fx = ulong `3405774848` 1265 end 1266 if ne imm 0 1267 fx = ulong `2432696320` 1268 if eq op 34 1269 fx = ulong `3506438144` 1270 end 1271 end 1272 if eq ty 4 1273 bo_w3 xor fx `2147483648` rd ra rb imm 1274 ret 1275 end 1276 if eq ty 9 1277 bo_w3 or fx `536870912` rd ra rb imm 1278 trapc 6 1 1279 ret 1280 end 1281 bo_w3 fx rd ra rb imm 1282 bo_fix rd ty 1283 end 1284 1285 note mul: i64 SMULH t, MUL, CMP t, rd, ASR #63, B.NE trap 1 (om4 BO_MUL) 1286 fn bo_mul ty ulong ra ulong rb ulong rd ulong to void 1287 if eq ty 9 1288 t = alloc 1289 e3 `2604694528` t ra rb 1290 bo_w3 `2600500224` rd ra rb 0 1291 e3 `3951098911` 0 t rd 1292 trapc 1 1 1293 ret 1294 end 1295 if eq ty 4 1296 bo_w3 `453016576` rd ra rb 0 1297 ret 1298 end 1299 bo_w3 `2600500224` rd ra rb 0 1300 bo_fix rd ty 1301 end 1302 1303 note div, rem (om4 BO_DIV, BO_SDIV): CBZ Xb trap 2 unless fl bit 1 (b a number other than 0); UDIV or 1304 note SDIV; rem: t = a / b, rd = a - t * b (MSUB); i64 div: CMN Xb, #1; B.NE +3; NEGS XZR, Xa; B.VS trap 1, 1305 note unless fl bit 2 (b a number other than -1) 1306 fn bo_div op ulong ty ulong ra ulong rb ulong rd ulong fl ulong to void 1307 if eq and fl 1 0 1308 trapsite or `3019898880` rb 2 1309 end 1310 if eq op 37 1311 t = alloc 1312 if ge ty 6 1313 e3 `2596277248` t ra rb 1314 else 1315 e3 `2596276224` t ra rb 1316 end 1317 e3 or `2600501248` shl ra 10 rd t rb 1318 ret 1319 end 1320 if lt ty 6 1321 bo_w3 `2596276224` rd ra rb 0 1322 ret 1323 end 1324 if eq ty 9 1325 if eq and fl 2 0 1326 emit or `2969568287` shl rb 5 1327 emit `1409286241` 1328 emit or `3942646783` shl ra 16 1329 trapc 6 1 1330 end 1331 end 1332 bo_w3 `2596277248` rd ra rb 0 1333 if ne ty 9 1334 bo_fix rd ty 1335 end 1336 end 1337 1338 note and, or, xor (om4 BO_LOG) 1339 fn bo_log op ulong ra ulong rb ulong rd ulong to void 1340 fx = ulong `2315255808` 1341 if eq op 39 1342 fx = ulong `2852126720` 1343 end 1344 if eq op 40 1345 fx = ulong `3388997632` 1346 end 1347 bo_w3 fx rd ra rb 0 1348 end 1349 1350 note bo_lsl: LSL Xd, Xn, #s as UBFM Xd, Xn, #(64-s) mod 64, #63-s 1351 fn bo_lsl ra ulong s ulong rd ulong to void 1352 r = shl and sub 64 s 63 16 1353 r = or r shl sub 63 s 10 1354 r = or r shl ra 5 1355 emit or or `3544186880` r rd 1356 end 1357 1358 note shl (om4 BO_SHL, BS_64): by a number s: UBFM Xd, Xn, #(64-s) mod 64, #63-s; by a register: the amount 1359 note check, LSLV; i64: t = a << s, X16 = t >> s arithmetic, CMP X16, Xa, B.NE trap 1, MOV Xd, Xt 1360 fn bo_shl ty ulong ra ulong rb ulong imm ulong rd ulong to void 1361 if eq ty 9 1362 t = alloc 1363 if ne imm 0 1364 bo_lsl ra rb t 1365 emit or or `2470509584` shl rb 16 shl t 5 1366 else 1367 bo_schk ty rb 1368 e3 `2596282368` t ra rb 1369 e3 `2596284432` 0 t rb 1370 end 1371 emit or `3942646303` shl ra 16 1372 trapc 1 1 1373 emit or or `2852127712` rd shl t 16 1374 ret 1375 end 1376 if ne imm 0 1377 bo_lsl ra rb rd 1378 bo_fix rd ty 1379 ret 1380 end 1381 bo_schk ty rb 1382 if eq ty 4 1383 bo_w3 `448798720` rd ra rb 0 1384 ret 1385 end 1386 bo_w3 `2596282368` rd ra rb 0 1387 bo_fix rd ty 1388 end 1389 1390 note shr: unsigned LSR, signed ASR; by a number UBFM / SBFM Xd, Xn, #s, #63; by a register the amount check 1391 note then LSRV / ASRV (om4 BO_SHR) 1392 fn bo_shr ty ulong ra ulong rb ulong imm ulong rd ulong to void 1393 if ne imm 0 1394 fi = ulong `3544251392` 1395 if ge ty 6 1396 fi = ulong `2470509568` 1397 end 1398 emit or or or fi shl rb 16 shl ra 5 rd 1399 ret 1400 end 1401 bo_schk ty rb 1402 fx = ulong `2596283392` 1403 if ge ty 6 1404 fx = ulong `2596284416` 1405 end 1406 bo_w3 fx rd ra rb 0 1407 end 1408 1409 note comparisons: CMP Xa, #imm or CMP Xa, Xb; the result is the flags and a condition (om4 BO_CMP) 1410 fn bo_cmp op ulong ty ulong ra ulong rb ulong imm ulong to void 1411 if ne imm 0 1412 emit or or `4043309087` shl rb 10 shl ra 5 1413 else 1414 emit or or `3942645791` shl rb 16 shl ra 5 1415 end 1416 i = mul sub op 43 2 1417 if ge ty 6 1418 i = add i 1 1419 end 1420 put rk 0 4 1421 put rv 0 conds i 1422 put rt 0 1 1423 end 1424 1425 note binop: op 33..48, destination (255 none), ix the fr slot of a (kind, number/register, type) then b. 1426 note Result in rk/rv/rt. om4 BINOP. 1427 fn binop op ulong dst ulong ix ulong to void 1428 ty = get fr add ix 2 1429 ra = matreg get fr ix get fr add ix 1 ty 1430 imm = ulong 0 1431 bk = get fr add ix 3 1432 bn = get fr add ix 4 1433 rb = ulong 0 1434 useimm = false 1435 if eq bk 3 1436 if or eq op 41 eq op 42 1437 if lt bn twid ty 1438 useimm = true 1439 end 1440 else 1441 if or lt op 35 ge op 43 1442 if le bn 4095 1443 useimm = true 1444 end 1445 end 1446 end 1447 end 1448 if useimm 1449 rb = bn 1450 imm = ulong 1 1451 else 1452 rb = matreg bk bn get fr add ix 5 1453 end 1454 if ge op 43 1455 bo_cmp op ty ra rb imm 1456 ret 1457 end 1458 if eq ty 1 1459 if gt sub op 38 2 1460 fail 7 1461 end 1462 end 1463 rd = destreg dst 1464 if lt op 35 1465 bo_add op ty ra rb imm rd 1466 else 1467 if eq op 35 1468 bo_mul ty ra rb rd 1469 else 1470 if lt op 38 1471 fl = ulong 0 1472 if and eq bk 3 ne bn 0 1473 fl = or fl 1 1474 end 1475 if and eq bk 3 ne bn `18446744073709551615` 1476 fl = or fl 2 1477 end 1478 bo_div op ty ra rb rd fl 1479 else 1480 if lt op 41 1481 bo_log op ra rb rd 1482 else 1483 if eq op 41 1484 bo_shl ty ra rb imm rd 1485 else 1486 bo_shr ty ra rb imm rd 1487 end 1488 end 1489 end 1490 end 1491 end 1492 put rk 0 1 1493 put rv 0 rd 1494 put rt 0 ty 1495 end 1496 1497 note ======== calls: registers saved around a call and loaded back ======== 1498 global svn ulong 1 1499 global sva ulong 1 1500 note save: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A 1501 note (C6.2.457); the stack check; STR Xr, [SP, #8j] for each (C6.2.415); STR X30, [SP, #8n]. Out: svn n, 1502 note sva A. om4 SAVE. 1503 fn save to void 1504 n = add get npar 0 get nslot 0 1505 a = shl shr add n 2 1 4 1506 put svn 0 n 1507 put sva 0 a 1508 spsub a 1509 stkchk 1510 j = ulong 0 1511 while lt j n 1512 emit or or `4177527776` poolc j shl j 10 1513 j = add j 1 1514 end 1515 emit or `4177527806` shl n 10 1516 end 1517 1518 note loadarg: register t from an argument: kind 1 or 5 a register v, read back from its save slot (LDR Xt, 1519 note [SP, #8 slot], C6.2.216); kind 3 or 6 the number or address v. om4 LOADARG. 1520 fn loadarg t ulong k ulong v ulong to void 1521 if or eq k 3 eq k 6 1522 matconst t v 1523 ret 1524 end 1525 emit or or `4181722080` t shl regidx v 10 1526 end 1527 1528 note basearg: register t = the base of array name e (index + 1): its register from the save area, or its 1529 note address. om4 BASEARG. 1530 fn basearg t ulong e ulong to void 1531 i = sub e 1 1532 if ge get nm_kind i 4 1533 matconst t get nm_addr i 1534 ret 1535 end 1536 loadarg t 1 ulong get nm_reg i 1537 end 1538 1539 note restore: d destination (255: a new temporary at pool slot `slot`), slot the pool slot before the 1540 note arguments, n saved count, a save bytes, res 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR 1541 note each register in use before the arguments except Xd (C6.2.216); LDR X30; ADD SP, SP, #A (C6.2.5). 1542 note Returns Xd (255 when no result). om4 RESTORE. 1543 fn restore d ulong slot ulong n ulong a ulong res ulong to ulong 1544 put nslot 0 slot 1545 rd = ulong 255 1546 if ne res 0 1547 rd = d 1548 if eq d 255 1549 rd = alloc 1550 end 1551 if ne rd 0 1552 emit or `2852127712` rd 1553 end 1554 end 1555 m = add get npar 0 slot 1556 j = ulong 0 1557 while lt j m 1558 r = poolc j 1559 if ne r rd 1560 emit or or `4181722080` r shl j 10 1561 end 1562 j = add j 1 1563 end 1564 emit or `4181722110` shl n 10 1565 spadd a 1566 ret rd 1567 end 1568 1569 note ca_bl: BL to function f (index + 1), C6.2.43 1570 fn ca_bl f ulong to void 1571 n = get ncalls 0 1572 if ge n 65536 1573 fail 14 1574 end 1575 put callsite n get oc 0 1576 put callfrom n get curfn 0 1577 put callto n f 1578 put ncalls 0 add n 1 1579 1580 emit or `2483027968` and shr sub get fn_addr sub f 1 get oc 0 2 `67108863` 1581 end 1582 1583 note ======== element addresses and array arguments ======== 1584 global ea_b ulong 1 1585 global ea_i ulong 1 1586 note elemaddr: array name e (index + 1), index value (kind, number or register, type). A number index must 1587 note be inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi, 1588 note Xt (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: ea_b base register 1589 note (the array's register, or a new one holding its address), ea_i index register. om4 ELEMADDR. 1590 fn elemaddr e ulong k ulong v ulong t ulong to void 1591 if eq t 1 1592 fail 7 1593 end 1594 i = sub e 1 1595 ln = get nm_len i 1596 x = v 1597 if eq k 3 1598 if ge v ln 1599 fail 21 1600 end 1601 x = alloc 1602 matconst x v 1603 else 1604 if le ln 4095 1605 emit or or `4043309087` shl ln 10 shl v 5 1606 else 1607 y = alloc 1608 matconst y ln 1609 emit or or `3942645791` shl y 16 shl v 5 1610 end 1611 trapc 2 3 1612 end 1613 put ea_i 0 x 1614 if ge get nm_kind i 4 1615 b = alloc 1616 matconst b get nm_addr i 1617 put ea_b 0 b 1618 else 1619 put ea_b 0 ulong get nm_reg i 1620 end 1621 end 1622 1623 note aa_word: the next word of an array argument must be a name of at most 8 bytes 1624 fn aa_word to void 1625 tok 1626 k = get tk 0 1627 if eq k 0 1628 fail 4 1629 end 1630 if ne k 1 1631 fail 16 1632 end 1633 if gt get tl 0 8 1634 fail 13 1635 end 1636 end 1637 1638 note arrarg: an array argument for parameter pi of function f (index + 1): [view | edit] NAME. Its type and 1639 note length must equal the parameter's; an edit parameter needs a writable array (local or edit, error 20; 1640 note a view passed to it is error 20, OMEGESE.md 9.4); a global is never passed (error 19). Out: rk 5 1641 note (register rv) or 6 (address rv, a text), rt the name entry. om4 ARRARG. 1642 fn arrarg f ulong pi ulong to void 1643 md = ulong 0 1644 aa_word 1645 w = get tw 0 1646 c = kw w 1647 if ne c 0 1648 if or lt c 57 gt c 58 1649 fail 16 1650 end 1651 md = c 1652 aa_word 1653 w = get tw 0 1654 end 1655 e = findname w 1656 if eq e 0 1657 fail 3 1658 end 1659 i = sub e 1 1660 k = ulong get nm_kind i 1661 if eq k 0 1662 fail 7 1663 end 1664 if eq k 4 1665 fail 19 1666 end 1667 p = add mul sub f 1 6 pi 1668 if eq get fn_pk p 3 1669 if eq md 57 1670 fail 20 1671 end 1672 if and ne k 1 ne k 3 1673 fail 20 1674 end 1675 else 1676 if eq md 58 1677 fail 7 1678 end 1679 end 1680 if ne get nm_type i get fn_pt p 1681 fail 7 1682 end 1683 if ne get nm_len i get fn_pl p 1684 fail 7 1685 end 1686 put rt 0 e 1687 if eq k 5 1688 put rk 0 6 1689 put rv 0 get nm_addr i 1690 else 1691 put rk 0 5 1692 put rv 0 ulong get nm_reg i 1693 end 1694 end 1695 1696 note ======== the parts of the value reader that read no further value ======== 1697 fn vdec to void 1698 put depth 0 sub get depth 0 1 1699 end 1700 1701 note vdone: a value's result, and one nesting level less (om4 VT_RET) 1702 fn vdone k ulong v ulong t ulong to void 1703 put rk 0 k 1704 put rv 0 v 1705 put rt 0 t 1706 vdec 1707 end 1708 1709 note vt_un: neg / not of the value in rk/rv/rt (a bare number already refused). neg: NEG Xd, Xm (SUB from 1710 note XZR, C6.2.458; the 32-bit form for u32), i64 NEGS + B.VS trap 1 (C6.2.465), then the wrap or the 1711 note sign check; not: bool EOR Xd, Xn, #1 (C6.2.155), else MVN (ORN from XZR, C6.2.300), then the wrap. 1712 note om4 VU1 .. VU_E. 1713 fn vt_un c ulong dst ulong to void 1714 ty = get rt 0 1715 ra = matreg get rk 0 get rv 0 ty 1716 rd = destreg dst 1717 if eq c 50 1718 if eq ty 1 1719 e3 `3527409664` rd ra 0 1720 else 1721 if eq ty 4 1722 e3 `706741216` rd 0 ra 1723 else 1724 e3 `2854224864` rd 0 ra 1725 if lt ty 6 1726 canon rd ty 1727 end 1728 end 1729 end 1730 else 1731 if eq ty 1 1732 fail 7 1733 end 1734 if eq ty 9 1735 e3 `3942646752` rd 0 ra 1736 trapc 6 1 1737 else 1738 if eq ty 4 1739 e3 `1258292192` rd 0 ra 1740 else 1741 e3 `3405775840` rd 0 ra 1742 if lt ty 6 1743 canon rd ty 1744 else 1745 chkext rd ty 1 1746 end 1747 end 1748 end 1749 end 1750 put rk 0 1 1751 put rv 0 rd 1752 put rt 0 ty 1753 end 1754 1755 note vt_conv: the value in rk/rv/rt converted to type tt (neither bool, error 9). Out of range when any bit 1756 note at or above s is set: LSR Xt, Xa, #s (UBFM, C6.2.487); CBNZ Xt trap 5 (C6.2.77); signed to a narrower 1757 note signed type: the sign-extension check, trap 5. om4 VTT1 .. VC_OK. 1758 fn vt_conv tt ulong to void 1759 ft = get rt 0 1760 ra = matreg get rk 0 get rv 0 ft 1761 if eq ft 1 1762 fail 9 1763 end 1764 if eq tt 1 1765 fail 9 1766 end 1767 wf = twid ft 1768 wt = twid tt 1769 s = ulong 99 1770 if lt ft 6 1771 if ge tt 6 1772 if ge wf wt 1773 s = sub wt 1 1774 end 1775 else 1776 if gt wf wt 1777 s = wt 1778 end 1779 end 1780 else 1781 if lt tt 6 1782 s = wt 1783 if gt s 63 1784 s = ulong 63 1785 end 1786 else 1787 if gt wf wt 1788 chkext ra tt 5 1789 end 1790 end 1791 end 1792 if ne s 99 1793 t = alloc 1794 emit or or or `3544251392` t shl s 16 shl ra 5 1795 trapsite or `3036676096` t 5 1796 end 1797 put rk 0 1 1798 put rv 0 ra 1799 put rt 0 tt 1800 end 1801 1802 note vt_get: get A i with the index value in rk/rv/rt: the element address, then the load of the element 1803 note type, register offset (LDOP table). om4 VT_GET. 1804 fn vt_get e ulong dst ulong to void 1805 elemaddr e get rk 0 get rv 0 get rt 0 1806 rd = destreg dst 1807 ty = ulong get nm_type sub e 1 1808 w = or ldop ty rd 1809 emit or or w shl get ea_b 0 5 shl get ea_i 0 16 1810 put rk 0 1 1811 put rv 0 rd 1812 put rt 0 ty 1813 end 1814 1815 note vs_chk: read / write bounds: n <= len A and off <= len A - n, else trap 3 (CMP C6.2.97, B.HI C6.2.34, 1816 note SUB C6.2.458). om4 VT_SYS. 1817 fn vs_chk e ulong ro ulong rn ulong to void 1818 t = alloc 1819 matconst t get nm_len sub e 1 1820 emit or or `3942645791` shl rn 5 shl t 16 1821 trapc 8 3 1822 e3 `3405774848` t t rn 1823 emit or or `3942645791` shl ro 5 shl t 16 1824 trapc 8 3 1825 end 1826 1827 note vs_call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n, X8 = 63 1828 note (read) or 64 (write) (MOVZ C6.2.285), SVC #0 (C6.2.466). om4 VT_SYS. 1829 fn vs_call c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void 1830 save 1831 loadarg 0 fk fv 1832 basearg 1 e 1833 loadarg 16 1 ro 1834 emit `2333081633` 1835 loadarg 2 1 rn 1836 emit or `3531603976` shl add c 10 5 1837 emit `3556769793` 1838 end 1839 1840 note ca_scal: a scalar argument just read (rk/rv/rt) for parameter p: flags into a register; its type 1841 note must be the parameter's; stored at fr[q..q+2]. om4 CA1 .. CA_PUT. 1842 fn ca_scal p ulong q ulong to void 1843 if eq get rk 0 4 1844 put rv 0 matreg 4 get rv 0 get rt 0 1845 put rk 0 1 1846 put rt 0 1 1847 end 1848 if ne get rt 0 ulong get fn_pt p 1849 fail 7 1850 end 1851 put fr q get rk 0 1852 put fr add q 1 get rv 0 1853 put fr add q 2 0 1854 end 1855 1856 note ca_arr: an array argument i of function f, call frame cb: one array passed twice is error 19. 1857 note om4 CA_ARR .. CA_PUT. 1858 fn ca_arr f ulong i ulong cb ulong to void 1859 arrarg f i 1860 j = ulong 0 1861 while lt j i 1862 if eq get fr add add cb mul j 3 2 get rt 0 1863 fail 19 1864 end 1865 j = add j 1 1866 end 1867 q = add cb mul i 3 1868 put fr q get rk 0 1869 put fr add q 1 get rv 0 1870 put fr add q 2 get rt 0 1871 end 1872 1873 note ca_end: all arguments read: save, the arguments into X0.., BL, restore. Frame cb: 3 per argument, 1874 note then cb+18 the parameter count, cb+19 the pool slot before the arguments. om4 CA_DONE .. CA5. 1875 fn ca_end f ulong dst ulong cb ulong to void 1876 save 1877 np = get fr add cb 18 1878 i = ulong 0 1879 while lt i np 1880 q = add cb mul i 3 1881 loadarg i get fr q get fr add q 1 1882 i = add i 1 1883 end 1884 ca_bl f 1885 hr = ulong 1 1886 if eq get fn_ret sub f 1 10 1887 hr = ulong 0 1888 end 1889 n = get svn 0 1890 a = get sva 0 1891 sl = get fr add cb 19 1892 r = restore dst sl n a hr 1893 put rk 0 1 1894 put rv 0 r 1895 put rt 0 ulong get fn_ret sub f 1 1896 end 1897 1898 note vs_fd, vs_arr, vs_off, vs_end: the steps of read / write between the values it reads, with the fd 1899 note (kind, value), the offset register and the pool slot before kept in fr[x+8..x+11] (om4's VT_SYS 1900 note frame slots 4, 5, 7 and 14) 1901 fn vs_fd x ulong to void 1902 if ne get rt 0 8 1903 fail 7 1904 end 1905 put fr add x 9 get rk 0 1906 put fr add x 10 get rv 0 1907 end 1908 1909 fn vs_arr c ulong e ulong to void 1910 if eq c 53 1911 k = get nm_kind sub e 1 1912 if or eq k 2 eq k 5 1913 fail 20 1914 end 1915 end 1916 end 1917 1918 fn vs_off x ulong to void 1919 if ne get rt 0 5 1920 fail 7 1921 end 1922 put fr add x 11 matreg get rk 0 get rv 0 get rt 0 1923 end 1924 1925 fn vs_end c ulong e ulong dst ulong x ulong to void 1926 if ne get rt 0 5 1927 fail 7 1928 end 1929 rn = matreg get rk 0 get rv 0 get rt 0 1930 ro = get fr add x 11 1931 vs_chk e ro rn 1932 fk = get fr add x 9 1933 fv = get fr add x 10 1934 vs_call c fk fv e ro rn 1935 sl = get fr add x 8 1936 n = get svn 0 1937 a = get sva 0 1938 r = restore dst sl n a 1 1939 vdone 1 r 9 1940 end 1941 1942 note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2. 1943 note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h. 1944 note No raw address or arbitrary syscall is exposed to an Omega program. 1945 fn hargc c ulong to ulong 1946 if or or eq c 107 eq c 109 eq c 129 1947 ret 0 1948 end 1949 if or eq c 100 eq c 101 1950 ret 1 1951 end 1952 if or or or eq c 102 eq c 105 eq c 106 eq c 127 1953 ret 2 1954 end 1955 ret 3 1956 end 1957 fn hsysno c ulong to ulong 1958 if eq c 127 1959 ret 129 1960 end 1961 if eq c 129 1962 ret 172 1963 end 1964 if eq c 100 1965 ret 57 1966 end 1967 if eq c 101 1968 ret 82 1969 end 1970 if eq c 102 1971 ret 52 1972 end 1973 if eq c 103 1974 ret 62 1975 end 1976 if eq c 104 1977 ret 198 1978 end 1979 if eq c 105 1980 ret 201 1981 end 1982 if eq c 106 1983 ret 242 1984 end 1985 if eq c 107 1986 ret 220 1987 end 1988 ret 24 1989 end 1990 fn harg x ulong i ulong ty ulong to void 1991 rdval 0 ty 255 0 1992 if ne get rt 0 ty 1993 fail 7 1994 end 1995 q = add add x 8 mul i 2 1996 put fr q get rk 0 1997 put fr add q 1 get rv 0 1998 end 1999 fn hload x ulong i ulong reg ulong to void 2000 q = add add x 8 mul i 2 2001 loadarg reg get fr q get fr add q 1 2002 end 2003 fn hsys n ulong to void 2004 matconst 8 n 2005 emit `3556769793` 2006 end 2007 fn hreturn dst ulong x ulong to void 2008 sl = get fr add x 7 2009 n = get svn 0 2010 a = get sva 0 2011 r = restore dst sl n a 1 2012 vdone 1 r 9 2013 end 2014 fn hscalar c ulong dst ulong x ulong to void 2015 np = hargc c 2016 for i ulong np 2017 ty = ulong 8 2018 if and eq c 103 eq i 1 2019 ty = ulong 9 2020 end 2021 harg x i ty 2022 end 2023 save 2024 for i ulong np 2025 hload x i i 2026 end 2027 if eq c 106 2028 hload x 1 3 2029 matconst 1 0 2030 matconst 2 0 2031 end 2032 if eq c 107 2033 matconst 0 17 2034 for i ulong 5 2035 matconst add i 1 0 2036 end 2037 end 2038 hsys hsysno c 2039 hreturn dst x 2040 end 2041 fn hclock c ulong dst ulong x ulong to void 2042 save 2043 spsub 16 2044 stkchk 2045 matconst 0 1 2046 if eq c 130 2047 matconst 0 0 2048 end 2049 emit `2432697313` 2050 hsys 113 2051 emit `4043309087` 2052 bad = get oc 0 2053 emit `1409286155` 2054 emit `4181722081` 2055 emit `4181723106` 2056 note Reject overflow before seconds are multiplied; clock result is a signed nanosecond count. 2057 matconst 3 `9223372036` 2058 e3 `3942645760` 31 1 3 2059 trapc 8 1 2060 matconst 3 `1000000000` 2061 e3 `2600500224` 1 1 3 2062 e3 `2868903936` 0 1 2 2063 trapc 6 1 2064 patch19 bad get oc 0 2065 spadd 16 2066 hreturn dst x 2067 end 2068 fn harray x ulong writable ulong to ulong 2069 e = arrname 2070 if ne get nm_type sub e 1 2 2071 fail 7 2072 end 2073 if ne writable 0 2074 vs_arr 53 e 2075 end 2076 put fr add x 20 e 2077 harg x 0 5 2078 harg x 1 5 2079 ro = matreg get fr add x 8 get fr add x 9 5 2080 rn = matreg get fr add x 10 get fr add x 11 5 2081 put fr add x 21 ro 2082 put fr add x 22 rn 2083 vs_chk e ro rn 2084 ret e 2085 end 2086 note Copy a checked path to a private 4096-byte stack buffer. Reject embedded zero bytes. 2087 note Public paths remain length-delimited; only the kernel-facing private copy has a terminator. 2088 fn hpathcp x ulong to void 2089 e = get fr add x 20 2090 save 2091 basearg 4 e 2092 loadarg 16 1 get fr add x 21 2093 e3 `2332033024` 4 4 16 2094 loadarg 5 1 get fr add x 22 2095 matconst 6 4095 2096 e3 `3942645760` 31 5 6 2097 trapc 8 3 2098 end 2099 fn hcopy to void 2100 spsub 4096 2101 stkchk 2102 emit `2432697313` 2103 head = get oc 0 2104 emit `4043309247` 2105 done = get oc 0 2106 emit `1409286144` 2107 emit `960495750` 2108 emit `4043309279` 2109 trapc 0 3 2110 emit `956301350` 2111 emit `2432697476` 2112 emit `2432697377` 2113 emit `3506439333` 2114 back head 2115 patch19 done get oc 0 2116 emit `956301375` 2117 emit `2432697313` 2118 matconst 0 `18446744073709551516` 2119 end 2120 fn hpath c ulong dst ulong x ulong to void 2121 e = harray x 0 2122 if eq c 110 2123 harg x 2 8 2124 harg x 3 8 2125 end 2126 if eq c 112 2127 harg x 2 8 2128 end 2129 hpathcp x 2130 if eq c 110 2131 hload x 2 2 2132 hload x 3 3 2133 end 2134 if eq c 111 2135 matconst 2 0 2136 end 2137 if eq c 126 2138 matconst 2 512 2139 end 2140 if eq c 112 2141 hload x 2 2 2142 end 2143 hcopy 2144 nr = ulong 56 2145 if or eq c 111 eq c 126 2146 nr = ulong 35 2147 end 2148 if eq c 112 2149 nr = ulong 34 2150 end 2151 hsys nr 2152 spadd 4096 2153 hreturn dst x 2154 end 2155 fn hbuffer c ulong dst ulong x ulong to void 2156 harg x 4 8 2157 wr = ulong 0 2158 if or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 2159 wr = ulong 1 2160 end 2161 e = harray x wr 2162 if or or eq c 116 eq c 118 eq c 119 2163 harg x 2 8 2164 end 2165 if or eq c 116 eq c 117 2166 need = ulong 4 2167 if eq c 117 2168 need = ulong 128 2169 end 2170 tmp = alloc 2171 matconst tmp need 2172 e3 `3942645760` 31 get fr add x 22 tmp 2173 trapc 3 3 2174 end 2175 save 2176 hload x 4 0 2177 basearg 1 e 2178 loadarg 16 1 get fr add x 21 2179 e3 `2332033024` 1 1 16 2180 loadarg 2 1 get fr add x 22 2181 nr = ulong 61 2182 if eq c 114 2183 nr = ulong 203 2184 end 2185 if eq c 115 2186 nr = ulong 200 2187 end 2188 if eq c 116 2189 nr = ulong 260 2190 hload x 2 2 2191 matconst 3 0 2192 end 2193 if eq c 117 2194 nr = ulong 80 2195 end 2196 if or eq c 118 eq c 119 2197 nr = ulong 207 2198 hload x 2 3 2199 matconst 4 0 2200 matconst 5 0 2201 if eq c 119 2202 nr = ulong 206 2203 matconst 16 16384 2204 e3 `2852126720` 3 3 16 2205 end 2206 end 2207 2208 if eq c 131 2209 note getsockname uses a private 32-bit socklen. Success returns the full address length. 2210 spsub 16 2211 stkchk 2212 emit `3103785954` 2213 emit `2432697314` 2214 hsys 204 2215 emit `4043309087` 2216 failed = get oc 0 2217 emit `1409286155` 2218 emit `3107980256` 2219 patch19 failed get oc 0 2220 spadd 16 2221 else 2222 hsys nr 2223 end 2224 hreturn dst x 2225 end 2226 fn hsleep dst ulong x ulong to void 2227 harg x 0 9 2228 save 2229 hload x 0 2 2230 emit `4043309151` 2231 trapc 11 3 2232 spsub 16 2233 stkchk 2234 matconst 3 `1000000000` 2235 e3 `2596276224` 4 2 3 2236 note MSUB x5,x4,x3,x2 gives the subsecond remainder. 2237 emit `2600700037` 2238 emit `4177527780` 2239 emit `4177528805` 2240 emit `2432697312` 2241 matconst 1 0 2242 hsys 101 2243 spadd 16 2244 hreturn dst x 2245 end 2246 fn hargs c ulong dst ulong x ulong to void 2247 if eq c 121 2248 save 2249 emit `4181721952` 2250 hreturn dst x 2251 ret 2252 end 2253 harg x 4 5 2254 e = harray x 1 2255 save 2256 hload x 4 0 2257 emit `4181721953` 2258 e3 `3942645760` 31 0 1 2259 trapc 2 3 2260 emit `2432697344` 2261 matconst 16 8 2262 e3 `2600500224` 0 0 16 2263 e3 `2332033024` 3 27 0 2264 emit `4181721187` 2265 e3 `2852126720` 4 31 3 2266 matconst 5 0 2267 scan = get oc 0 2268 emit `960495750` 2269 emit `4043309279` 2270 done = get oc 0 2271 emit `1409286144` 2272 emit `2432697476` 2273 emit `2432697509` 2274 matconst 16 `1048576` 2275 e3 `3942645760` 31 5 16 2276 trapc 2 3 2277 back scan 2278 patch19 done get oc 0 2279 loadarg 2 1 get fr add x 22 2280 e3 `3942645760` 31 5 2 2281 small = get oc 0 2282 emit `1409286152` 2283 basearg 0 e 2284 loadarg 16 1 get fr add x 21 2285 e3 `2332033024` 0 0 16 2286 e3 `2852126720` 2 31 5 2287 copy = get oc 0 2288 emit `4043309247` 2289 endcp = get oc 0 2290 emit `1409286144` 2291 emit `960495718` 2292 emit `956301318` 2293 emit `2432697443` 2294 emit `2432697344` 2295 emit `3506439333` 2296 back copy 2297 patch19 endcp get oc 0 2298 e3 `2852126720` 0 31 2 2299 endbr = get oc 0 2300 emit `335544320` 2301 patch19 small get oc 0 2302 matconst 0 `18446744073709551511` 2303 patch26 endbr get oc 0 2304 hreturn dst x 2305 end 2306 2307 note waitio(fd int, events int, timeout_ns long): revents, 0 timeout, or negative errno. 2308 note ppoll uses one private pollfd and one private timespec. Negative timeout is infinite. 2309 fn hwaitio dst ulong x ulong to void 2310 harg x 0 8 2311 harg x 1 8 2312 harg x 2 9 2313 save 2314 hload x 0 0 2315 hload x 1 1 2316 hload x 2 2 2317 note pollfd.events is 16 bits; refuse truncation of the public int argument. 2318 emit `4043309119` 2319 trapc 11 3 2320 matconst 16 65535 2321 e3 `3942645760` 31 1 16 2322 trapc 8 3 2323 spsub 32 2324 stkchk 2325 emit `4177527807` 2326 emit `3103785952` 2327 emit `2030046177` 2328 matconst 3 `1000000000` 2329 emit `4043309151` 2330 forever = get oc 0 2331 emit `1409286155` 2332 e3 `2596276224` 4 2 3 2333 emit `2600700037` 2334 emit `4177528804` 2335 emit `4177529829` 2336 emit `2432705506` 2337 jump = get oc 0 2338 emit `335544320` 2339 patch19 forever get oc 0 2340 matconst 2 0 2341 patch26 jump get oc 0 2342 emit `2432697312` 2343 matconst 1 1 2344 matconst 3 0 2345 matconst 4 8 2346 hsys 73 2347 emit `4043309087` 2348 failed = get oc 0 2349 emit `1409286157` 2350 emit `2034241504` 2351 patch19 failed get oc 0 2352 spadd 32 2353 hreturn dst x 2354 end 2355 2356 note A packed argument list is u16 count followed by count (u16 length, bytes) records. 2357 note Byte order is little-endian. The packet is at most 4096 bytes and 64 records. 2358 note The decoder constructs kernel pointers only in private stack memory. 2359 fn hpack c ulong dst ulong x ulong to void 2360 e = harray x 0 2361 if eq c 125 2362 harg x 2 8 2363 end 2364 save 2365 basearg 4 e 2366 loadarg 16 1 get fr add x 21 2367 e3 `2332033024` 4 4 16 2368 loadarg 5 1 get fr add x 22 2369 matconst 16 4096 2370 e3 `3942645760` 31 5 16 2371 trapc 8 3 2372 emit `4043311295` 2373 trapc 3 3 2374 if eq c 125 2375 hload x 2 14 2376 end 2377 spsub 8192 2378 stkchk 2379 emit `2034237574` 2380 emit `2432698500` 2381 emit `3506440357` 2382 emit `4043309279` 2383 trapc 0 3 2384 matconst 16 64 2385 e3 `3942645760` 31 6 16 2386 trapc 8 3 2387 if eq c 125 2388 emit `4043311327` 2389 trapc 1 3 2390 end 2391 matconst 9 0 2392 emit `2432697322` 2393 emit `2436892651` 2394 outer = get oc 0 2395 e3 `3942645760` 31 9 6 2396 done = get oc 0 2397 emit `1409286146` 2398 emit `4043311295` 2399 trapc 3 3 2400 emit `2034237580` 2401 emit `2432698500` 2402 emit `3506440357` 2403 e3 `3942645760` 31 12 5 2404 trapc 8 3 2405 note A program path and both rename paths must be nonempty. 2406 if eq c 124 2407 emit `4043309375` 2408 notfirst = get oc 0 2409 emit `1409286145` 2410 emit `4043309471` 2411 trapc 0 3 2412 patch19 notfirst get oc 0 2413 else 2414 emit `4043309471` 2415 trapc 0 3 2416 end 2417 emit `4177527146` 2418 emit `2432704875` 2419 inner = get oc 0 2420 emit `4043309471` 2421 endstr = get oc 0 2422 emit `1409286144` 2423 emit `960495757` 2424 emit `4043309503` 2425 trapc 0 3 2426 emit `956301645` 2427 emit `2432697476` 2428 emit `2432697674` 2429 emit `3506439333` 2430 emit `3506439564` 2431 back inner 2432 patch19 endstr get oc 0 2433 emit `956301663` 2434 emit `2432697674` 2435 emit `2432697641` 2436 back outer 2437 patch19 done get oc 0 2438 emit `4043309247` 2439 trapc 1 3 2440 emit `4177527167` 2441 if eq c 124 2442 emit `2432697312` 2443 emit `2436892641` 2444 e3 `2852126720` 2 31 11 2445 hsys 221 2446 else 2447 emit `2436892656` 2448 emit `4181721601` 2449 emit `4181722627` 2450 matconst 0 `18446744073709551516` 2451 matconst 2 `18446744073709551516` 2452 e3 `2852126720` 4 31 14 2453 hsys 276 2454 end 2455 spadd 8192 2456 hreturn dst x 2457 end 2458 fn hpipe dst ulong x ulong to void 2459 e = harray x 1 2460 harg x 2 8 2461 tmp = alloc 2462 matconst tmp 8 2463 e3 `3942645760` 31 get fr add x 22 tmp 2464 trapc 3 3 2465 save 2466 basearg 0 e 2467 loadarg 16 1 get fr add x 21 2468 e3 `2332033024` 0 0 16 2469 hload x 2 1 2470 hsys 59 2471 hreturn dst x 2472 end 2473 2474 fn hcwd dst ulong x ulong to void 2475 e = harray x 1 2476 save 2477 basearg 0 e 2478 loadarg 16 1 get fr add x 21 2479 e3 `2332033024` 0 0 16 2480 loadarg 1 1 get fr add x 22 2481 hsys 17 2482 hreturn dst x 2483 end 2484 fn hreadlnk dst ulong x ulong to void 2485 e = harray x 0 2486 put fr add x 23 e 2487 put fr add x 24 get fr add x 21 2488 put fr add x 25 get fr add x 22 2489 e = harray x 1 2490 put fr add x 26 e 2491 put fr add x 27 get fr add x 21 2492 put fr add x 28 get fr add x 22 2493 put fr add x 20 get fr add x 23 2494 put fr add x 21 get fr add x 24 2495 put fr add x 22 get fr add x 25 2496 hpathcp x 2497 note readlnk refuses an empty path before the kernel call. 2498 emit `4043309247` 2499 trapc 0 3 2500 basearg 2 get fr add x 26 2501 loadarg 16 1 get fr add x 27 2502 e3 `2332033024` 2 2 16 2503 loadarg 3 1 get fr add x 28 2504 hcopy 2505 hsys 78 2506 spadd 4096 2507 hreturn dst x 2508 end 2509 fn hsockopt dst ulong x ulong to void 2510 harg x 2 8 2511 harg x 3 8 2512 harg x 4 8 2513 e = harray x 0 2514 save 2515 hload x 2 0 2516 hload x 3 1 2517 hload x 4 2 2518 basearg 3 e 2519 loadarg 16 1 get fr add x 21 2520 e3 `2332033024` 3 3 16 2521 loadarg 4 1 get fr add x 22 2522 hsys 208 2523 hreturn dst x 2524 end 2525 2526 fn hostval c ulong dst ulong to void 2527 if eq get progmode 0 0 2528 fail 9 2529 end 2530 x = mul get depth 0 32 2531 put fr add x 7 get nslot 0 2532 if eq c 132 2533 hcwd dst x 2534 ret 2535 end 2536 if eq c 133 2537 hreadlnk dst x 2538 ret 2539 end 2540 if eq c 134 2541 hsockopt dst x 2542 ret 2543 end 2544 if or eq c 109 eq c 130 2545 hclock c dst x 2546 ret 2547 end 2548 if or and ge c 113 le c 119 eq c 131 2549 hbuffer c dst x 2550 ret 2551 end 2552 if eq c 120 2553 hsleep dst x 2554 ret 2555 end 2556 if eq c 123 2557 hwaitio dst x 2558 ret 2559 end 2560 if or eq c 124 eq c 125 2561 hpack c dst x 2562 ret 2563 end 2564 if eq c 126 2565 hpath c dst x 2566 ret 2567 end 2568 if or eq c 127 eq c 129 2569 hscalar c dst x 2570 ret 2571 end 2572 if eq c 128 2573 hpipe dst x 2574 ret 2575 end 2576 if ge c 121 2577 put hostargs 0 1 2578 hargs c dst x 2579 ret 2580 end 2581 if ge c 110 2582 hpath c dst x 2583 ret 2584 end 2585 hscalar c dst x 2586 end 2587 2588 note ======== rdval: read one value (om4 VAL, VALTOK, CALL and the VT_ parts, one self-recursive 2589 note function because a function calls only earlier functions or itself) ======== 2590 note mode 0: read the first word; 1: the first word is the current token; 2: a call of function fe (index 2591 note + 1), its arguments still to read. exp the expected type (0 none), dst the destination register (255 2592 note none). Out: rk kind (1 register, 2 bare number, 3 typed number, 4 flags), rv register / number / 2593 note condition, rt type (for a bare number: 1 when written as 2^63 or more). Only the outermost op writes the 2594 note destination. Every value nests one level deeper (at most 1024, error 14); a call does not. 2595 fn rdval mode ulong exp ulong dst ulong fe ulong to void 2596 if eq mode 2 2597 cb = add mul get depth 0 32 8 2598 put fr add cb 18 ulong get fn_np sub fe 1 2599 put fr add cb 19 get nslot 0 2600 if eq get progmode 0 0 2601 if eq get curfn 0 fe 2602 fail 9 2603 end 2604 end 2605 i = ulong 0 2606 while lt i get fr add cb 18 2607 p = add mul sub fe 1 6 i 2608 if eq get fn_pk p 0 2609 rdval 0 ulong get fn_pt p 255 0 2610 ca_scal p add cb mul i 3 2611 else 2612 ca_arr fe i cb 2613 end 2614 i = add i 1 2615 end 2616 ca_end fe dst cb 2617 ret 2618 end 2619 if eq mode 0 2620 tok 2621 end 2622 put depth 0 add get depth 0 1 2623 if gt get depth 0 1024 2624 fail 14 2625 end 2626 if or eq get tk 0 0 eq get tk 0 3 2627 fail 4 2628 end 2629 if eq get tk 0 4 2630 fail 16 2631 end 2632 if eq get tk 0 2 2633 if eq exp 0 2634 vdone 2 get tw 0 get tbig 0 2635 ret 2636 end 2637 range get tw 0 exp get tbig 0 2638 vdone 3 get tw 0 exp 2639 ret 2640 end 2641 if gt get tl 0 8 2642 f = findfn get tw 0 get tl 0 get ts 0 2643 if eq f 0 2644 fail 13 2645 end 2646 if eq get fn_ret sub f 1 10 2647 fail 7 2648 end 2649 rdval 2 0 dst f 2650 vdec 2651 ret 2652 end 2653 c = kw get tw 0 2654 if eq c 0 2655 e = findname get tw 0 2656 if ne e 0 2657 if ne get nm_kind sub e 1 0 2658 fail 7 2659 end 2660 vdone 1 ulong get nm_reg sub e 1 ulong get nm_type sub e 1 2661 ret 2662 end 2663 f = findfn get tw 0 0 0 2664 if eq f 0 2665 fail 3 2666 end 2667 if eq get fn_ret sub f 1 10 2668 fail 7 2669 end 2670 rdval 2 0 dst f 2671 vdec 2672 ret 2673 end 2674 if le sub c 1 8 2675 tok 2676 if eq get tk 0 2 2677 range get tw 0 c get tbig 0 2678 vdone 3 get tw 0 c 2679 ret 2680 end 2681 rdval 1 0 255 0 2682 if eq get rk 0 2 2683 fail 11 2684 end 2685 vt_conv c 2686 vdec 2687 ret 2688 end 2689 if eq c 74 2690 rdval 0 exp dst 0 2691 tok 2692 if ne get tk 0 1 2693 fail 16 2694 end 2695 if gt get tl 0 8 2696 fail 16 2697 end 2698 if ne kw get tw 0 75 2699 fail 16 2700 end 2701 vdec 2702 ret 2703 end 2704 if eq c 77 2705 fail 9 2706 end 2707 if and ge c 100 le c 134 2708 hostval c dst 2709 ret 2710 end 2711 if eq c 51 2712 e = arrname 2713 rdval 0 5 255 0 2714 vt_get e dst 2715 vdec 2716 ret 2717 end 2718 if eq c 52 2719 e = arrname 2720 vdone 3 get nm_len sub e 1 5 2721 ret 2722 end 2723 if or eq c 53 eq c 54 2724 x = mul get depth 0 32 2725 put fr add x 8 get nslot 0 2726 rdval 0 8 255 0 2727 vs_fd x 2728 e = arrname 2729 vs_arr c e 2730 rdval 0 5 255 0 2731 vs_off x 2732 rdval 0 5 255 0 2733 vs_end c e dst x 2734 ret 2735 end 2736 if eq c 55 2737 vdone 3 1 1 2738 ret 2739 end 2740 if eq c 56 2741 vdone 3 0 1 2742 ret 2743 end 2744 if gt sub c 33 17 2745 fail 16 2746 end 2747 if ge c 49 2748 rdval 0 exp 255 0 2749 if and eq c 50 eq get rk 0 4 2750 put rv 0 xor get rv 0 1 2751 vdec 2752 ret 2753 end 2754 if eq get rk 0 2 2755 fail 11 2756 end 2757 vt_un c dst 2758 vdec 2759 ret 2760 end 2761 rdval 0 0 255 0 2762 ak = get rk 0 2763 av = get rv 0 2764 at = get rt 0 2765 if eq ak 4 2766 av = matreg 4 av at 2767 ak = ulong 1 2768 at = ulong 1 2769 end 2770 rdval 0 0 255 0 2771 bk = get rk 0 2772 bv = get rv 0 2773 bt = get rt 0 2774 if eq bk 4 2775 bv = matreg 4 bv bt 2776 bk = ulong 1 2777 bt = ulong 1 2778 end 2779 if eq ak 2 2780 if eq bk 2 2781 fail 11 2782 end 2783 range av bt at 2784 at = bt 2785 ak = ulong 3 2786 end 2787 if eq bk 2 2788 range bv at bt 2789 bt = at 2790 bk = ulong 3 2791 end 2792 if and ne c 41 ne c 42 2793 if ne at bt 2794 fail 7 2795 end 2796 end 2797 x = mul get depth 0 32 2798 put fr x ak 2799 put fr add x 1 av 2800 put fr add x 2 at 2801 put fr add x 3 bk 2802 put fr add x 4 bv 2803 put fr add x 5 bt 2804 binop c dst x 2805 vdec 2806 end 2807 2808 note cond: read a condition (a bool value); emit a branch taken when it is false: B.cond with the opposite 2809 note condition (C6.2.34), or CBZ Xr (C6.2.78). Returns that branch's place. om4 COND. 2810 fn cond to ulong 2811 rdval 0 1 255 0 2812 if ne get rt 0 1 2813 fail 7 2814 end 2815 if eq get rk 0 4 2816 at = get oc 0 2817 emit or `1409286144` xor get rv 0 1 2818 ret at 2819 end 2820 r = matreg get rk 0 get rv 0 get rt 0 2821 at = get oc 0 2822 emit or `3019898880` r 2823 ret at 2824 end 2825 2826 note ======== statements, one per line (om4 STMT and the S_ parts) ======== 2827 note skipnl: note ...: the rest of the line is not read (up to the newline, which tok reads). om4 S_NOTE. 2828 fn skipnl to void 2829 go = true 2830 while go 2831 n = ulong 0 2832 while and go lt n 999999 2833 if ge get cur 0 get inlen 0 2834 go = false 2835 else 2836 if eq get inp get cur 0 10 2837 go = false 2838 else 2839 put cur 0 add get cur 0 1 2840 end 2841 end 2842 n = add n 1 2843 end 2844 end 2845 end 2846 2847 note s_long: a word over 8 characters at the start of a line: only a call of a void function. om4 S_LONG. 2848 fn s_long to void 2849 if eq get curret 0 0 2850 fail 13 2851 end 2852 if ne get dead 0 0 2853 fail 17 2854 end 2855 f = findfn get tw 0 get tl 0 get ts 0 2856 if eq f 0 2857 fail 13 2858 end 2859 if ne get fn_ret sub f 1 10 2860 fail 7 2861 end 2862 rdval 2 0 255 f 2863 eol 2864 end 2865 2866 note blo: B.LO back to an earlier place (C6.2.34) 2867 fn blo at ulong to void 2868 d = and shr sub at get oc 0 2 524287 2869 emit or `1409286147` shl d 5 2870 end 2871 2872 note sa_arr: x = new T N v: N elements of type T on the stack, each set to v; only in the function's 2873 note outermost block, so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program 2874 note mode: the stack check; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop: STR v, [Xb, Xi, LSL]; 2875 note ADD Xi, Xi, #1; CMP Xi, #N or Xn; B.LO back (C6.2.34). om4 SA_ARR. 2876 fn sa_arr w ulong to void 2877 if ne get nb 0 0 2878 fail 9 2879 end 2880 t = typeword 2881 elemtype t 2882 tok 2883 if ne get tk 0 2 2884 fail 16 2885 end 2886 n = get tw 0 2887 arrlen n 2888 by = shl shr add shl n tlog t 15 4 4 2889 s = add get stkbytes 0 by 2890 if gt s `4194304` 2891 fail 23 2892 end 2893 put stkbytes 0 s 2894 r = alloc 2895 put held 0 get nslot 0 2896 rdval 0 t 255 0 2897 if ne get rt 0 t 2898 fail 7 2899 end 2900 v = matreg get rk 0 get rv 0 get rt 0 2901 spsub by 2902 stkchk 2903 emit or `2432697312` r 2904 i = alloc 2905 emit or `3531603968` i 2906 m = ulong 0 2907 if gt n 4095 2908 m = alloc 2909 matconst m n 2910 end 2911 lp = get oc 0 2912 emit or or or stop t v shl r 5 shl i 16 2913 emit or or `2432697344` i shl i 5 2914 if le n 4095 2915 emit or or `4043309087` shl n 10 shl i 5 2916 else 2917 emit or or `3942645791` shl m 16 shl i 5 2918 end 2919 blo lp 2920 addname w r t n 1 0 2921 end 2922 2923 note s_assign: name [=] value (an existing scalar, or a new one), or name = new T N v. om4 S_ASSIGN. 2924 fn s_assign w ulong to void 2925 tok 2926 if eq get tk 0 1 2927 if le get tl 0 8 2928 if eq kw get tw 0 73 2929 tok 2930 end 2931 end 2932 end 2933 e = findname w 2934 if ne e 0 2935 i = sub e 1 2936 if ne get nm_kind i 0 2937 fail 7 2938 end 2939 r = ulong get nm_reg i 2940 t = ulong get nm_type i 2941 rdval 1 t r 0 2942 if ne get rt 0 t 2943 fail 7 2944 end 2945 force get rk 0 get rv 0 get rt 0 r 2946 eol 2947 ret 2948 end 2949 if ne findfn w 0 0 0 2950 fail 10 2951 end 2952 if eq get tk 0 1 2953 if le get tl 0 8 2954 if eq kw get tw 0 84 2955 sa_arr w 2956 eol 2957 ret 2958 end 2959 end 2960 end 2961 r = alloc 2962 put held 0 get nslot 0 2963 rdval 1 0 r 0 2964 if eq get rk 0 2 2965 fail 11 2966 end 2967 t = get rt 0 2968 force get rk 0 get rv 0 t r 2969 addname w r t 0 0 0 2970 eol 2971 end 2972 2973 note s_name: a name at the start of a line: a call of a void function, or name [=] value. om4 S_NAME. 2974 fn s_name w ulong to void 2975 if ne findname w 0 2976 s_assign w 2977 ret 2978 end 2979 f = findfn w get tl 0 0 2980 if eq f 0 2981 s_assign w 2982 ret 2983 end 2984 if ne get fn_ret sub f 1 10 2985 fail 7 2986 end 2987 rdval 2 0 255 f 2988 eol 2989 end 2990 2991 note fn_p: the type of parameter np (name pw) of function f (index): T, or view / edit T N (an array: 2992 note kind 2 / 3, element type, length 1 .. 2^24). om4 FN_P .. FN_ADD. 2993 fn fn_p f ulong np ulong pw ulong to void 2994 tok 2995 if ne get tk 0 1 2996 fail 16 2997 end 2998 if gt get tl 0 8 2999 fail 16 3000 end 3001 c = kw get tw 0 3002 t = ulong 0 3003 ln = ulong 0 3004 k = ulong 0 3005 if or eq c 57 eq c 58 3006 k = sub c 55 3007 t = typeword 3008 elemtype t 3009 tok 3010 if eq get tk 0 0 3011 fail 4 3012 end 3013 if ne get tk 0 2 3014 fail 16 3015 end 3016 ln = get tw 0 3017 arrlen ln 3018 else 3019 if gt sub c 1 8 3020 fail 16 3021 end 3022 t = c 3023 end 3024 addname pw poolc np t ln k 0 3025 p = add mul f 6 np 3026 put fn_pt p uchar t 3027 put fn_pl p ln 3028 put fn_pk p uchar k 3029 end 3030 3031 note fn_to: to T | to void at the end of a fn line; the function's state starts. om4 FN_TO .. FN_T2. 3032 fn fn_to f ulong np ulong to void 3033 tok 3034 if eq get tk 0 0 3035 fail 4 3036 end 3037 if ne get tk 0 1 3038 fail 16 3039 end 3040 if gt get tl 0 8 3041 fail 16 3042 end 3043 c = kw get tw 0 3044 r = c 3045 if eq c 76 3046 r = ulong 10 3047 else 3048 if gt sub c 1 8 3049 fail 16 3050 end 3051 end 3052 put curret 0 r 3053 put fn_ret f uchar r 3054 put fn_np f uchar np 3055 put stkbytes 0 0 3056 put dead 0 0 3057 put npar 0 np 3058 put nslot 0 0 3059 put held 0 0 3060 put nb 0 0 3061 put nt 0 0 3062 eol 3063 end 3064 3065 note s_fn: fn name (param type | param view T N | param edit T N)* to type | void. om4 S_FN. 3066 fn s_fn to void 3067 if ne get curret 0 0 3068 fail 15 3069 end 3070 tok 3071 if ne get tk 0 1 3072 fail 16 3073 end 3074 if gt get tl 0 63 3075 fail 13 3076 end 3077 w = get tw 0 3078 if ne kw w 0 3079 fail 16 3080 end 3081 l = get tl 0 3082 s = get ts 0 3083 f = ulong 0 3084 if eq get scanning 0 1 3085 newname w l s 3086 f = get nf 0 3087 if ge f 512 3088 fail 14 3089 end 3090 put nf 0 add f 1 3091 put curfn 0 add f 1 3092 put lastfn 0 add f 1 3093 put fn_name f w 3094 put fn_addr f get oc 0 3095 put fn_ret f 0 3096 put fn_np f 0 3097 put fn_nmlen f l 3098 put fn_off f s 3099 else 3100 f = sub findfn w l s 1 3101 put curfn 0 add f 1 3102 put lastfn 0 add f 1 3103 put fn_addr f get oc 0 3104 end 3105 put nn 0 get nglob 0 3106 np = ulong 0 3107 go = true 3108 while go 3109 tok 3110 if eq get tk 0 0 3111 fail 4 3112 end 3113 if ne get tk 0 1 3114 fail 16 3115 end 3116 if gt get tl 0 8 3117 fail 13 3118 end 3119 pw = get tw 0 3120 c = kw pw 3121 if eq c 65 3122 go = false 3123 else 3124 if ne c 0 3125 fail 16 3126 end 3127 newname pw get tl 0 get ts 0 3128 if ge np 6 3129 fail 9 3130 end 3131 fn_p f np pw 3132 np = add np 1 3133 end 3134 end 3135 fn_to f np 3136 if eq get scanning 0 1 3137 put curret 0 0 3138 put nn 0 0 3139 end 3140 end 3141 3142 note s_ret: ret [value]: the value into X0, give back the local arrays' stack, RET. om4 S_RET. 3143 fn s_ret to void 3144 r = get curret 0 3145 if eq r 10 3146 eol 3147 epi 3148 dead1 3149 ret 3150 end 3151 rdval 0 r 0 0 3152 if ne get rt 0 r 3153 fail 7 3154 end 3155 force get rk 0 get rv 0 get rt 0 0 3156 epi 3157 dead1 3158 eol 3159 end 3160 3161 note s_exit: exit value (int): Linux exit (system call 93: MOVZ X8, #93, C6.2.285; SVC #0, C6.2.466); the 3162 note path ends. om4 S_EXIT. 3163 fn s_exit to void 3164 rdval 0 8 255 0 3165 if ne get rt 0 8 3166 fail 7 3167 end 3168 force get rk 0 get rv 0 get rt 0 0 3169 emit `3531606952` 3170 emit `3556769793` 3171 dead1 3172 eol 3173 end 3174 3175 note stel: the checked store of v (type t) at ea_b / ea_i (the STOP table: register offset, scaled) 3176 fn stel t ulong v ulong to void 3177 b = shl get ea_b 0 5 3178 i = shl get ea_i 0 16 3179 emit or or or stop t v b i 3180 end 3181 3182 note s_put: put A i v: index, then value, then the checked store (STOP table). om4 S_PUT. 3183 fn s_put to void 3184 e = arrname 3185 k = get nm_kind sub e 1 3186 if or eq k 2 eq k 5 3187 fail 20 3188 end 3189 rdval 0 5 255 0 3190 ik = get rk 0 3191 iv = get rv 0 3192 it = get rt 0 3193 t = ulong get nm_type sub e 1 3194 rdval 0 t 255 0 3195 if ne get rt 0 t 3196 fail 7 3197 end 3198 v = matreg get rk 0 get rv 0 get rt 0 3199 elemaddr e ik iv it 3200 stel t v 3201 eol 3202 end 3203 3204 note s_global: global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the 3205 note program image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of 3206 note pools (error 23). om4 S_GLOBAL. 3207 fn s_global to void 3208 w = topname 3209 t = typeword 3210 elemtype t 3211 tok 3212 if ne get tk 0 2 3213 fail 16 3214 end 3215 n = get tw 0 3216 arrlen n 3217 by = shl shr add shl n tlog t 15 4 4 3218 pb = get poolb 0 3219 a = add `276824064` pb 3220 s = add pb by 3221 if gt s `1073741824` 3222 fail 23 3223 end 3224 put poolb 0 s 3225 addname w 0 t n 4 a 3226 put nglob 0 get nn 0 3227 eol 3228 end 3229 3230 note s_text: text NAME "...": read-only bytes in the program image (escapes \n \t \\ \", any other is error 3231 note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT. 3232 fn s_text to void 3233 w = topname 3234 tok 3235 if ne get tk 0 4 3236 fail 16 3237 end 3238 a = add get oc 0 `4194304` 3239 p = get tw 0 3240 e = add p get tl 0 3241 n = ulong 0 3242 go = true 3243 while go 3244 m = ulong 0 3245 while and go lt m 999999 3246 if ge p e 3247 go = false 3248 else 3249 b = get inp p 3250 p = add p 1 3251 if eq b 92 3252 b = get inp p 3253 p = add p 1 3254 if eq b 110 3255 b = uchar 10 3256 else 3257 if eq b 116 3258 b = uchar 9 3259 else 3260 if and ne b 92 ne b 34 3261 fail 22 3262 end 3263 end 3264 end 3265 end 3266 emitb b 3267 n = add n 1 3268 end 3269 m = add m 1 3270 end 3271 end 3272 while ne and get oc 0 3 0 3273 emitb 0 3274 end 3275 addname w 0 2 n 5 a 3276 put nglob 0 get nn 0 3277 eol 3278 end 3279 3280 note s_if: if cond: the false branch is patched at else / end. om4 S_IF. 3281 fn s_if to void 3282 at = cond 3283 pushb at 1 0 0 0 3284 pushnh get nn 0 get held 0 3285 eol 3286 end 3287 3288 note s_else: jump over the else part (B, C6.2.35); the if's false branch lands after that jump. om4 S_ELSE. 3289 fn s_else to void 3290 n = get nb 0 3291 if eq n 0 3292 fail 15 3293 end 3294 i = sub n 1 3295 if ne get bkind i 1 3296 fail 15 3297 end 3298 b = get oc 0 3299 emit `335544320` 3300 patch19 get bbr i get oc 0 3301 put bkind i 2 3302 put bbr i b 3303 put nn 0 get bnames i 3304 put held 0 get bheld i 3305 put bdead i get dead 0 3306 put dead 0 0 3307 eol 3308 end 3309 3310 note lpcnt: the hidden counter check of a loop: CMP Xc, #N (C6.2.96) or CMP Xc, Xn (C6.2.97); B.HS trap 3311 note 4; ADD Xc, Xc, #1 (C6.2.5). om4 SW_NOB .. SW_G and the same in S_FOR. 3312 fn lpcnt c ulong n ulong to void 3313 if le n 4095 3314 emit or or `4043309087` shl n 10 shl c 5 3315 else 3316 m = alloc 3317 matconst m n 3318 emit or or `3942645791` shl c 5 shl m 16 3319 end 3320 trapc 2 4 3321 emit or or `2432697344` c shl c 5 3322 end 3323 3324 note s_while: while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4; 3325 note counter = counter + 1; body; B head. N is 1 .. 999999 (error 8), `1000000` with no bound. om4 S_WHILE. 3326 fn s_while to void 3327 sn = get nn 0 3328 sh = get held 0 3329 c = alloc 3330 put held 0 get nslot 0 3331 emit or `3531603968` c 3332 hd = get oc 0 3333 br = cond 3334 n = ulong `1000000` 3335 tok 3336 k = get tk 0 3337 if and ne k 0 ne k 3 3338 if ne k 1 3339 fail 5 3340 end 3341 if gt get tl 0 8 3342 fail 5 3343 end 3344 if ne kw get tw 0 70 3345 fail 5 3346 end 3347 tok 3348 if eq get tk 0 0 3349 fail 4 3350 end 3351 if ne get tk 0 2 3352 fail 16 3353 end 3354 if ge sub get tw 0 1 999999 3355 fail 8 3356 end 3357 n = get tw 0 3358 eol 3359 end 3360 lpcnt c n 3361 pushb br 3 hd c 0 3362 pushnh sn sh 3363 end 3364 3365 note sf_br: B.HS (unsigned) or B.GE (signed) to the loop exit, C6.2.34 (distance filled at end); returns 3366 note its place. om4 SF_BR. 3367 fn sf_br t ulong to ulong 3368 at = get oc 0 3369 if lt t 6 3370 emit `1409286146` 3371 else 3372 emit `1409286154` 3373 end 3374 ret at 3375 end 3376 3377 note sf_num: for i T K with K a number: i = 0 (MOVZ, C6.2.285); head: CMP Xi, #K or Xk; B.HS/B.GE exit. 3378 note om4 SF_NUM .. SF_PUSH. 3379 fn sf_num w ulong t ulong kk ulong sn ulong sh ulong to void 3380 eol 3381 i = alloc 3382 put held 0 get nslot 0 3383 addname w i t 0 0 0 3384 emit or `3531603968` i 3385 hd = get oc 0 3386 if le kk 4095 3387 emit or or `4043309087` shl kk 10 shl i 5 3388 else 3389 k = alloc 3390 matconst k kk 3391 emit or or `3942645791` shl i 5 shl k 16 3392 end 3393 br = sf_br t 3394 pushb br 4 hd i t 3395 pushnh sn sh 3396 end 3397 3398 note sf_val: for i T K with K a value of type T in register kr: i = 0; the hidden counter c = 0; head: CMP 3399 note Xi, Xk; B.HS/B.GE exit; the counter guard of a while with no bound. om4 SF_VAL. 3400 fn sf_val w ulong t ulong kr ulong sn ulong sh ulong to void 3401 eol 3402 i = alloc 3403 put held 0 get nslot 0 3404 addname w i t 0 0 0 3405 emit or `3531603968` i 3406 c = alloc 3407 put held 0 get nslot 0 3408 emit or `3531603968` c 3409 hd = get oc 0 3410 emit or or `3942645791` shl kr 16 shl i 5 3411 br = sf_br t 3412 m = alloc 3413 matconst m `1000000` 3414 emit or or `3942645791` shl c 5 shl m 16 3415 trapc 2 4 3416 emit or or `2432697344` c shl c 5 3417 pushb br 4 hd i t 3418 pushnh sn sh 3419 end 3420 3421 note s_for: for i T K: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number, or a 3422 note value of type T: a name is read at every pass, another value once before the loop. om4 S_FOR. 3423 fn s_for to void 3424 sn = get nn 0 3425 sh = get held 0 3426 tok 3427 if eq get tk 0 0 3428 fail 4 3429 end 3430 if ne get tk 0 1 3431 fail 16 3432 end 3433 if gt get tl 0 8 3434 fail 13 3435 end 3436 w = get tw 0 3437 if ne kw w 0 3438 fail 16 3439 end 3440 newname w get tl 0 get ts 0 3441 t = typeword 3442 if eq t 1 3443 fail 7 3444 end 3445 tok 3446 if eq get tk 0 0 3447 fail 4 3448 end 3449 if eq get tk 0 2 3450 range get tw 0 t get tbig 0 3451 sf_num w t get tw 0 sn sh 3452 ret 3453 end 3454 rdval 1 t 255 0 3455 if ne get rt 0 t 3456 fail 7 3457 end 3458 if eq get rk 0 3 3459 sf_num w t get rv 0 sn sh 3460 ret 3461 end 3462 kr = matreg get rk 0 get rv 0 get rt 0 3463 sf_val w t kr sn sh 3464 end 3465 3466 note finish: end of a function: a function that needs a value must not reach its end (error 18), a void 3467 note one returns; then the trap stubs: shared tail, function mode MOV X0, X7; LDR X16, [X7, #16]; BR X16 3468 note (C6.2.282, C6.2.216, C6.2.46: OscRt.trap); program mode ADD X0, X1, #100; MOVZ X8, #93; SVC #0 (exit 3469 note 100 + code). Per trap code used: MOVZ X1, #code (C6.2.285); B tail. om4 FINISH. 3470 fn finish to void 3471 eol 3472 if eq get dead 0 0 3473 if ne get curret 0 10 3474 fail 18 3475 end 3476 epi 3477 end 3478 nt0 = get nt 0 3479 if ne nt0 0 3480 tail = get oc 0 3481 if eq get progmode 0 0 3482 emit `2852586464` 3483 emit `4181723376` 3484 emit `3592356352` 3485 else 3486 emit `2432798752` 3487 emit `3531606952` 3488 emit `3556769793` 3489 end 3490 code = ulong 1 3491 while le code 14 3492 st = ulong 0 3493 j = ulong 0 3494 while lt j nt0 3495 if eq get tcode j code 3496 if eq st 0 3497 st = get oc 0 3498 emit or `3531603969` shl code 5 3499 back tail 3500 end 3501 patch19 get tsite j st 3502 end 3503 j = add j 1 3504 end 3505 code = add code 1 3506 end 3507 end 3508 put curret 0 0 3509 put nn 0 get nglob 0 3510 put curfn 0 0 3511 end 3512 3513 note s_end: close the innermost block (if: patch its branch; else: patch its jump; while: B head; for: i = 3514 note add i 1, B head), or the function. om4 S_END. 3515 fn s_end to void 3516 n = get nb 0 3517 if eq n 0 3518 finish 3519 ret 3520 end 3521 i = sub n 1 3522 put nb 0 i 3523 k = get bkind i 3524 if eq k 2 3525 put dead 0 and get dead 0 get bdead i 3526 else 3527 put dead 0 0 3528 end 3529 if eq k 4 3530 put fr 0 1 3531 put fr 1 get breg i 3532 put fr 2 get btyp i 3533 put fr 3 3 3534 put fr 4 1 3535 put fr 5 get btyp i 3536 binop 33 get breg i 0 3537 end 3538 if ge k 3 3539 back get bhead i 3540 end 3541 if eq k 2 3542 patch26 get bbr i get oc 0 3543 else 3544 patch19 get bbr i get oc 0 3545 end 3546 put nn 0 get bnames i 3547 put held 0 get bheld i 3548 eol 3549 end 3550 3551 note ======== the end of the input: the output ======== 3552 note writeout: the output from byte st to the end, to stdout (error 2), then exit 0. om4 WRITEOUT. 3553 fn writeout st ulong to void 3554 p = st 3555 go = true 3556 while go 3557 m = ulong 0 3558 while and go lt m 999999 3559 if ge p get oc 0 3560 go = false 3561 else 3562 n = write 1 out p sub get oc 0 p 3563 if le n 0 3564 fail 2 3565 end 3566 p = add p ulong n 3567 end 3568 m = add m 1 3569 end 3570 end 3571 exit int 0 3572 end 3573 3574 note elfhdr: the 176-byte file header (om4 ELFHDR, 44 words): ELF64 little-endian, executable, AArch64, 3575 note entry 0x4000b0 (the word after the header), 2 program headers: code read+execute from 0x400000, and 3576 note the read/write pools from 0x10000000. Only the words that are not 0 (the output starts at 0). 3577 fn elfhdr to void 3578 wrword 0 `1179403647` 3579 wrword 4 65794 3580 wrword 16 `11993090` 3581 wrword 20 1 3582 wrword 24 `4194480` 3583 wrword 32 64 3584 wrword 52 `3670080` 3585 wrword 56 2 3586 wrword 64 1 3587 wrword 68 5 3588 wrword 80 `4194304` 3589 wrword 88 `4194304` 3590 wrword 112 4096 3591 wrword 120 1 3592 wrword 124 6 3593 wrword 136 `268435456` 3594 wrword 144 `268435456` 3595 wrword 168 4096 3596 end 3597 3598 note eof_prog: program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080, 3599 note LSL 16; MOV SP, X16 (ADD immediate, C6.2.5); BL main (C6.2.43); [MOVZ X0, #0 for a void main]; MOVZ X8, 3600 note #93; SVC #0. The entry word after the header is a B to it; the header gets the file and pool sizes. 3601 note om4 EOF_PROG. 3602 fn eof_prog to void 3603 f = findfn `1852399981` 4 0 3604 if eq f 0 3605 fail 16 3606 end 3607 if ne get fn_np sub f 1 0 3608 fail 9 3609 end 3610 wrword 176 or `335544320` and shr sub get oc 0 176 2 `67108863` 3611 if ne get hostargs 0 0 3612 note Preserve Linux's initial argument stack privately before installing Omega's bounded stack. 3613 emit `2432697339` 3614 end 3615 emit `3533832220` 3616 emit `3533836304` 3617 emit `2432696863` 3618 emit or `2483027968` and shr sub get fn_addr sub f 1 get oc 0 2 `67108863` 3619 if eq get fn_ret sub f 1 10 3620 emit `3531603968` 3621 end 3622 emit `3531606952` 3623 emit `3556769793` 3624 elfhdr 3625 wrword 96 get oc 0 3626 wrword 104 get oc 0 3627 wrword 160 add get poolb 0 `8388608` 3628 writeout 0 3629 end 3630 3631 note s_eof: end of input: no open function (error 15), some function (16); function mode: no globals or 3632 note texts (9); one function: its bare words; more: the entry word, a B to the last function. om4 S_EOF. 3633 note Resolve every call after all addresses are known. In function mode remove leaves of the call 3634 note graph; any functions left after nf rounds form or reach a cycle (error 9). 3635 fn resolve to void 3636 n = get ncalls 0 3637 i = ulong 0 3638 while lt i n 3639 s = get callsite i 3640 f = sub get callto i 1 3641 wrword s or `2483027968` and shr sub get fn_addr f s 2 `67108863` 3642 i = add i 1 3643 end 3644 if eq get progmode 0 0 3645 pass = ulong 0 3646 while lt pass get nf 0 3647 f = ulong 0 3648 while lt f get nf 0 3649 if eq get settled f 0 3650 ok = true 3651 i = ulong 0 3652 while and ok lt i n 3653 if eq get callfrom i add f 1 3654 if eq get settled sub get callto i 1 0 3655 ok = false 3656 end 3657 end 3658 i = add i 1 3659 end 3660 if ok 3661 put settled f 1 3662 end 3663 end 3664 f = add f 1 3665 end 3666 pass = add pass 1 3667 end 3668 f = ulong 0 3669 while lt f get nf 0 3670 if eq get settled f 0 3671 fail 9 3672 end 3673 f = add f 1 3674 end 3675 end 3676 end 3677 3678 fn s_eof to void 3679 3680 if ne get curret 0 0 3681 fail 15 3682 end 3683 if eq get nf 0 0 3684 fail 16 3685 end 3686 resolve 3687 if ne get progmode 0 0 3688 eof_prog 3689 end 3690 if ne get nglob 0 0 3691 fail 9 3692 end 3693 if eq get nf 0 1 3694 writeout 180 3695 end 3696 a = get fn_addr sub get lastfn 0 1 3697 wrword 176 or `335544320` and shr sub a 176 2 `67108863` 3698 writeout 176 3699 end 3700 3701 note stmt: one line. Returns 1 at the end of the input. om4 STMT. 3702 fn stmt to ulong 3703 put nslot 0 get held 0 3704 tok 3705 k = get tk 0 3706 if eq k 0 3707 ret 0 3708 end 3709 if eq k 3 3710 s_eof 3711 ret 1 3712 end 3713 if ne k 1 3714 fail 16 3715 end 3716 if gt get tl 0 8 3717 s_long 3718 ret 0 3719 end 3720 w = get tw 0 3721 c = kw w 3722 if eq c 83 3723 skipnl 3724 ret 0 3725 end 3726 if eq c 64 3727 s_fn 3728 ret 0 3729 end 3730 if eq get curret 0 0 3731 if eq c 78 3732 s_global 3733 ret 0 3734 end 3735 if eq c 79 3736 s_text 3737 ret 0 3738 end 3739 fail 16 3740 end 3741 if eq c 66 3742 s_end 3743 ret 0 3744 end 3745 if eq c 68 3746 s_else 3747 ret 0 3748 end 3749 if ne get dead 0 0 3750 fail 17 3751 end 3752 if eq c 0 3753 s_name w 3754 ret 0 3755 end 3756 if eq c 67 3757 s_if 3758 ret 0 3759 end 3760 if eq c 69 3761 s_while 3762 ret 0 3763 end 3764 if eq c 71 3765 s_for 3766 ret 0 3767 end 3768 if eq c 72 3769 s_ret 3770 ret 0 3771 end 3772 if eq c 80 3773 s_put 3774 ret 0 3775 end 3776 if eq c 82 3777 s_exit 3778 ret 0 3779 end 3780 if or or or eq c 77 eq c 78 eq c 79 eq c 81 3781 fail 9 3782 end 3783 fail 16 3784 ret 0 3785 end 3786 3787 note ======== program mode: some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ======== 3788 note skipbl: the first place at or after q that is not a space or tab (or the end) 3789 fn skipbl q ulong to ulong 3790 e = get inlen 0 3791 p = q 3792 go = true 3793 while go 3794 m = ulong 0 3795 while and go lt m 999999 3796 if ge p e 3797 go = false 3798 else 3799 b = get inp p 3800 if or eq b 32 eq b 9 3801 p = add p 1 3802 else 3803 go = false 3804 end 3805 end 3806 m = add m 1 3807 end 3808 end 3809 ret p 3810 end 3811 3812 note skipln: the place after the next newline at or after q (or the end) 3813 fn skipln q ulong to ulong 3814 e = get inlen 0 3815 p = q 3816 go = true 3817 while go 3818 m = ulong 0 3819 while and go lt m 999999 3820 if ge p e 3821 go = false 3822 else 3823 b = get inp p 3824 p = add p 1 3825 if eq b 10 3826 go = false 3827 end 3828 end 3829 m = add m 1 3830 end 3831 end 3832 ret p 3833 end 3834 3835 note ps_at: the line's first byte that is not blank is at p: 1 when the line is `fn main`, 2 when the input 3836 note ends while deciding, else 0. om4 PS_LINE .. PS_YES. 3837 fn ps_at p ulong to ulong 3838 e = get inlen 0 3839 if ne get inp p 102 3840 ret 0 3841 end 3842 q = add p 1 3843 if ge q e 3844 ret 2 3845 end 3846 if ne get inp q 110 3847 ret 0 3848 end 3849 r = add q 1 3850 q = skipbl r 3851 if ge q e 3852 ret 2 3853 end 3854 if eq q r 3855 ret 0 3856 end 3857 if gt add q 4 e 3858 ret 0 3859 end 3860 if ne get inp q 109 3861 ret 0 3862 end 3863 if ne get inp add q 1 97 3864 ret 0 3865 end 3866 if ne get inp add q 2 105 3867 ret 0 3868 end 3869 if ne get inp add q 3 110 3870 ret 0 3871 end 3872 if ge add q 4 e 3873 ret 1 3874 end 3875 if gt get inp add q 4 32 3876 ret 0 3877 end 3878 ret 1 3879 end 3880 3881 fn prescan to void 3882 e = get inlen 0 3883 p = ulong 0 3884 go = true 3885 while go 3886 m = ulong 0 3887 while and go lt m 999999 3888 p = skipbl p 3889 if ge p e 3890 go = false 3891 else 3892 r = ps_at p 3893 if eq r 1 3894 put progmode 0 1 3895 go = false 3896 end 3897 if eq r 2 3898 go = false 3899 end 3900 if go 3901 p = skipln p 3902 if ge p e 3903 go = false 3904 end 3905 end 3906 end 3907 m = add m 1 3908 end 3909 end 3910 end 3911 3912 note First collect signatures. Only fn headers are parsed here; other lines are read in the body pass. 3913 fn namescan to void 3914 put scanning 0 1 3915 put line 0 1 3916 go = true 3917 while go 3918 n = ulong 0 3919 while and go lt n 999999 3920 tok 3921 if eq get tk 0 3 3922 go = false 3923 else 3924 if ne get tk 0 0 3925 if and eq get tk 0 1 eq get tw 0 28262 3926 s_fn 3927 else 3928 skipnl 3929 end 3930 end 3931 end 3932 n = add n 1 3933 end 3934 end 3935 put scanning 0 0 3936 put cur 0 0 3937 put line 0 1 3938 put nn 0 0 3939 put curfn 0 0 3940 put curret 0 0 3941 put npar 0 0 3942 put nslot 0 0 3943 put held 0 0 3944 end 3945 3946 note main: read all of stdin 3947 note (8 MiB at most, error 14; a read error is 1), find the mode, then one 3948 note statement per line from output byte 180 (om4 START .. STMT) 3949 fn main to int 3950 off = ulong 0 3951 go = true 3952 while go 3953 m = ulong 0 3954 while and go lt m 999999 3955 if ge off len inp 3956 fail 14 3957 end 3958 n = read 0 inp off sub len inp off 3959 if eq n 0 3960 go = false 3961 else 3962 if lt n 0 3963 fail 1 3964 end 3965 off = add off ulong n 3966 end 3967 m = add m 1 3968 end 3969 end 3970 put inlen 0 off 3971 prescan 3972 namescan 3973 put oc 0 180 3974 put line 0 1 3975 done = false 3976 while not done 3977 m = ulong 0 3978 while and not done lt m 999999 3979 if ne stmt 0 3980 done = true 3981 end 3982 m = add m 1 3983 end 3984 end 3985 ret 0 3986 end