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/language/omega_parse.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 / language / omega_parse.om` 914 lines ยท 19790 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Pure seeded OM-2 Surface Language V0 parser: a faithful port of src/language/omega_parse.c. 3 note Same grammar, node order, canonical contract text, error texts, columns and return codes. 4 note Depends on omega_lex.om. 5 note 6 note Statement kinds (OmegaStmtKind): 0=EMPTY 1=EXPR 2=LET 3=FN. 7 note AST node kinds (OmegaAstKind): 1=INT 2=BOOL 3=NAME 4=BINARY 5=ASCRIBE. 8 note Types are (tag, width) with the TypeTag values of visor.om: bool (V_TY_BOOL, 1), uN (V_TY_UINT, N). 9 note Functions return 0 or the C return code; a parsed node index comes back in opr_out. 10 11 const OPR_MAX_NODES ulong 128 12 const OPR_MAX_DEPTH ulong 32 13 14 global opr_pos ulong 1 15 global opr_out long 1 16 global opr_stmt ulong 1 17 global opr_scol ulong 1 18 global opr_root long 1 19 global opr_ncnt ulong 1 20 global opr_nkind ulong 128 21 global opr_ncol ulong 128 22 global opr_nop ulong 128 23 global opr_nlhs long 128 24 global opr_nrhs long 128 25 global opr_nval ulong 128 26 global opr_nstr uchar 8192 27 global opr_nslen ulong 128 28 global opr_nttag ulong 128 29 global opr_ntwid ulong 128 30 31 global opr_name uchar 64 32 global opr_nlen ulong 1 33 global opr_lttag ulong 1 34 global opr_ltwid ulong 1 35 global opr_param uchar 64 36 global opr_plen ulong 1 37 global opr_pttag ulong 1 38 global opr_ptwid ulong 1 39 global opr_rttag ulong 1 40 global opr_rtwid ulong 1 41 global opr_ty_tag ulong 1 42 global opr_ty_wid ulong 1 43 note canonical contract text: 0 = requires, 1 = ensures (64 bytes each) 44 global opr_ctxt uchar 128 45 global opr_clen ulong 2 46 global opr_pc uchar 96 47 global opr_pcl ulong 1 48 49 fn opr_peek to ulong 50 ret get olx_tkind get opr_pos 0 51 end 52 53 fn opr_peek_col to ulong 54 ret get olx_tcol get opr_pos 0 55 end 56 57 fn opr_peek2 to ulong 58 p = add get opr_pos 0 1 59 if gt p get olx_tcnt 0 60 p = get olx_tcnt 0 61 end 62 ret get olx_tkind p 63 end 64 65 fn opr_next to void 66 p = get opr_pos 0 67 if lt p get olx_tcnt 0 68 put opr_pos 0 add p 1 69 end 70 end 71 72 note the found-token text of expect / expect_end: the word of a name, else tok_text 73 fn olm_found t ulong to void 74 k = get olx_tkind t 75 if eq k 1 76 olm_tstr t 77 else 78 olm_tok k 79 end 80 end 81 82 text opr_m_exp "expected " 83 text opr_m_found " but found '" 84 85 fn opr_expect k ulong what view uchar * to long 86 t = get opr_pos 0 87 if ne get olx_tkind t k 88 olm_reset 89 olm_t opr_m_exp 90 olm_t what 91 olm_t opr_m_found 92 olm_found t 93 olm_c 39 94 olm_cap 159 95 olx_fail get olx_tcol t 96 ret -1 97 end 98 opr_next 99 ret 0 100 end 101 102 note ---- omega_language_is_reserved: keywords and RESERVED_EXTRA ---- 103 text opr_w_u8 "u8" 104 text opr_w_u16 "u16" 105 text opr_w_u32 "u32" 106 text opr_w_u64 "u64" 107 text opr_w_bool "bool" 108 text opr_w_i8 "i8" 109 text opr_w_i16 "i16" 110 text opr_w_i32 "i32" 111 text opr_w_i64 "i64" 112 text opr_w_result "result" 113 text opr_w_effect "effect" 114 text opr_w_effects "effects" 115 text opr_w_cap "cap" 116 text opr_w_capability "capability" 117 text opr_w_mint "mint" 118 text opr_w_revoke "revoke" 119 text opr_w_grant "grant" 120 text opr_w_publish "publish" 121 text opr_w_promote "promote" 122 text opr_w_authority "authority" 123 text opr_w_admin "admin" 124 text opr_w_syscall "syscall" 125 text opr_w_io "io" 126 text opr_w_print "print" 127 text opr_w_import "import" 128 text opr_w_extern "extern" 129 text opr_w_unsafe "unsafe" 130 text opr_w_asm "asm" 131 text opr_w_if "if" 132 text opr_w_else "else" 133 text opr_w_while "while" 134 text opr_w_for "for" 135 text opr_w_loop "loop" 136 text opr_w_return "return" 137 text opr_w_match "match" 138 text opr_w_struct "struct" 139 text opr_w_enum "enum" 140 text opr_w_mut "mut" 141 text opr_w_var "var" 142 text opr_w_const "const" 143 text opr_w_self "self" 144 text opr_w_rec "rec" 145 text opr_w_us "_" 146 147 fn opr_res_types t ulong to bool 148 if or olx_tok_eq t opr_w_u8 or olx_tok_eq t opr_w_u16 olx_tok_eq t opr_w_u32 149 ret true 150 end 151 if or olx_tok_eq t opr_w_u64 or olx_tok_eq t opr_w_bool olx_tok_eq t opr_w_i8 152 ret true 153 end 154 if or olx_tok_eq t opr_w_i16 or olx_tok_eq t opr_w_i32 olx_tok_eq t opr_w_i64 155 ret true 156 end 157 ret olx_tok_eq t opr_w_result 158 end 159 160 fn opr_res_effects t ulong to bool 161 if or olx_tok_eq t opr_w_effect or olx_tok_eq t opr_w_effects olx_tok_eq t opr_w_cap 162 ret true 163 end 164 if or olx_tok_eq t opr_w_capability or olx_tok_eq t opr_w_mint olx_tok_eq t opr_w_revoke 165 ret true 166 end 167 if or olx_tok_eq t opr_w_grant or olx_tok_eq t opr_w_publish olx_tok_eq t opr_w_promote 168 ret true 169 end 170 if or olx_tok_eq t opr_w_authority or olx_tok_eq t opr_w_admin olx_tok_eq t opr_w_syscall 171 ret true 172 end 173 if or olx_tok_eq t opr_w_io or olx_tok_eq t opr_w_print olx_tok_eq t opr_w_import 174 ret true 175 end 176 ret or olx_tok_eq t opr_w_extern or olx_tok_eq t opr_w_unsafe olx_tok_eq t opr_w_asm 177 end 178 179 fn opr_res_control t ulong to bool 180 if or olx_tok_eq t opr_w_if or olx_tok_eq t opr_w_else olx_tok_eq t opr_w_while 181 ret true 182 end 183 if or olx_tok_eq t opr_w_for or olx_tok_eq t opr_w_loop olx_tok_eq t opr_w_return 184 ret true 185 end 186 if or olx_tok_eq t opr_w_match or olx_tok_eq t opr_w_struct olx_tok_eq t opr_w_enum 187 ret true 188 end 189 if or olx_tok_eq t opr_w_mut or olx_tok_eq t opr_w_var olx_tok_eq t opr_w_const 190 ret true 191 end 192 ret or olx_tok_eq t opr_w_self olx_tok_eq t opr_w_rec 193 end 194 195 fn opr_is_reserved t ulong to bool 196 if ne olx_keyword t 1 197 ret true 198 end 199 if opr_res_types t 200 ret true 201 end 202 if opr_res_effects t 203 ret true 204 end 205 ret opr_res_control t 206 end 207 208 note ---- parse_type ---- 209 text opr_m_type "expected a type (u8, u16, u32, u64 or bool)" 210 text opr_m_signed "signed integers are not supported in V0 (the existing builders and evaluator are unsigned-only)" 211 text opr_m_nott " is not a V0 type (use u8, u16, u32, u64 or bool)" 212 213 note parse_type: 0 with the type in opr_ty_tag / opr_ty_wid 214 fn opr_parse_type to long 215 t = get opr_pos 0 216 col = get olx_tcol t 217 if ne get olx_tkind t 1 218 olx_failt col opr_m_type 219 ret -1 220 end 221 tag = V_TY_UINT 222 wid = ulong 0 223 if olx_tok_eq t opr_w_u8 224 wid = 8 225 end 226 if olx_tok_eq t opr_w_u16 227 wid = 16 228 end 229 if olx_tok_eq t opr_w_u32 230 wid = 32 231 end 232 if olx_tok_eq t opr_w_u64 233 wid = 64 234 end 235 if olx_tok_eq t opr_w_bool 236 tag = V_TY_BOOL 237 wid = 1 238 end 239 if eq wid 0 240 if or or olx_tok_eq t opr_w_i8 olx_tok_eq t opr_w_i16 or olx_tok_eq t opr_w_i32 olx_tok_eq t opr_w_i64 241 olx_failt col opr_m_signed 242 ret -2 243 end 244 olm_reset 245 olm_c 39 246 olm_tstr t 247 olm_c 39 248 olm_t opr_m_nott 249 olm_cap 159 250 olx_fail col 251 ret -2 252 end 253 put opr_ty_tag 0 tag 254 put opr_ty_wid 0 wid 255 opr_next 256 ret 0 257 end 258 259 text opr_m_large "expression is too large for V0 (node limit reached)" 260 261 note alloc_or_fail: 0 with the new node in opr_out, or -3 262 fn opr_alloc kind ulong col ulong to long 263 c = get opr_ncnt 0 264 if ge c OPR_MAX_NODES 265 olx_failt col opr_m_large 266 ret -3 267 end 268 put opr_ncnt 0 add c 1 269 put opr_nkind c kind 270 put opr_ncol c col 271 put opr_nop c 0 272 put opr_nlhs c -1 273 put opr_nrhs c -1 274 put opr_nval c 0 275 put opr_nslen c 0 276 put opr_nttag c 0 277 put opr_ntwid c 0 278 put opr_out 0 long c 279 ret 0 280 end 281 282 text opr_m_res " is reserved: effects, authority, control flow and type names are not values in Omega V0" 283 284 fn opr_reserved_msg t ulong to long 285 olm_reset 286 olm_c 39 287 olm_tstr t 288 olm_c 39 289 olm_t opr_m_res 290 olm_cap 199 291 olx_fail get olx_tcol t 292 ret -2 293 end 294 295 fn opr_copy_name_node t ulong ni ulong to void 296 sl = get olx_tslen t 297 put opr_nslen ni sl 298 sb = mul t 64 299 db = mul ni 64 300 for i ulong sl bound 64 301 put opr_nstr add db i get olx_tstr add sb i 302 end 303 end 304 305 text opr_m_call "function calls are not supported in V0" 306 text opr_m_rparen "')'" 307 text opr_m_neg "negative numbers are not supported in V0 (unsigned integers only)" 308 text opr_m_not "'!' (logical not) is not supported in V0" 309 text opr_m_block "blocks and records are not supported in V0 expressions" 310 text opr_m_kw "keyword cannot be used inside an expression" 311 text opr_m_value "expected a value but found '" 312 313 fn opr_parse_primary depth ulong to long 314 t = get opr_pos 0 315 k = get olx_tkind t 316 col = get olx_tcol t 317 if eq k 2 318 rc = opr_alloc 1 col 319 if ne rc 0 320 ret rc 321 end 322 put opr_nval ulong get opr_out 0 get olx_tval t 323 opr_next 324 ret 0 325 end 326 if or eq k 7 eq k 8 327 rc = opr_alloc 2 col 328 if ne rc 0 329 ret rc 330 end 331 if eq k 7 332 put opr_nval ulong get opr_out 0 1 333 end 334 opr_next 335 ret 0 336 end 337 if eq k 1 338 if eq opr_peek2 9 339 olx_failt col opr_m_call 340 ret -2 341 end 342 if opr_is_reserved t 343 ret opr_reserved_msg t 344 end 345 rc = opr_alloc 3 col 346 if ne rc 0 347 ret rc 348 end 349 opr_copy_name_node t ulong get opr_out 0 350 opr_next 351 ret 0 352 end 353 if eq k 9 354 opr_next 355 rc = opr_parse_expr add depth 1 356 if ne rc 0 357 ret rc 358 end 359 inner = get opr_out 0 360 if eq opr_peek 13 361 ccol = opr_peek_col 362 opr_next 363 rc = opr_parse_type 364 if ne rc 0 365 ret rc 366 end 367 rc = opr_alloc 5 ccol 368 if ne rc 0 369 ret rc 370 end 371 ni = ulong get opr_out 0 372 put opr_nlhs ni inner 373 put opr_nttag ni get opr_ty_tag 0 374 put opr_ntwid ni get opr_ty_wid 0 375 inner = long ni 376 end 377 rc = opr_expect 10 opr_m_rparen 378 if ne rc 0 379 ret rc 380 end 381 put opr_out 0 inner 382 ret 0 383 end 384 if eq k 18 385 olx_failt col opr_m_neg 386 ret -2 387 end 388 if eq k 29 389 olx_failt col opr_m_not 390 ret -2 391 end 392 if eq k 11 393 olx_failt col opr_m_block 394 ret -2 395 end 396 if and ge k 3 le k 6 397 olx_failt col opr_m_kw 398 ret -1 399 end 400 olm_reset 401 olm_t opr_m_value 402 olm_tok k 403 olm_c 39 404 olm_cap 127 405 olx_fail col 406 ret -1 407 end 408 409 note precedence level of a token kind, lowest first; 5 = not a binary operator 410 fn opr_level_of k ulong to ulong 411 if and ge k 23 le k 28 412 ret 0 413 end 414 if eq k 22 415 ret 1 416 end 417 if eq k 21 418 ret 2 419 end 420 if or eq k 17 eq k 18 421 ret 3 422 end 423 if or eq k 19 eq k 20 424 ret 4 425 end 426 ret 5 427 end 428 429 text opr_m_chain "comparisons cannot be chained; use parentheses" 430 431 fn opr_parse_level level ulong depth ulong to long 432 if gt level 4 433 ret opr_parse_primary depth 434 end 435 rc = opr_parse_level add level 1 depth 436 if ne rc 0 437 ret rc 438 end 439 lhs = get opr_out 0 440 seen = ulong 0 441 while eq opr_level_of opr_peek level bound 256 442 ot = get opr_pos 0 443 opr_next 444 if and eq level 0 gt seen 0 445 olx_failt get olx_tcol ot opr_m_chain 446 ret -1 447 end 448 seen = add seen 1 449 rc = opr_parse_level add level 1 depth 450 if ne rc 0 451 ret rc 452 end 453 rhs = get opr_out 0 454 rc = opr_alloc 4 get olx_tcol ot 455 if ne rc 0 456 ret rc 457 end 458 ni = ulong get opr_out 0 459 put opr_nop ni get olx_tkind ot 460 put opr_nlhs ni lhs 461 put opr_nrhs ni rhs 462 lhs = long ni 463 end 464 put opr_out 0 lhs 465 ret 0 466 end 467 468 text opr_m_deep "expression is nested too deeply for V0 (limit 32)" 469 470 fn opr_parse_expr depth ulong to long 471 if gt depth OPR_MAX_DEPTH 472 olx_failt opr_peek_col opr_m_deep 473 ret -3 474 end 475 ret opr_parse_level 0 depth 476 end 477 478 text opr_m_unexp "unexpected '" 479 text opr_m_after "' after the end of the statement" 480 481 fn opr_expect_end to long 482 t = get opr_pos 0 483 if eq get olx_tkind t 0 484 ret 0 485 end 486 olm_reset 487 olm_t opr_m_unexp 488 olm_found t 489 olm_t opr_m_after 490 olm_cap 127 491 olx_fail get olx_tcol t 492 ret -1 493 end 494 495 text opr_m_name "expected a name" 496 text opr_m_last "'_' is reserved for the last result" 497 498 fn opr_check_binding_name t ulong to long 499 col = get olx_tcol t 500 if ne get olx_tkind t 1 501 olx_failt col opr_m_name 502 ret -1 503 end 504 if olx_tok_eq t opr_w_us 505 olx_failt col opr_m_last 506 ret -1 507 end 508 if opr_is_reserved t 509 ret opr_reserved_msg t 510 end 511 ret 0 512 end 513 514 note ---- parse_clause: canonical contract text into opr_ctxt slot dst ---- 515 text opr_m_nobody "contract clause is not followed by the function body '{ ... }'" 516 text opr_m_resonly "'result' can only appear in 'ensures'" 517 text opr_m_cid " is not allowed in a contract (only the parameter, 'result', numbers and operators)" 518 text opr_m_unbal "unbalanced ')' in contract clause" 519 text opr_m_ctok " is not allowed in a contract clause" 520 text opr_m_clong "contract clause is longer than 63 characters (V0 contract text limit)" 521 text opr_m_cempty "empty contract clause" 522 text opr_w_x "x" 523 524 fn opr_tok_is_param t ulong to bool 525 pl = get opr_plen 0 526 if ne get olx_tslen t pl 527 ret false 528 end 529 b = mul t 64 530 for i ulong pl bound 64 531 if ne get olx_tstr add b i get opr_param i 532 ret false 533 end 534 end 535 ret true 536 end 537 538 fn opr_pc_t s view uchar * to void 539 n = len s 540 for i ulong n bound 96 541 put opr_pc i get s i 542 end 543 put opr_pcl 0 n 544 end 545 546 note the piece of one clause token into opr_pc: 0, or the C return code 547 fn opr_clause_piece t ulong allow_result bool to long 548 k = get olx_tkind t 549 col = get olx_tcol t 550 if eq k 1 551 if opr_tok_is_param t 552 opr_pc_t opr_w_x 553 ret 0 554 end 555 if olx_tok_eq t opr_w_result 556 if not allow_result 557 olx_failt col opr_m_resonly 558 ret -2 559 end 560 opr_pc_t opr_w_result 561 ret 0 562 end 563 olm_reset 564 olm_c 39 565 olm_tstr t 566 olm_c 39 567 olm_t opr_m_cid 568 olm_cap 159 569 olx_fail col 570 ret -2 571 end 572 olm_reset 573 if eq k 2 574 olm_u get olx_tval t 575 else 576 if or or eq k 7 eq k 8 and ge k 17 le k 29 577 olm_tok k 578 else 579 if or eq k 9 eq k 10 580 olm_tok k 581 else 582 olm_c 39 583 olm_tok k 584 olm_c 39 585 olm_t opr_m_ctok 586 olm_cap 127 587 olx_fail col 588 ret -1 589 end 590 end 591 end 592 n = get olm_n 0 593 for i ulong n bound 96 594 put opr_pc i get olm_b i 595 end 596 put opr_pcl 0 n 597 ret 0 598 end 599 600 note parse_clause state: text length, paren depth, first token, previous token was '(' 601 global opr_cl_len ulong 1 602 global opr_cl_par ulong 1 603 global opr_cl_first ulong 1 604 global opr_cl_plp ulong 1 605 606 note opr_pc appended to clause dst after sp spaces: 0, or -2 when the text would pass 63 bytes 607 fn opr_clause_append dst ulong sp ulong scol ulong to long 608 ln = get opr_cl_len 0 609 pl = get opr_pcl 0 610 if ge add add ln sp pl 64 611 olx_failt scol opr_m_clong 612 ret -2 613 end 614 db = add mul dst 64 ln 615 if eq sp 1 616 put opr_ctxt db uchar 32 617 db = add db 1 618 end 619 for i ulong pl bound 96 620 put opr_ctxt add db i get opr_pc i 621 end 622 ln = add add ln sp pl 623 put opr_cl_len 0 ln 624 put opr_clen dst ln 625 ret 0 626 end 627 628 note one clause token t appended to clause dst (start column scol): 0 or the C return code 629 fn opr_clause_tok t ulong allow_result bool dst ulong scol ulong to long 630 k = get olx_tkind t 631 if eq k 0 632 olx_failt get olx_tcol t opr_m_nobody 633 ret -1 634 end 635 if and eq k 10 eq get opr_cl_par 0 0 636 olx_failt get olx_tcol t opr_m_unbal 637 ret -1 638 end 639 rc = opr_clause_piece t allow_result 640 if ne rc 0 641 ret rc 642 end 643 if eq k 9 644 put opr_cl_par 0 add get opr_cl_par 0 1 645 end 646 if eq k 10 647 put opr_cl_par 0 sub get opr_cl_par 0 1 648 end 649 sp = ulong 0 650 if and and eq get opr_cl_first 0 0 eq get opr_cl_plp 0 0 ne k 10 651 sp = 1 652 end 653 rc2 = opr_clause_append dst sp scol 654 if ne rc2 0 655 ret rc2 656 end 657 put opr_cl_first 0 0 658 if eq k 9 659 put opr_cl_plp 0 1 660 else 661 put opr_cl_plp 0 0 662 end 663 ret 0 664 end 665 666 fn opr_parse_clause stop1 ulong stop2 ulong allow_result bool dst ulong to long 667 put opr_cl_len 0 0 668 put opr_cl_par 0 0 669 put opr_cl_first 0 1 670 put opr_cl_plp 0 0 671 put opr_clen dst 0 672 scol = opr_peek_col 673 while true bound 260 674 t = get opr_pos 0 675 k = get olx_tkind t 676 if eq get opr_cl_par 0 0 677 if or eq k stop1 eq k stop2 678 break 679 end 680 end 681 rc = opr_clause_tok t allow_result dst scol 682 if ne rc 0 683 ret rc 684 end 685 opr_next 686 end 687 if eq get opr_cl_first 0 1 688 olx_failt opr_peek_col opr_m_cempty 689 ret -1 690 end 691 ret 0 692 end 693 694 text opr_w_true "true" 695 696 fn opr_clause_default dst ulong to void 697 db = mul dst 64 698 n = len opr_w_true 699 for i ulong n bound 8 700 put opr_ctxt add db i get opr_w_true i 701 end 702 put opr_clen dst n 703 end 704 705 note ---- parse_fn ---- 706 text opr_m_lp "'(' after the function name" 707 text opr_m_one "V0 functions take exactly one parameter" 708 text opr_m_same "parameter cannot share the function's name (recursion is not supported)" 709 text opr_m_pcolon "':' and a parameter type" 710 text opr_m_arrow "'->' and a result type" 711 text opr_m_lbrace "'{' starting the function body" 712 text opr_m_rbrace "'}' closing the function body" 713 714 fn opr_param_is_name to bool 715 if ne get opr_plen 0 get opr_nlen 0 716 ret false 717 end 718 for i ulong get opr_plen 0 bound 64 719 if ne get opr_param i get opr_name i 720 ret false 721 end 722 end 723 ret true 724 end 725 726 fn opr_parse_fn to long 727 opr_next 728 nm = get opr_pos 0 729 rc = opr_check_binding_name nm 730 if ne rc 0 731 ret rc 732 end 733 nl = get olx_tslen nm 734 put opr_nlen 0 nl 735 for i ulong nl bound 64 736 put opr_name i get olx_tstr add mul nm 64 i 737 end 738 opr_next 739 rc = opr_expect 9 opr_m_lp 740 if ne rc 0 741 ret rc 742 end 743 if eq opr_peek 10 744 olx_failt opr_peek_col opr_m_one 745 ret -2 746 end 747 pn = get opr_pos 0 748 rc = opr_check_binding_name pn 749 if ne rc 0 750 ret rc 751 end 752 pl = get olx_tslen pn 753 put opr_plen 0 pl 754 for i ulong pl bound 64 755 put opr_param i get olx_tstr add mul pn 64 i 756 end 757 if opr_param_is_name 758 olx_failt get olx_tcol pn opr_m_same 759 ret -2 760 end 761 opr_next 762 rc = opr_expect 13 opr_m_pcolon 763 if ne rc 0 764 ret rc 765 end 766 rc = opr_parse_type 767 if ne rc 0 768 ret rc 769 end 770 put opr_pttag 0 get opr_ty_tag 0 771 put opr_ptwid 0 get opr_ty_wid 0 772 if eq opr_peek 14 773 olx_failt opr_peek_col opr_m_one 774 ret -2 775 end 776 rc = opr_expect 10 opr_m_rparen 777 if ne rc 0 778 ret rc 779 end 780 rc = opr_expect 15 opr_m_arrow 781 if ne rc 0 782 ret rc 783 end 784 rc = opr_parse_type 785 if ne rc 0 786 ret rc 787 end 788 put opr_rttag 0 get opr_ty_tag 0 789 put opr_rtwid 0 get opr_ty_wid 0 790 opr_clause_default 0 791 opr_clause_default 1 792 if eq opr_peek 5 793 opr_next 794 rc = opr_parse_clause 6 11 false 0 795 if ne rc 0 796 ret rc 797 end 798 end 799 if eq opr_peek 6 800 opr_next 801 rc = opr_parse_clause 11 11 true 1 802 if ne rc 0 803 ret rc 804 end 805 end 806 rc = opr_expect 11 opr_m_lbrace 807 if ne rc 0 808 ret rc 809 end 810 rc = opr_parse_expr 0 811 if ne rc 0 812 ret rc 813 end 814 put opr_root 0 get opr_out 0 815 rc = opr_expect 12 opr_m_rbrace 816 if ne rc 0 817 ret rc 818 end 819 ret opr_expect_end 820 end 821 822 note ---- omega_language_parse over the lexed tokens ---- 823 text opr_m_letcolon "':' and a type (V0 bindings need an explicit type: let x: u64 = 7)" 824 text opr_m_assign "'='" 825 826 fn opr_parse_let to long 827 opr_next 828 nm = get opr_pos 0 829 rc = opr_check_binding_name nm 830 if ne rc 0 831 ret rc 832 end 833 nl = get olx_tslen nm 834 put opr_nlen 0 nl 835 for i ulong nl bound 64 836 put opr_name i get olx_tstr add mul nm 64 i 837 end 838 opr_next 839 rc = opr_expect 13 opr_m_letcolon 840 if ne rc 0 841 ret rc 842 end 843 rc = opr_parse_type 844 if ne rc 0 845 ret rc 846 end 847 put opr_lttag 0 get opr_ty_tag 0 848 put opr_ltwid 0 get opr_ty_wid 0 849 rc = opr_expect 16 opr_m_assign 850 if ne rc 0 851 ret rc 852 end 853 rc = opr_parse_expr 0 854 if ne rc 0 855 ret rc 856 end 857 put opr_root 0 get opr_out 0 858 ret opr_expect_end 859 end 860 861 fn opr_parse_line to long 862 put opr_pos 0 0 863 put opr_ncnt 0 0 864 put opr_stmt 0 0 865 put opr_root 0 -1 866 put opr_nlen 0 0 867 put opr_plen 0 0 868 put opr_lttag 0 0 869 put opr_ltwid 0 0 870 put opr_pttag 0 0 871 put opr_ptwid 0 0 872 put opr_rttag 0 0 873 put opr_rtwid 0 0 874 put opr_clen 0 0 875 put opr_clen 1 0 876 k = opr_peek 877 put opr_scol 0 opr_peek_col 878 if eq k 0 879 ret 0 880 end 881 if eq k 3 882 put opr_stmt 0 2 883 ret opr_parse_let 884 end 885 if eq k 4 886 put opr_stmt 0 3 887 ret opr_parse_fn 888 end 889 put opr_stmt 0 1 890 rc = opr_parse_expr 0 891 if ne rc 0 892 ret rc 893 end 894 root = get opr_out 0 895 if eq opr_peek 13 896 ccol = opr_peek_col 897 opr_next 898 rc = opr_parse_type 899 if ne rc 0 900 ret rc 901 end 902 rc = opr_alloc 5 ccol 903 if ne rc 0 904 ret rc 905 end 906 ni = ulong get opr_out 0 907 put opr_nlhs ni root 908 put opr_nttag ni get opr_ty_tag 0 909 put opr_ntwid ni get opr_ty_wid 0 910 root = long ni 911 end 912 put opr_root 0 root 913 ret opr_expect_end 914 end