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
omega-mv / src / source-aware / core.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | note Handwritten bounded source-aware layer. Lower OSC and checker2 are external unchanged interfaces. |
| 3 | global Ib uchar 8192 |
| 4 | global Eb uchar 8192 |
| 5 | global El ulong 1 |
| 6 | global M ulong 8 |
| 7 | global Cp ulong 4 |
| 8 | global Oc ulong 64 |
| 9 | global Ot ulong 64 |
| 10 | global Oat ulong 64 |
| 11 | global Oef ulong 64 |
| 12 | global Oal ulong 64 |
| 13 | global Oob ulong 64 |
| 14 | global Oa ulong 64 |
| 15 | global Ob ulong 64 |
| 16 | global Oi ulong 64 |
| 17 | global Ss ulong 64 |
| 18 | global Se ulong 64 |
| 19 | global Src ulong 3 |
| 20 | text Conhex "d4ed6148bfa97cc693d3fa4495e2d7e2e68aba04607a7e96dd9a9c54bf9073a8" |
| 21 | text Semdom "omega.source.semantic.v1" |
| 22 | text Provdom "omega.source.provenance.v1" |
| 23 | |
| 24 | fn number off ulong size ulong to ulong |
| 25 | v = ulong 0 |
| 26 | for i ulong size |
| 27 | v = or v shl ulong get Ib add off i mul i 8 |
| 28 | end |
| 29 | ret v |
| 30 | end |
| 31 | |
| 32 | fn magic off ulong val ulong to bool |
| 33 | ret eq number off 4 val |
| 34 | end |
| 35 | |
| 36 | fn nib c uchar to ulong |
| 37 | if le c 57 |
| 38 | ret sub ulong c 48 |
| 39 | end |
| 40 | ret add sub ulong c 97 10 |
| 41 | end |
| 42 | |
| 43 | fn contract to bool |
| 44 | for i ulong 32 |
| 45 | a = nib get Conhex mul i 2 |
| 46 | b = nib get Conhex add mul i 2 1 |
| 47 | if ne ulong get Ib add 25 i add mul a 16 b |
| 48 | ret false |
| 49 | end |
| 50 | end |
| 51 | ret true |
| 52 | end |
| 53 | |
| 54 | fn part off ulong n ulong to void |
| 55 | for i ulong n |
| 56 | hbyte get Ib add off i |
| 57 | end |
| 58 | end |
| 59 | |
| 60 | fn hashed off ulong n ulong at ulong to bool |
| 61 | hinit |
| 62 | part off n |
| 63 | finish |
| 64 | for i ulong 32 |
| 65 | if ne get Hash i get Ib add at i |
| 66 | ret false |
| 67 | end |
| 68 | end |
| 69 | ret true |
| 70 | end |
| 71 | |
| 72 | fn refok a ulong ty ulong i ulong to bool |
| 73 | if ge a i |
| 74 | ret false |
| 75 | end |
| 76 | ret eq get Ot a ty |
| 77 | end |
| 78 | |
| 79 | fn aliasok a ulong to bool |
| 80 | if eq a 255 |
| 81 | ret true |
| 82 | end |
| 83 | ret and ge a 1 le a 8 |
| 84 | end |
| 85 | |
| 86 | fn pureop i ulong to ulong |
| 87 | if ne get Oef i 0 |
| 88 | ret 71 |
| 89 | end |
| 90 | if ne get Oal i 0 |
| 91 | ret 71 |
| 92 | end |
| 93 | ret 0 |
| 94 | end |
| 95 | |
| 96 | fn arith i ulong to ulong |
| 97 | ty = get Ot i |
| 98 | if gt ty 2 |
| 99 | ret 70 |
| 100 | end |
| 101 | if ne get Oat i ty |
| 102 | ret 70 |
| 103 | end |
| 104 | if eq refok get Oa i ty i false |
| 105 | ret 70 |
| 106 | end |
| 107 | if eq refok get Ob i ty i false |
| 108 | ret 70 |
| 109 | end |
| 110 | if ne get Oi i 0 |
| 111 | ret 65 |
| 112 | end |
| 113 | need = ulong 8 |
| 114 | if eq ty 1 |
| 115 | if ne pureop i 0 |
| 116 | ret 71 |
| 117 | end |
| 118 | need = 1 |
| 119 | if eq get M 1 4 |
| 120 | need = or need 4 |
| 121 | end |
| 122 | if eq get M 1 6 |
| 123 | need = or need 4 |
| 124 | end |
| 125 | else |
| 126 | if ne get Oef i 20 |
| 127 | ret 71 |
| 128 | end |
| 129 | if ne get Oal i 255 |
| 130 | ret 71 |
| 131 | end |
| 132 | end |
| 133 | if eq get Oc i 5 |
| 134 | need = or need 2 |
| 135 | end |
| 136 | if ne get Oob i need |
| 137 | ret 72 |
| 138 | end |
| 139 | ret 0 |
| 140 | end |
| 141 | |
| 142 | fn memop i ulong to ulong |
| 143 | if ne get M 1 6 |
| 144 | ret 68 |
| 145 | end |
| 146 | if ne get Ot i 1 |
| 147 | ret 70 |
| 148 | end |
| 149 | if ne get Oat i 4 |
| 150 | ret 70 |
| 151 | end |
| 152 | if eq refok get Oa i 4 i false |
| 153 | ret 70 |
| 154 | end |
| 155 | if eq refok get Ob i 1 i false |
| 156 | ret 70 |
| 157 | end |
| 158 | if eq aliasok get Oal i false |
| 159 | ret 71 |
| 160 | end |
| 161 | if ne get Oal i get Oal get Oa i |
| 162 | ret 71 |
| 163 | end |
| 164 | need = ulong 17 |
| 165 | if eq get Oc i 8 |
| 166 | need = 19 |
| 167 | if eq refok get Oi i 1 i false |
| 168 | ret 70 |
| 169 | end |
| 170 | else |
| 171 | if ne get Oi i 0 |
| 172 | ret 65 |
| 173 | end |
| 174 | end |
| 175 | if ne get Oef i need |
| 176 | ret 71 |
| 177 | end |
| 178 | if ne get Oob i 24 |
| 179 | ret 72 |
| 180 | end |
| 181 | ret 0 |
| 182 | end |
| 183 | |
| 184 | fn checkop i ulong to ulong |
| 185 | code = get Oc i |
| 186 | ty = get Ot i |
| 187 | if eq ty 0 |
| 188 | ret 70 |
| 189 | end |
| 190 | if gt ty 4 |
| 191 | ret 70 |
| 192 | end |
| 193 | if eq get M 1 3 |
| 194 | if ne ty 2 |
| 195 | ret 68 |
| 196 | end |
| 197 | else |
| 198 | if ne get M 1 6 |
| 199 | if ne ty 1 |
| 200 | ret 68 |
| 201 | end |
| 202 | end |
| 203 | end |
| 204 | if eq code 0 |
| 205 | ret 69 |
| 206 | end |
| 207 | if gt code 9 |
| 208 | ret 69 |
| 209 | end |
| 210 | if eq code 1 |
| 211 | if gt ty 2 |
| 212 | ret 70 |
| 213 | end |
| 214 | if ne get Oat i ty |
| 215 | ret 70 |
| 216 | end |
| 217 | if ne get Oa i 65535 |
| 218 | ret 70 |
| 219 | end |
| 220 | if ne get Ob i 65535 |
| 221 | ret 70 |
| 222 | end |
| 223 | if ne get Oob i 0 |
| 224 | ret 72 |
| 225 | end |
| 226 | ret pureop i |
| 227 | end |
| 228 | if le code 5 |
| 229 | ret arith i |
| 230 | end |
| 231 | if eq code 6 |
| 232 | if ne get M 1 6 |
| 233 | ret 68 |
| 234 | end |
| 235 | if ne ty 3 |
| 236 | ret 70 |
| 237 | end |
| 238 | if ne get Oat i 3 |
| 239 | ret 70 |
| 240 | end |
| 241 | if eq refok get Oa i 3 i false |
| 242 | ret 70 |
| 243 | end |
| 244 | if ne get Ob i 65535 |
| 245 | ret 70 |
| 246 | end |
| 247 | if ne get Oi i 0 |
| 248 | ret 65 |
| 249 | end |
| 250 | if ne get Oef i 63 |
| 251 | ret 71 |
| 252 | end |
| 253 | if ne get Oal i 255 |
| 254 | ret 71 |
| 255 | end |
| 256 | if ne get Oob i 8 |
| 257 | ret 72 |
| 258 | end |
| 259 | ret 0 |
| 260 | end |
| 261 | if le code 8 |
| 262 | ret memop i |
| 263 | end |
| 264 | if ne get Oat i 0 |
| 265 | ret 70 |
| 266 | end |
| 267 | if ne get Oa i 65535 |
| 268 | ret 70 |
| 269 | end |
| 270 | if ne get Ob i 65535 |
| 271 | ret 70 |
| 272 | end |
| 273 | if gt get Oi i 5 |
| 274 | ret 67 |
| 275 | end |
| 276 | for j ulong i |
| 277 | if eq get Oc j 9 |
| 278 | if eq get Oi j get Oi i |
| 279 | ret 70 |
| 280 | end |
| 281 | end |
| 282 | end |
| 283 | if ne get Oob i 1 |
| 284 | ret 72 |
| 285 | end |
| 286 | if ne get Oef i 0 |
| 287 | ret 71 |
| 288 | end |
| 289 | if eq ty 4 |
| 290 | if eq aliasok get Oal i false |
| 291 | ret 71 |
| 292 | end |
| 293 | else |
| 294 | if ne get Oal i 0 |
| 295 | ret 71 |
| 296 | end |
| 297 | end |
| 298 | ret 0 |
| 299 | end |
| 300 | |
| 301 | fn profile to ulong |
| 302 | p = get M 1 |
| 303 | l = get M 0 |
| 304 | r = get M 2 |
| 305 | abi = get M 3 |
| 306 | if eq p 0 |
| 307 | ret 68 |
| 308 | end |
| 309 | if gt p 6 |
| 310 | ret 68 |
| 311 | end |
| 312 | if eq p 1 |
| 313 | if ne l 1 |
| 314 | ret 68 |
| 315 | end |
| 316 | end |
| 317 | if eq p 2 |
| 318 | if ne l 2 |
| 319 | ret 68 |
| 320 | end |
| 321 | end |
| 322 | if eq p 5 |
| 323 | if ne l 4 |
| 324 | ret 68 |
| 325 | end |
| 326 | end |
| 327 | if eq p 3 |
| 328 | if ne l 3 |
| 329 | ret 68 |
| 330 | end |
| 331 | end |
| 332 | if eq p 4 |
| 333 | if ne l 3 |
| 334 | ret 68 |
| 335 | end |
| 336 | end |
| 337 | if eq p 6 |
| 338 | if ne l 3 |
| 339 | ret 68 |
| 340 | end |
| 341 | end |
| 342 | if or eq p 3 eq p 6 |
| 343 | if or eq r 0 gt r 2 |
| 344 | ret 68 |
| 345 | end |
| 346 | if eq p 6 |
| 347 | if ne abi 2 |
| 348 | ret 68 |
| 349 | end |
| 350 | else |
| 351 | if ne abi 1 |
| 352 | ret 68 |
| 353 | end |
| 354 | end |
| 355 | else |
| 356 | if ne r 0 |
| 357 | ret 68 |
| 358 | end |
| 359 | if ne abi 1 |
| 360 | ret 68 |
| 361 | end |
| 362 | end |
| 363 | ret 0 |
| 364 | end |
| 365 | |
| 366 | fn ops to ulong |
| 367 | for i ulong get M 4 |
| 368 | off = add 57 mul i 20 |
| 369 | if ne ulong get Ib off get M 0 |
| 370 | ret 68 |
| 371 | end |
| 372 | if ne get Ib add off 1 1 |
| 373 | ret 66 |
| 374 | end |
| 375 | put Oc i number add off 2 1 |
| 376 | put Ot i number add off 3 1 |
| 377 | put Oat i number add off 4 1 |
| 378 | put Oef i number add off 5 1 |
| 379 | put Oal i number add off 6 1 |
| 380 | put Oob i number add off 7 1 |
| 381 | put Oa i number add off 8 2 |
| 382 | put Ob i number add off 10 2 |
| 383 | put Oi i number add off 12 8 |
| 384 | code = checkop i |
| 385 | if ne code 0 |
| 386 | ret code |
| 387 | end |
| 388 | end |
| 389 | ret 0 |
| 390 | end |
| 391 | |
| 392 | fn utf8 off ulong n ulong to bool |
| 393 | pos = ulong 0 |
| 394 | while lt pos n |
| 395 | c = ulong get Ib add off pos |
| 396 | pos = add pos 1 |
| 397 | if ge c 128 |
| 398 | extra = ulong 0 |
| 399 | v = ulong 0 |
| 400 | low = ulong 0 |
| 401 | if and ge c 194 le c 223 |
| 402 | extra = 1 |
| 403 | v = and c 31 |
| 404 | low = 128 |
| 405 | end |
| 406 | if and ge c 224 le c 239 |
| 407 | extra = 2 |
| 408 | v = and c 15 |
| 409 | low = 2048 |
| 410 | end |
| 411 | if and ge c 240 le c 244 |
| 412 | extra = 3 |
| 413 | v = and c 7 |
| 414 | low = 65536 |
| 415 | end |
| 416 | if eq extra 0 |
| 417 | ret false |
| 418 | end |
| 419 | if gt extra sub n pos |
| 420 | ret false |
| 421 | end |
| 422 | for j ulong extra |
| 423 | c = ulong get Ib add off pos |
| 424 | if or lt c 128 gt c 191 |
| 425 | ret false |
| 426 | end |
| 427 | v = or shl v 6 and c 63 |
| 428 | pos = add pos 1 |
| 429 | end |
| 430 | if lt v low |
| 431 | ret false |
| 432 | end |
| 433 | if gt v 1114111 |
| 434 | ret false |
| 435 | end |
| 436 | if and ge v 55296 le v 57343 |
| 437 | ret false |
| 438 | end |
| 439 | end |
| 440 | end |
| 441 | ret true |
| 442 | end |
| 443 | |
| 444 | fn boundary pos ulong to bool |
| 445 | if eq pos get Src 1 |
| 446 | ret true |
| 447 | end |
| 448 | c = ulong get Ib add get Src 0 pos |
| 449 | ret or lt c 128 gt c 191 |
| 450 | end |
| 451 | |
| 452 | fn sidecar to ulong |
| 453 | off = get M 7 |
| 454 | size = get M 6 |
| 455 | if lt size 74 |
| 456 | ret 65 |
| 457 | end |
| 458 | if eq magic off 1347636559 false |
| 459 | ret 65 |
| 460 | end |
| 461 | if ne get Ib add off 4 1 |
| 462 | ret 66 |
| 463 | end |
| 464 | enc = number add off 5 1 |
| 465 | if gt enc 1 |
| 466 | ret 76 |
| 467 | end |
| 468 | n = number add off 6 4 |
| 469 | if gt n 4096 |
| 470 | ret 67 |
| 471 | end |
| 472 | start = add off add 74 mul get M 4 8 |
| 473 | if ne size add add 74 mul get M 4 8 n |
| 474 | ret 65 |
| 475 | end |
| 476 | put Src 0 start |
| 477 | put Src 1 n |
| 478 | put Src 2 enc |
| 479 | if eq hashed 13 get M 5 add off 10 false |
| 480 | ret 74 |
| 481 | end |
| 482 | if eq hashed start n add off 42 false |
| 483 | ret 74 |
| 484 | end |
| 485 | if eq enc 1 |
| 486 | if eq utf8 start n false |
| 487 | ret 76 |
| 488 | end |
| 489 | end |
| 490 | for i ulong get M 4 |
| 491 | at = add off add 74 mul i 8 |
| 492 | a = number at 4 |
| 493 | b = number add at 4 4 |
| 494 | if or gt a b gt b n |
| 495 | ret 75 |
| 496 | end |
| 497 | put Ss i a |
| 498 | put Se i b |
| 499 | if eq enc 1 |
| 500 | if eq boundary a false |
| 501 | ret 75 |
| 502 | end |
| 503 | if eq boundary b false |
| 504 | ret 75 |
| 505 | end |
| 506 | end |
| 507 | end |
| 508 | ret 0 |
| 509 | end |
| 510 | |
| 511 | fn decode n ulong to ulong |
| 512 | put El 0 0 |
| 513 | if gt n 8192 |
| 514 | ret 67 |
| 515 | end |
| 516 | if lt n 13 |
| 517 | ret 65 |
| 518 | end |
| 519 | if eq magic 0 1112755535 false |
| 520 | ret 65 |
| 521 | end |
| 522 | if ne get Ib 4 1 |
| 523 | ret 66 |
| 524 | end |
| 525 | sn = number 5 4 |
| 526 | pn = number 9 4 |
| 527 | if or gt sn 1324 gt pn 4682 |
| 528 | ret 67 |
| 529 | end |
| 530 | if ne n add 13 add sn pn |
| 531 | ret 65 |
| 532 | end |
| 533 | if lt sn 44 |
| 534 | ret 65 |
| 535 | end |
| 536 | if eq magic 13 1095978319 false |
| 537 | ret 65 |
| 538 | end |
| 539 | if ne get Ib 17 1 |
| 540 | ret 66 |
| 541 | end |
| 542 | if ne get Ib 20 1 |
| 543 | ret 66 |
| 544 | end |
| 545 | put M 0 number 18 1 |
| 546 | put M 1 number 19 1 |
| 547 | put M 2 number 21 1 |
| 548 | put M 3 number 22 1 |
| 549 | put M 4 number 23 2 |
| 550 | put M 5 sn |
| 551 | put M 6 pn |
| 552 | put M 7 add 13 sn |
| 553 | if or eq get M 4 0 gt get M 4 64 |
| 554 | ret 67 |
| 555 | end |
| 556 | if ne sn add 44 mul get M 4 20 |
| 557 | ret 65 |
| 558 | end |
| 559 | if eq contract false |
| 560 | ret 78 |
| 561 | end |
| 562 | code = profile |
| 563 | if ne code 0 |
| 564 | ret code |
| 565 | end |
| 566 | code = ops |
| 567 | if ne code 0 |
| 568 | ret code |
| 569 | end |
| 570 | if ne pn 0 |
| 571 | ret sidecar |
| 572 | end |
| 573 | ret 0 |
| 574 | end |
| 575 | |
| 576 | fn ebyte v ulong to void |
| 577 | put Eb get El 0 uchar v |
| 578 | put El 0 add get El 0 1 |
| 579 | end |
| 580 | |
| 581 | fn emitnum v ulong n ulong to void |
| 582 | for i ulong n |
| 583 | ebyte and shr v mul i 8 255 |
| 584 | end |
| 585 | end |
| 586 | |
| 587 | fn emitpart off ulong n ulong to void |
| 588 | for i ulong n |
| 589 | ebyte ulong get Ib add off i |
| 590 | end |
| 591 | end |
| 592 | |
| 593 | fn encode to void |
| 594 | emitnum 1112755535 4 |
| 595 | ebyte 1 |
| 596 | emitnum get M 5 4 |
| 597 | emitnum get M 6 4 |
| 598 | emitnum 1095978319 4 |
| 599 | ebyte 1 |
| 600 | ebyte get M 0 |
| 601 | ebyte get M 1 |
| 602 | ebyte 1 |
| 603 | ebyte get M 2 |
| 604 | ebyte get M 3 |
| 605 | emitnum get M 4 2 |
| 606 | emitpart 25 32 |
| 607 | for i ulong get M 4 |
| 608 | ebyte get M 0 |
| 609 | ebyte 1 |
| 610 | ebyte get Oc i |
| 611 | ebyte get Ot i |
| 612 | ebyte get Oat i |
| 613 | ebyte get Oef i |
| 614 | ebyte get Oal i |
| 615 | ebyte get Oob i |
| 616 | emitnum get Oa i 2 |
| 617 | emitnum get Ob i 2 |
| 618 | emitnum get Oi i 8 |
| 619 | end |
| 620 | if ne get M 6 0 |
| 621 | emitnum 1347636559 4 |
| 622 | ebyte 1 |
| 623 | ebyte get Src 2 |
| 624 | emitnum get Src 1 4 |
| 625 | emitpart add get M 7 10 64 |
| 626 | for i ulong get M 4 |
| 627 | emitnum get Ss i 4 |
| 628 | emitnum get Se i 4 |
| 629 | end |
| 630 | emitpart get Src 0 get Src 1 |
| 631 | end |
| 632 | end |
| 633 | |
| 634 | fn digout to void |
| 635 | finish |
| 636 | for i ulong 32 |
| 637 | ebyte ulong get Hash i |
| 638 | end |
| 639 | end |
| 640 | |
| 641 | fn legal i ulong to ulong |
| 642 | if ne get Cp 2 get M 3 |
| 643 | ret 4 |
| 644 | end |
| 645 | if ne and get Oef i get Cp 3 get Oef i |
| 646 | ret 4 |
| 647 | end |
| 648 | if ne get M 2 0 |
| 649 | if ne get Cp 1 get M 2 |
| 650 | ret 2 |
| 651 | end |
| 652 | end |
| 653 | if eq get Cp 0 1 |
| 654 | ret 1 |
| 655 | end |
| 656 | if or eq get M 1 3 eq get M 1 6 |
| 657 | ret 4 |
| 658 | end |
| 659 | if ne get Ot i 1 |
| 660 | ret 4 |
| 661 | end |
| 662 | if le get Oc i 5 |
| 663 | ret 3 |
| 664 | end |
| 665 | if eq get Oc i 9 |
| 666 | ret 3 |
| 667 | end |
| 668 | ret 4 |
| 669 | end |
| 670 | |
| 671 | fn caps n ulong to ulong |
| 672 | if lt n 4 |
| 673 | ret 65 |
| 674 | end |
| 675 | for i ulong 4 |
| 676 | put Cp i number i 1 |
| 677 | end |
| 678 | if or eq get Cp 0 0 gt get Cp 0 2 |
| 679 | ret 68 |
| 680 | end |
| 681 | if gt get Cp 1 2 |
| 682 | ret 68 |
| 683 | end |
| 684 | if or eq get Cp 2 0 gt get Cp 2 2 |
| 685 | ret 68 |
| 686 | end |
| 687 | if gt get Cp 3 63 |
| 688 | ret 68 |
| 689 | end |
| 690 | for i ulong sub n 4 |
| 691 | put Ib i get Ib add i 4 |
| 692 | end |
| 693 | ret 0 |
| 694 | end |
| 695 | |
| 696 | fn perform mode ulong n ulong to ulong |
| 697 | put El 0 0 |
| 698 | if gt n 8192 |
| 699 | ret 67 |
| 700 | end |
| 701 | if or eq mode 0 gt mode 6 |
| 702 | ret 64 |
| 703 | end |
| 704 | if eq mode 6 |
| 705 | code = caps n |
| 706 | if ne code 0 |
| 707 | ret code |
| 708 | end |
| 709 | n = sub n 4 |
| 710 | end |
| 711 | code = decode n |
| 712 | if ne code 0 |
| 713 | ret code |
| 714 | end |
| 715 | if le mode 2 |
| 716 | encode |
| 717 | ret 0 |
| 718 | end |
| 719 | if eq mode 3 |
| 720 | hinit |
| 721 | for i ulong len Semdom |
| 722 | hbyte get Semdom i |
| 723 | end |
| 724 | part 13 get M 5 |
| 725 | digout |
| 726 | ret 0 |
| 727 | end |
| 728 | if eq mode 4 |
| 729 | hinit |
| 730 | for i ulong len Provdom |
| 731 | hbyte get Provdom i |
| 732 | end |
| 733 | part 0 n |
| 734 | digout |
| 735 | ret 0 |
| 736 | end |
| 737 | if eq mode 5 |
| 738 | if eq get M 6 0 |
| 739 | ret 73 |
| 740 | end |
| 741 | emitpart get Src 0 get Src 1 |
| 742 | ret 0 |
| 743 | end |
| 744 | for i ulong get M 4 |
| 745 | ebyte legal i |
| 746 | ebyte get Oob i |
| 747 | end |
| 748 | ret 0 |
| 749 | end |