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/src/adapters/go-u64-import.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 / src / adapters / go-u64-import.om` 984 lines ยท 14527 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-or-later 2 note Handwritten bounded Go 1.27 uint64 expression importer, profile go-u64-pure-v1 (source-aware v2). 3 note No Go compiler, parser library or host fallback. Spec: spec/universal/go-u64-v1.md. 4 note SHA256 definitions are the unchanged, pinned source-aware vendor core prepended at build. 5 global Src uchar 4096 6 global Extra uchar 1 7 global Out uchar 8192 8 global Slen ulong 1 9 global Cur ulong 1 10 global Tk ulong 1 11 global Ts ulong 1 12 global Te ulong 1 13 global Tv ulong 1 14 global Ins ulong 1 15 global Nl ulong 1 16 global Npar ulong 1 17 global Poff ulong 6 18 global Plen ulong 6 19 global Nop ulong 1 20 global Beg ulong 64 21 global Ends ulong 64 22 global Kc ulong 64 23 global Kv ulong 64 24 text Fixed "package main func return uint64 +build" 25 text Keys "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var true false iota nil append cap clear close complex copy delete imag len make max min new panic print println real recover main init" 26 text Types "any bool byte comparable complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr" 27 text Entry "calc omega_" 28 text ESyn "GO_IMPORT_SYNTAX\n" 29 text EType "GO_IMPORT_UNSUPPORTED_TYPE\n" 30 text ECap "GO_IMPORT_LIMIT\n" 31 text EArith "GO_IMPORT_UNSUPPORTED_ARITHMETIC\n" 32 text EForm "GO_IMPORT_UNSUPPORTED_CONSTRUCT\n" 33 text EName "GO_IMPORT_UNKNOWN_IDENTIFIER\n" 34 text ESig "GO_IMPORT_UNSUPPORTED_SIGNATURE\n" 35 text ELex "GO_IMPORT_UNSUPPORTED_SOURCE_FORM\n" 36 text EIO "GO_IMPORT_IO\n" 37 38 fn die code ulong to void 39 if eq code 65 40 w = write 2 ESyn 0 len ESyn 41 end 42 if eq code 66 43 w = write 2 EType 0 len EType 44 end 45 if eq code 67 46 w = write 2 ECap 0 len ECap 47 end 48 if eq code 68 49 w = write 2 EArith 0 len EArith 50 end 51 if eq code 69 52 w = write 2 EForm 0 len EForm 53 end 54 if eq code 70 55 w = write 2 EName 0 len EName 56 end 57 if eq code 71 58 w = write 2 ESig 0 len ESig 59 end 60 if eq code 72 61 w = write 2 ELex 0 len ELex 62 end 63 if eq code 77 64 w = write 2 EIO 0 len EIO 65 end 66 exit int code 67 end 68 69 fn alpha c uchar to bool 70 ret or or and ge c 65 le c 90 and ge c 97 le c 122 eq c 95 71 end 72 73 fn digit c uchar to bool 74 ret and ge c 48 le c 57 75 end 76 77 fn ident c uchar to bool 78 ret or alpha c digit c 79 end 80 81 fn srcdig p ulong to bool 82 if ge p get Slen 0 83 ret false 84 end 85 ret digit get Src p 86 end 87 88 fn srcid p ulong to bool 89 if ge p get Slen 0 90 ret false 91 end 92 ret ident get Src p 93 end 94 95 fn srcis p ulong c ulong to bool 96 if ge p get Slen 0 97 ret false 98 end 99 ret eq ulong get Src p c 100 end 101 102 fn notnl p ulong to bool 103 if ge p get Slen 0 104 ret false 105 end 106 ret ne get Src p 10 107 end 108 109 note Strict UTF-8 (no overlong, surrogate or above U+10FFFF) over the whole source. 110 fn utf8 to bool 111 n = get Slen 0 112 pos = ulong 0 113 while lt pos n 114 c = ulong get Src pos 115 pos = add pos 1 116 if ge c 128 117 extra = ulong 0 118 v = ulong 0 119 low = ulong 0 120 if and ge c 194 le c 223 121 extra = 1 122 v = and c 31 123 low = 128 124 end 125 if and ge c 224 le c 239 126 extra = 2 127 v = and c 15 128 low = 2048 129 end 130 if and ge c 240 le c 244 131 extra = 3 132 v = and c 7 133 low = 65536 134 end 135 if eq extra 0 136 ret false 137 end 138 if gt extra sub n pos 139 ret false 140 end 141 for j ulong extra 142 c = ulong get Src pos 143 if or lt c 128 gt c 191 144 ret false 145 end 146 v = or shl v 6 and c 63 147 pos = add pos 1 148 end 149 if lt v low 150 ret false 151 end 152 if gt v `1114111` 153 ret false 154 end 155 if and ge v 55296 le v 57343 156 ret false 157 end 158 end 159 end 160 ret true 161 end 162 163 fn blank p ulong to bool 164 if ge p get Slen 0 165 ret true 166 end 167 c = get Src p 168 ret or or eq c 32 eq c 9 or eq c 10 eq c 13 169 end 170 171 note Line comment; acts like a newline. Compiler directives (//go:..., //line, //export, // +build) 172 note are not ordinary comments: the byte after // must be blank, and the text may not start with +build. 173 fn linecom to void 174 p = add get Cur 0 2 175 if not blank p 176 die 72 177 end 178 q = p 179 while or srcis q 32 srcis q 9 180 q = add q 1 181 end 182 hit = ulong 1 183 for i ulong 6 184 if not srcis add q i ulong get Fixed add 32 i 185 hit = 0 186 end 187 end 188 if eq hit 1 189 die 72 190 end 191 while notnl p 192 p = add p 1 193 end 194 put Nl 0 1 195 put Cur 0 p 196 end 197 198 note General comment; Go general comments do not nest. One containing a newline acts like a newline. 199 note The byte after /* must be blank or *, which excludes the /*line directive. 200 fn blockcom to void 201 p = add get Cur 0 2 202 if not or blank p srcis p 42 203 die 72 204 end 205 while lt add p 1 get Slen 0 206 a = get Src p 207 b = get Src add p 1 208 if and eq a 42 eq b 47 209 put Cur 0 add p 2 210 ret 211 end 212 if eq a 10 213 put Nl 0 1 214 end 215 p = add p 1 216 end 217 die 65 218 end 219 220 fn spaces to void 221 more = ulong 1 222 while eq more 1 223 if ge get Cur 0 get Slen 0 224 ret 225 end 226 p = get Cur 0 227 c = get Src p 228 if or or eq c 32 eq c 9 or eq c 10 eq c 13 229 if eq c 10 230 put Nl 0 1 231 end 232 put Cur 0 add p 1 233 else 234 if and eq c 47 lt add p 1 get Slen 0 235 d = get Src add p 1 236 if eq d 47 237 linecom 238 else 239 if eq d 42 240 blockcom 241 else 242 more = 0 243 end 244 end 245 else 246 more = 0 247 end 248 end 249 end 250 end 251 252 fn word off ulong n ulong to bool 253 if or ne get Tk 0 256 ne sub get Te 0 get Ts 0 n 254 ret false 255 end 256 for i ulong n 257 if ne get Src add get Ts 0 i get Fixed add off i 258 ret false 259 end 260 end 261 ret true 262 end 263 264 note An identifier ends a line with an automatic semicolon, except the keywords of this grammar that 265 note do not (package, func). Every other keyword refuses wherever it appears. 266 fn idlex to void 267 p = add get Cur 0 1 268 while srcid p 269 p = add p 1 270 end 271 put Tk 0 256 272 put Cur 0 p 273 put Te 0 p 274 put Ins 0 1 275 if or word 0 7 word 13 4 276 put Ins 0 0 277 end 278 end 279 280 note Decimal literal 0 or [1-9][0-9]*; no 0x/0o/0b, no legacy octal 0nn, no _, no float or imaginary form. 281 fn numlex to void 282 p = get Cur 0 283 if eq get Src p 48 284 if srcdig add p 1 285 die 68 286 end 287 end 288 v = ulong 0 289 while srcdig p 290 d = sub ulong get Src p 48 291 if gt v `1844674407370955161` 292 die 67 293 end 294 if and eq v `1844674407370955161` gt d 5 295 die 67 296 end 297 v = add mul v 10 d 298 p = add p 1 299 end 300 if srcid p 301 die 68 302 end 303 if srcis p 46 304 die 68 305 end 306 put Tk 0 257 307 put Tv 0 v 308 put Cur 0 p 309 put Te 0 p 310 put Ins 0 1 311 end 312 313 note Go automatic semicolon insertion: a newline (or the end of input) after an identifier, literal, 314 note ) ] or } is a ; token. Token 59 is both the explicit and the inserted semicolon. 315 fn lexnext to void 316 put Nl 0 0 317 spaces 318 p = get Cur 0 319 if and eq get Ins 0 1 or eq get Nl 0 1 ge p get Slen 0 320 put Ins 0 0 321 put Tk 0 59 322 put Ts 0 p 323 put Te 0 p 324 ret 325 end 326 put Ins 0 0 327 put Ts 0 p 328 if ge p get Slen 0 329 put Tk 0 0 330 put Te 0 p 331 ret 332 end 333 c = get Src p 334 if alpha c 335 idlex 336 else 337 if digit c 338 numlex 339 else 340 if gt c 127 341 die 69 342 end 343 put Tk 0 ulong c 344 put Cur 0 add p 1 345 put Te 0 add p 1 346 if or or eq c 41 eq c 93 eq c 125 347 put Ins 0 1 348 end 349 end 350 end 351 end 352 353 fn keyeq txt ulong off ulong n ulong to bool 354 if ne sub get Te 0 get Ts 0 n 355 ret false 356 end 357 for i ulong n 358 c = get Src add get Ts 0 i 359 if eq txt 0 360 if ne c get Keys add off i 361 ret false 362 end 363 else 364 if ne c get Types add off i 365 ret false 366 end 367 end 368 end 369 ret true 370 end 371 372 fn keychar p ulong to bool 373 if ge p len Keys 374 ret false 375 end 376 ret ne get Keys p 32 377 end 378 379 fn typechar p ulong to bool 380 if ge p len Types 381 ret false 382 end 383 ret ne get Types p 32 384 end 385 386 note Keywords, predeclared constants and functions, main and init. 387 fn iskey to bool 388 if ne get Tk 0 256 389 ret false 390 end 391 p = ulong 0 392 while lt p len Keys 393 b = p 394 while keychar p 395 p = add p 1 396 end 397 if keyeq 0 b sub p b 398 ret true 399 end 400 p = add p 1 401 end 402 ret false 403 end 404 405 note Predeclared type names. 406 fn istype to bool 407 if ne get Tk 0 256 408 ret false 409 end 410 p = ulong 0 411 while lt p len Types 412 b = p 413 while typechar p 414 p = add p 1 415 end 416 if keyeq 1 b sub p b 417 ret true 418 end 419 p = add p 1 420 end 421 ret false 422 end 423 424 fn entryok to bool 425 n = sub get Te 0 get Ts 0 426 if eq n 4 427 for i ulong 4 428 if ne get Src add get Ts 0 i get Entry i 429 ret false 430 end 431 end 432 ret true 433 end 434 if le n 6 435 ret false 436 end 437 for i ulong 6 438 if ne get Src add get Ts 0 i get Entry add i 5 439 ret false 440 end 441 end 442 ret true 443 end 444 445 fn nameok to void 446 if ne get Tk 0 256 447 die 69 448 end 449 if gt sub get Te 0 get Ts 0 32 450 die 71 451 end 452 c = get Src get Ts 0 453 if or lt c 97 gt c 122 454 die 71 455 end 456 if iskey 457 die 71 458 end 459 if istype 460 die 71 461 end 462 end 463 464 fn need k ulong to void 465 if ne get Tk 0 k 466 die 65 467 end 468 lexnext 469 end 470 471 fn same off ulong count ulong to bool 472 if ne count sub get Te 0 get Ts 0 473 ret false 474 end 475 for i ulong count 476 if ne get Src add off i get Src add get Ts 0 i 477 ret false 478 end 479 end 480 ret true 481 end 482 483 fn leput off ulong v ulong n ulong to void 484 for i ulong n 485 put Out add off i uchar and shr v mul i 8 255 486 end 487 end 488 489 note One OMSA v2 operation record of the Go member: dialect 7, version 1, type 1. 490 fn emitop op ulong a ulong b ulong imm ulong lo ulong hi ulong to ulong 491 i = get Nop 0 492 if ge i 64 493 die 67 494 end 495 p = add 57 mul i 20 496 for j ulong 20 497 put Out add p j 0 498 end 499 put Out p 7 500 put Out add p 1 1 501 put Out add p 2 uchar op 502 put Out add p 3 1 503 if ne op 9 504 put Out add p 4 1 505 end 506 if ne op 1 507 put Out add p 7 1 508 end 509 leput add p 8 a 2 510 leput add p 10 b 2 511 leput add p 12 imm 8 512 put Beg i lo 513 put Ends i hi 514 put Kc i 0 515 put Kv i imm 516 if eq op 1 517 put Kc i 1 518 end 519 put Nop 0 add i 1 520 ret i 521 end 522 523 note Untyped constants: a source operation whose operands are both constant-only is a Go constant 524 note expression, evaluated exactly. It must lie in 0..2^64-1, so that the exact value equals the 525 note modulo-2^64 tree and the conversion to uint64 compiles; otherwise refuse 68. 526 fn mkop code ulong a ulong b ulong lo ulong hi ulong to ulong 527 k = emitop code a b 0 lo hi 528 if and eq get Kc a 1 eq get Kc b 1 529 x = get Kv a 530 y = get Kv b 531 v = ulong 0 532 if eq code 2 533 v = add x y 534 if lt v x 535 die 68 536 end 537 end 538 if eq code 3 539 if lt x y 540 die 68 541 end 542 v = sub x y 543 end 544 if eq code 4 545 v = mul x y 546 if ne x 0 547 if ne div v x y 548 die 68 549 end 550 end 551 end 552 put Kc k 1 553 put Kv k v 554 end 555 ret k 556 end 557 558 fn badarith to bool 559 k = get Tk 0 560 if or or eq k 47 eq k 37 eq k 38 561 ret true 562 end 563 if or or eq k 124 eq k 94 eq k 60 564 ret true 565 end 566 if or eq k 62 eq k 33 567 ret true 568 end 569 if eq k 61 570 ret srcis get Te 0 61 571 end 572 ret false 573 end 574 575 fn closer to void 576 t = get Tk 0 577 if eq t 41 578 lexnext 579 ret 580 end 581 if badarith 582 die 68 583 end 584 if or or eq t 0 eq t 59 or eq t 125 eq t 44 585 die 65 586 end 587 if or eq t 256 eq t 257 588 die 65 589 end 590 die 69 591 end 592 593 fn identprim to ulong 594 for j ulong get Npar 0 595 if same get Poff j get Plen j 596 lexnext 597 ret j 598 end 599 end 600 if istype 601 die 66 602 end 603 if iskey 604 die 69 605 end 606 die 70 607 ret 0 608 end 609 610 fn primary depth ulong to ulong 611 if gt depth 16 612 die 67 613 end 614 t = get Tk 0 615 if eq t 257 616 node = emitop 1 65535 65535 get Tv 0 get Ts 0 get Te 0 617 lexnext 618 ret node 619 end 620 if eq t 256 621 ret identprim 622 end 623 if eq t 40 624 lexnext 625 node = expr add depth 1 626 closer 627 ret node 628 end 629 if or or eq t 43 eq t 45 or eq t 94 eq t 42 630 die 68 631 end 632 if or or eq t 38 eq t 33 or eq t 60 eq t 126 633 die 68 634 end 635 if or eq t 39 eq t 46 636 die 68 637 end 638 if or or eq t 0 eq t 41 or eq t 59 or eq t 44 eq t 125 639 die 65 640 end 641 die 69 642 ret 0 643 end 644 645 fn term depth ulong to ulong 646 left = primary depth 647 while eq get Tk 0 42 648 lo = get Ts 0 649 hi = get Te 0 650 lexnext 651 right = primary depth 652 left = mkop 4 left right lo hi 653 end 654 ret left 655 end 656 657 fn expr depth ulong to ulong 658 left = term depth 659 while or eq get Tk 0 43 eq get Tk 0 45 660 code = ulong 2 661 if eq get Tk 0 45 662 code = 3 663 end 664 lo = get Ts 0 665 hi = get Te 0 666 lexnext 667 right = term depth 668 left = mkop code left right lo hi 669 end 670 ret left 671 end 672 673 fn pname to void 674 nameok 675 j = get Npar 0 676 if ge j 6 677 die 67 678 end 679 for k ulong j 680 if same get Poff k get Plen k 681 die 71 682 end 683 end 684 put Poff j get Ts 0 685 put Plen j sub get Te 0 get Ts 0 686 x = emitop 9 65535 65535 j get Ts 0 get Te 0 687 put Npar 0 add j 1 688 lexnext 689 end 690 691 fn ptype to void 692 if word 25 6 693 lexnext 694 ret 695 end 696 t = get Tk 0 697 if eq t 46 698 die 69 699 end 700 if or or eq t 256 eq t 42 or eq t 91 eq t 40 701 die 66 702 end 703 die 65 704 end 705 706 note Named parameters, optionally grouped (a, b uint64); every group has type uint64. 707 fn params to void 708 if eq get Tk 0 41 709 lexnext 710 ret 711 end 712 more = ulong 1 713 while eq more 1 714 pname 715 if eq get Tk 0 44 716 lexnext 717 if eq get Tk 0 41 718 die 65 719 end 720 else 721 ptype 722 if eq get Tk 0 44 723 lexnext 724 if eq get Tk 0 41 725 die 65 726 end 727 else 728 more = 0 729 end 730 end 731 end 732 need 41 733 end 734 735 fn result to void 736 t = get Tk 0 737 if eq t 40 738 die 69 739 end 740 if eq t 123 741 die 71 742 end 743 if word 25 6 744 lexnext 745 ret 746 end 747 if or or eq t 256 eq t 42 eq t 91 748 die 66 749 end 750 die 65 751 end 752 753 fn header to void 754 lexnext 755 if not word 0 7 756 if eq get Tk 0 0 757 die 65 758 end 759 die 69 760 end 761 lexnext 762 if ne get Tk 0 256 763 die 65 764 end 765 if not word 8 4 766 die 71 767 end 768 lexnext 769 need 59 770 if not word 13 4 771 if eq get Tk 0 0 772 die 65 773 end 774 die 69 775 end 776 lexnext 777 if eq get Tk 0 40 778 die 69 779 end 780 nameok 781 if not entryok 782 die 71 783 end 784 lexnext 785 if eq get Tk 0 91 786 die 69 787 end 788 need 40 789 params 790 result 791 need 123 792 if not word 18 6 793 if eq get Tk 0 125 794 die 65 795 end 796 die 69 797 end 798 lexnext 799 end 800 801 fn bodyend to void 802 if badarith 803 die 68 804 end 805 if eq get Tk 0 59 806 lexnext 807 if ne get Tk 0 125 808 die 69 809 end 810 end 811 t = get Tk 0 812 if eq t 125 813 lexnext 814 ret 815 end 816 if or eq t 0 eq t 41 817 die 65 818 end 819 if or eq t 256 eq t 257 820 die 65 821 end 822 die 69 823 end 824 825 fn parse to void 826 put Cur 0 0 827 header 828 if eq get Tk 0 59 829 die 65 830 end 831 root = expr 0 832 bodyend 833 if eq get Tk 0 59 834 lexnext 835 end 836 if ne get Tk 0 0 837 die 69 838 end 839 z = emitop 1 65535 65535 0 0 0 840 root = emitop 2 root z 0 0 0 841 end 842 843 fn parent to void 844 put Out 25 212 845 put Out 26 237 846 put Out 27 97 847 put Out 28 72 848 put Out 29 191 849 put Out 30 169 850 put Out 31 124 851 put Out 32 198 852 put Out 33 147 853 put Out 34 211 854 put Out 35 250 855 put Out 36 68 856 put Out 37 149 857 put Out 38 226 858 put Out 39 215 859 put Out 40 226 860 put Out 41 230 861 put Out 42 138 862 put Out 43 186 863 put Out 44 4 864 put Out 45 96 865 put Out 46 122 866 put Out 47 126 867 put Out 48 150 868 put Out 49 221 869 put Out 50 154 870 put Out 51 156 871 put Out 52 84 872 put Out 53 191 873 put Out 54 144 874 put Out 55 115 875 put Out 56 168 876 end 877 878 note OMSB v1 envelope, OMSA semantic header version 2, language 7 (Go 1.27), profile 9, runtime 0, ABI 1. 879 fn envelope to ulong 880 n = get Nop 0 881 sem = add 44 mul 20 n 882 prov = add add 74 mul 8 n get Slen 0 883 put Out 0 79 884 put Out 1 77 885 put Out 2 83 886 put Out 3 66 887 put Out 4 1 888 leput 5 sem 4 889 leput 9 prov 4 890 put Out 13 79 891 put Out 14 77 892 put Out 15 83 893 put Out 16 65 894 put Out 17 2 895 put Out 18 7 896 put Out 19 9 897 put Out 20 1 898 put Out 21 0 899 put Out 22 1 900 leput 23 n 2 901 parent 902 s = add 13 sem 903 put Out s 79 904 put Out add s 1 77 905 put Out add s 2 83 906 put Out add s 3 80 907 put Out add s 4 1 908 put Out add s 5 1 909 leput add s 6 get Slen 0 4 910 hinit 911 for i ulong sem 912 hbyte get Out add 13 i 913 end 914 finish 915 for i ulong 32 916 put Out add add s 10 i get Hash i 917 end 918 hinit 919 for i ulong get Slen 0 920 hbyte get Src i 921 end 922 finish 923 for i ulong 32 924 put Out add add s 42 i get Hash i 925 end 926 for i ulong n 927 leput add add s 74 mul i 8 get Beg i 4 928 leput add add s 78 mul i 8 get Ends i 4 929 end 930 b = add add s 74 mul n 8 931 for i ulong get Slen 0 932 put Out add b i get Src i 933 end 934 ret add add 13 sem prov 935 end 936 937 fn main to int 938 n = ulong 0 939 more = ulong 1 940 while and eq more 1 lt n 4096 941 r = read 0 Src n sub 4096 n 942 if lt r 0 943 die 77 944 end 945 if eq r 0 946 more = 0 947 else 948 n = add n ulong r 949 end 950 end 951 if eq n 4096 952 r = read 0 Extra 0 1 953 if lt r 0 954 die 77 955 end 956 if gt r 0 957 die 67 958 end 959 end 960 put Slen 0 n 961 for i ulong n 962 if eq get Src i 0 963 die 65 964 end 965 end 966 if not utf8 967 die 72 968 end 969 if and srcis 0 239 and srcis 1 187 srcis 2 191 970 die 72 971 end 972 constants 973 parse 974 n = envelope 975 sent = ulong 0 976 while lt sent n 977 r = write 1 Out sent sub n sent 978 if le r 0 979 die 77 980 end 981 sent = add sent ulong r 982 end 983 ret 0 984 end