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 / seed / profile / profile.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Critical source profile. Compile the checked unit too; this is not a parser/typechecker. |
| 3 | note Full-byte token identity, finite pools, fail-closed capacity checks. See README. |
| 4 | global src uchar 65536 |
| 5 | global off ulong 16384 |
| 6 | global siz ulong 16384 |
| 7 | global ls ulong 4096 |
| 8 | global lc ulong 4096 |
| 9 | global lf ulong 4096 |
| 10 | global dep ulong 4096 |
| 11 | global fs ulong 128 |
| 12 | global fe ulong 128 |
| 13 | global nm ulong 128 |
| 14 | global fx uchar 128 |
| 15 | global mem ulong 128 |
| 16 | global edges uchar 16384 |
| 17 | global weak uchar 16384 |
| 18 | global reach uchar 16384 |
| 19 | global alive uchar 128 |
| 20 | global ko ulong 64 |
| 21 | global kl ulong 64 |
| 22 | global st ulong 8 |
| 23 | global host ulong 128 |
| 24 | global hb uchar 16384 |
| 25 | global arg uchar 4096 |
| 26 | global ob uchar 24 |
| 27 | text keys "note fn end if else while for bound new global text const to ret exit trap put requires ensures invariant om2 release = len ulong uint ushort uchar long int short byte view edit own add gt depth p10 effect allow E1 pure main" |
| 28 | text hp "seed/effects/effects.om" |
| 29 | text tpre "text tab " |
| 30 | text pass "PROFILE-PASS\n" |
| 31 | text bad "PROFILE-REFUSED:" |
| 32 | text rules "B1B2B3E1X1P1C1" |
| 33 | text lpre ":" |
| 34 | text inv "PROFILE-INVALID\n" |
| 35 | text use "profile [bounds] [SOURCE ...] < unit.om\n" |
| 36 | text bmode "bounds" |
| 37 | fn stop code int to void |
| 38 | if ne write 1 inv 0 len inv long len inv |
| 39 | exit 4 |
| 40 | end |
| 41 | exit code |
| 42 | end |
| 43 | note Rules: 0 B1 loop bound, 1 B2 recursion, 2 B3 allocation, 3 E1 checked result, 4 X1 effect boundary, 5 P1 pure, 6 C1 contract mode. |
| 44 | fn refuse rule ulong l ulong to void |
| 45 | if ne write 1 bad 0 len bad long len bad |
| 46 | exit 4 |
| 47 | end |
| 48 | if ne write 1 rules mul rule 2 2 2 |
| 49 | exit 4 |
| 50 | end |
| 51 | if ne write 1 lpre 0 len lpre long len lpre |
| 52 | exit 4 |
| 53 | end |
| 54 | put ob 23 10 |
| 55 | v = add l 1 |
| 56 | i = ulong 23 |
| 57 | for j ulong 20 bound 20 |
| 58 | i = sub i 1 |
| 59 | put ob i uchar add 48 rem v 10 |
| 60 | v = div v 10 |
| 61 | if eq v 0 |
| 62 | break |
| 63 | end |
| 64 | end |
| 65 | if ne write 1 ob i sub 24 i long sub 24 i |
| 66 | exit 4 |
| 67 | end |
| 68 | exit 1 |
| 69 | end |
| 70 | fn init to void |
| 71 | s = ulong 0 |
| 72 | k = ulong 0 |
| 73 | for i ulong len keys |
| 74 | if eq get keys i 32 |
| 75 | put ko k s |
| 76 | put kl k sub i s |
| 77 | k = add k 1 |
| 78 | s = add i 1 |
| 79 | end |
| 80 | end |
| 81 | put ko k s |
| 82 | put kl k sub len keys s |
| 83 | end |
| 84 | fn keyis t ulong k ulong to bool |
| 85 | if eq t 0 |
| 86 | ret false |
| 87 | end |
| 88 | if ne get siz t get kl k |
| 89 | ret false |
| 90 | end |
| 91 | o = get ko k |
| 92 | for j ulong get siz t bound 63 |
| 93 | x = get src add get off t j |
| 94 | if ne x get keys add o j |
| 95 | ret false |
| 96 | end |
| 97 | end |
| 98 | ret true |
| 99 | end |
| 100 | fn word t ulong to ulong |
| 101 | if or eq t 0 gt get siz t 8 |
| 102 | ret 0 |
| 103 | end |
| 104 | v = ulong 0 |
| 105 | for j ulong get siz t bound 8 |
| 106 | c = ulong get src add get off t j |
| 107 | v = or v shl c mul j 8 |
| 108 | end |
| 109 | ret v |
| 110 | end |
| 111 | fn at l ulong p ulong to ulong |
| 112 | if ge p get lc l |
| 113 | ret 0 |
| 114 | end |
| 115 | ret add get ls l p |
| 116 | end |
| 117 | fn is l ulong p ulong k ulong to bool |
| 118 | ret keyis at l p k |
| 119 | end |
| 120 | fn same a ulong b ulong to bool |
| 121 | if or eq a 0 eq b 0 |
| 122 | ret false |
| 123 | end |
| 124 | if ne get siz a get siz b |
| 125 | ret false |
| 126 | end |
| 127 | for j ulong get siz a bound 63 |
| 128 | x = get src add get off a j |
| 129 | y = get src add get off b j |
| 130 | if ne x y |
| 131 | ret false |
| 132 | end |
| 133 | end |
| 134 | ret true |
| 135 | end |
| 136 | fn number t ulong to ulong |
| 137 | if eq t 0 |
| 138 | ret 1048577 |
| 139 | end |
| 140 | v = ulong 0 |
| 141 | for j ulong get siz t bound 63 |
| 142 | c = get src add get off t j |
| 143 | if or lt c 48 gt c 57 |
| 144 | ret 1048577 |
| 145 | end |
| 146 | if gt v 1048576 |
| 147 | ret 1048577 |
| 148 | end |
| 149 | v = add mul v 10 sub ulong c 48 |
| 150 | end |
| 151 | ret v |
| 152 | end |
| 153 | fn value t ulong to ulong |
| 154 | v = number t |
| 155 | if le v 1048576 |
| 156 | ret v |
| 157 | end |
| 158 | for l ulong get st 1 bound 4096 |
| 159 | if is l 0 11 |
| 160 | if same t at l 1 |
| 161 | ret number at l 3 |
| 162 | end |
| 163 | end |
| 164 | end |
| 165 | ret 1048577 |
| 166 | end |
| 167 | fn func t ulong to ulong |
| 168 | for f ulong get st 2 bound 128 |
| 169 | if same t get nm f |
| 170 | ret f |
| 171 | end |
| 172 | end |
| 173 | ret 128 |
| 174 | end |
| 175 | fn token a ulong n ulong to void |
| 176 | if eq n 0 |
| 177 | ret |
| 178 | end |
| 179 | if gt n 63 |
| 180 | stop 3 |
| 181 | end |
| 182 | t = add get st 0 1 |
| 183 | if ge t 16384 |
| 184 | stop 3 |
| 185 | end |
| 186 | put off t a |
| 187 | put siz t n |
| 188 | put st 0 t |
| 189 | l = get st 1 |
| 190 | if eq get lc l 0 |
| 191 | put ls l t |
| 192 | end |
| 193 | put lc l add get lc l 1 |
| 194 | end |
| 195 | fn blank c ulong to bool |
| 196 | if or eq c 32 eq c 9 |
| 197 | ret true |
| 198 | end |
| 199 | if or eq c 13 eq c 40 |
| 200 | ret true |
| 201 | end |
| 202 | ret eq c 41 |
| 203 | end |
| 204 | fn tabpre i ulong to bool |
| 205 | for k ulong len tpre |
| 206 | if ne get hb add sub i len tpre k get tpre k |
| 207 | ret false |
| 208 | end |
| 209 | end |
| 210 | ret true |
| 211 | end |
| 212 | fn lex n ulong to void |
| 213 | a = ulong 0 |
| 214 | size = ulong 0 |
| 215 | quote = false |
| 216 | esc = false |
| 217 | skip = false |
| 218 | for i ulong n bound 65536 |
| 219 | c = get src i |
| 220 | if eq c 10 |
| 221 | token a size |
| 222 | size = ulong 0 |
| 223 | quote = false |
| 224 | esc = false |
| 225 | skip = false |
| 226 | l = add get st 1 1 |
| 227 | if ge l 4096 |
| 228 | stop 3 |
| 229 | end |
| 230 | put st 1 l |
| 231 | continue |
| 232 | end |
| 233 | if skip |
| 234 | continue |
| 235 | end |
| 236 | if quote |
| 237 | if esc |
| 238 | esc = false |
| 239 | else |
| 240 | if eq c 92 |
| 241 | esc = true |
| 242 | else |
| 243 | if eq c 34 |
| 244 | quote = false |
| 245 | end |
| 246 | end |
| 247 | end |
| 248 | continue |
| 249 | end |
| 250 | if eq c 34 |
| 251 | token a size |
| 252 | size = ulong 0 |
| 253 | quote = true |
| 254 | continue |
| 255 | end |
| 256 | if blank ulong c |
| 257 | token a size |
| 258 | size = ulong 0 |
| 259 | note Preserve only p10 annotations; ordinary comments need no bounded token storage. |
| 260 | l = get st 1 |
| 261 | if ge get lc l 2 |
| 262 | if and is l 0 0 not is l 1 38 |
| 263 | skip = true |
| 264 | end |
| 265 | end |
| 266 | continue |
| 267 | end |
| 268 | if eq size 0 |
| 269 | a = i |
| 270 | end |
| 271 | size = add size 1 |
| 272 | end |
| 273 | token a size |
| 274 | put st 1 add get st 1 1 |
| 275 | end |
| 276 | fn hosts to void |
| 277 | fd = fopen hp 0 len hp 0 0 |
| 278 | if lt fd 0 |
| 279 | stop 3 |
| 280 | end |
| 281 | n = read int fd hb 0 len hb |
| 282 | if ne fclose int fd 0 |
| 283 | stop 3 |
| 284 | end |
| 285 | if le n 0 |
| 286 | stop 3 |
| 287 | end |
| 288 | note Find the exact authoritative effects table prefix, then decode only its first column. |
| 289 | a = ulong 0 |
| 290 | found = false |
| 291 | for i ulong ulong n bound 16384 |
| 292 | c = get hb i |
| 293 | if ge i len tpre |
| 294 | if and eq c 34 tabpre i |
| 295 | a = add i 1 |
| 296 | found = true |
| 297 | break |
| 298 | end |
| 299 | end |
| 300 | end |
| 301 | if not found |
| 302 | stop 3 |
| 303 | end |
| 304 | hdecode a ulong n |
| 305 | end |
| 306 | note cnt 9 marks a row whose first column was already stored. |
| 307 | fn hdecode a ulong n ulong to void |
| 308 | w = ulong 0 |
| 309 | cnt = ulong 0 |
| 310 | for j ulong sub n a bound 16384 |
| 311 | c = get hb add a j |
| 312 | if eq c 34 |
| 313 | if eq get st 3 0 |
| 314 | stop 3 |
| 315 | end |
| 316 | ret |
| 317 | end |
| 318 | if eq c 110 |
| 319 | if eq get hb sub add a j 1 92 |
| 320 | w = ulong 0 |
| 321 | cnt = ulong 0 |
| 322 | continue |
| 323 | end |
| 324 | end |
| 325 | if lt cnt 9 |
| 326 | if eq c 32 |
| 327 | k = get st 3 |
| 328 | if ge k 128 |
| 329 | stop 3 |
| 330 | end |
| 331 | put host k w |
| 332 | put st 3 add k 1 |
| 333 | cnt = ulong 9 |
| 334 | else |
| 335 | if ge cnt 8 |
| 336 | stop 3 |
| 337 | end |
| 338 | w = or w shl ulong c mul cnt 8 |
| 339 | cnt = add cnt 1 |
| 340 | end |
| 341 | end |
| 342 | end |
| 343 | stop 3 |
| 344 | end |
| 345 | fn ishost t ulong to bool |
| 346 | w = word t |
| 347 | for i ulong get st 3 bound 128 |
| 348 | if eq w get host i |
| 349 | ret true |
| 350 | end |
| 351 | end |
| 352 | ret false |
| 353 | end |
| 354 | fn declarations to void |
| 355 | f = ulong 128 |
| 356 | d = ulong 0 |
| 357 | for l ulong get st 1 bound 4096 |
| 358 | if is l 0 1 |
| 359 | if ne d 0 |
| 360 | stop 3 |
| 361 | end |
| 362 | f = get st 2 |
| 363 | if ge f 128 |
| 364 | stop 3 |
| 365 | end |
| 366 | put fs f l |
| 367 | put nm f at l 1 |
| 368 | put st 2 add f 1 |
| 369 | if gt l 0 |
| 370 | p = sub l 1 |
| 371 | if and is p 0 0 and is p 1 38 is p 2 39 |
| 372 | put fx f 1 |
| 373 | end |
| 374 | if and is p 0 0 and is p 1 38 is p 2 42 |
| 375 | put fx f 2 |
| 376 | end |
| 377 | end |
| 378 | d = ulong 1 |
| 379 | else |
| 380 | if is l 0 2 |
| 381 | if eq d 0 |
| 382 | stop 3 |
| 383 | end |
| 384 | d = sub d 1 |
| 385 | if eq d 0 |
| 386 | put fe f l |
| 387 | end |
| 388 | end |
| 389 | end |
| 390 | put lf l f |
| 391 | put dep l d |
| 392 | if or is l 0 3 or is l 0 5 is l 0 6 |
| 393 | d = add d 1 |
| 394 | end |
| 395 | end |
| 396 | if or ne d 0 eq get st 2 0 |
| 397 | stop 3 |
| 398 | end |
| 399 | end |
| 400 | note Shared assignment classifier for B2, B3 and E1: the index of the value's first token when line l |
| 401 | note assigns, else 0. omc s_name accepts NAME [=] value: a leading name that is not a statement |
| 402 | note keyword (indexes 0..21), a unit function or a host word assigns even without =. omc refuses a |
| 403 | note parameter, global or local that shadows a function or host word (errors 10 and 16). |
| 404 | fn asg l ulong to ulong |
| 405 | if lt get lc l 2 |
| 406 | ret 0 |
| 407 | end |
| 408 | if is l 1 22 |
| 409 | ret 2 |
| 410 | end |
| 411 | for k ulong 22 |
| 412 | if is l 0 k |
| 413 | ret 0 |
| 414 | end |
| 415 | end |
| 416 | t = at l 0 |
| 417 | if or lt func t 128 ishost t |
| 418 | ret 0 |
| 419 | end |
| 420 | bare = ulong 1 |
| 421 | ret bare |
| 422 | end |
| 423 | fn exempt l ulong to bool |
| 424 | if eq l 0 |
| 425 | ret false |
| 426 | end |
| 427 | p = sub l 1 |
| 428 | ret and gt get lc p 4 and is p 0 0 and is p 1 38 and is p 2 40 is p 3 41 |
| 429 | end |
| 430 | fn mentions k ulong name ulong to bool |
| 431 | start = asg k |
| 432 | for p ulong sub get lc k start bound 16384 |
| 433 | t = at k add p start |
| 434 | if same name t |
| 435 | ret true |
| 436 | end |
| 437 | end |
| 438 | ret false |
| 439 | end |
| 440 | note Walk the straight-line continuation: leave blocks outward, skip the sibling else branch. |
| 441 | fn used l ulong name ulong to bool |
| 442 | d = get dep l |
| 443 | e = get fe get lf l |
| 444 | sk = ulong 0 |
| 445 | for j ulong sub e l bound 4096 |
| 446 | k = add add l j 1 |
| 447 | dk = get dep k |
| 448 | if lt dk d |
| 449 | d = dk |
| 450 | end |
| 451 | if ne sk 0 |
| 452 | if ge dk sk |
| 453 | continue |
| 454 | end |
| 455 | sk = ulong 0 |
| 456 | end |
| 457 | if is k 0 0 |
| 458 | continue |
| 459 | end |
| 460 | if and eq dk d is k 0 4 |
| 461 | sk = d |
| 462 | continue |
| 463 | end |
| 464 | if mentions k name |
| 465 | ret true |
| 466 | end |
| 467 | if eq dk d |
| 468 | if and ne asg k 0 same name at k 0 |
| 469 | ret false |
| 470 | end |
| 471 | if or is k 0 13 or is k 0 14 is k 0 15 |
| 472 | ret false |
| 473 | end |
| 474 | end |
| 475 | end |
| 476 | ret false |
| 477 | end |
| 478 | note Size of t if line r declares it (global, text or same-function new); 0 if it does not. |
| 479 | fn dsize r ulong t ulong fl ulong to ulong |
| 480 | if and is r 0 9 same at r 1 t |
| 481 | ret value at r 3 |
| 482 | end |
| 483 | if and is r 0 10 same at r 1 t |
| 484 | note Source span conservatively includes the declaration words, quotes and escapes. |
| 485 | q = add r 1 |
| 486 | if lt q get st 1 |
| 487 | if gt get ls q 0 |
| 488 | ret sub get off get ls q get off at r 0 |
| 489 | end |
| 490 | end |
| 491 | ret 1048577 |
| 492 | end |
| 493 | if ne get lf r fl |
| 494 | ret 0 |
| 495 | end |
| 496 | v = asg r |
| 497 | if and ne v 0 and is r v 8 same at r 0 t |
| 498 | ret value at r add v 2 |
| 499 | end |
| 500 | ret 0 |
| 501 | end |
| 502 | fn length l ulong t ulong to ulong |
| 503 | fl = get lf l |
| 504 | for r ulong l bound 4096 |
| 505 | v = dsize r t fl |
| 506 | if ne v 0 |
| 507 | ret v |
| 508 | end |
| 509 | end |
| 510 | if ge fl 128 |
| 511 | ret 1048577 |
| 512 | end |
| 513 | r = get fs fl |
| 514 | for p ulong get lc r bound 16384 |
| 515 | if same at r p t |
| 516 | q = add p 1 |
| 517 | if or is r q 32 or is r q 33 is r q 34 |
| 518 | ret value at r add p 3 |
| 519 | end |
| 520 | end |
| 521 | end |
| 522 | ret 1048577 |
| 523 | end |
| 524 | fn checkloop l ulong to void |
| 525 | v = ulong 1048577 |
| 526 | if is l 0 6 |
| 527 | v = value at l 3 |
| 528 | if is l 3 23 |
| 529 | v = length l at l 4 |
| 530 | end |
| 531 | end |
| 532 | for p ulong get lc l bound 16384 |
| 533 | if is l p 7 |
| 534 | v = value at l add p 1 |
| 535 | end |
| 536 | end |
| 537 | if gt v 8192 |
| 538 | refuse 0 l |
| 539 | end |
| 540 | end |
| 541 | fn width l ulong t ulong to ulong |
| 542 | if or keyis t 24 keyis t 28 |
| 543 | ret 8 |
| 544 | end |
| 545 | if or keyis t 25 keyis t 29 |
| 546 | ret 4 |
| 547 | end |
| 548 | if or keyis t 26 keyis t 30 |
| 549 | ret 2 |
| 550 | end |
| 551 | if or keyis t 27 keyis t 31 |
| 552 | ret 1 |
| 553 | end |
| 554 | refuse 2 l |
| 555 | ret 0 |
| 556 | end |
| 557 | fn salloc l ulong f ulong to void |
| 558 | if is l 0 9 |
| 559 | v = value at l 3 |
| 560 | if gt v 65536 |
| 561 | refuse 2 l |
| 562 | end |
| 563 | b = mul v width l at l 2 |
| 564 | put st 5 add get st 5 b |
| 565 | if gt get st 5 65536 |
| 566 | refuse 2 l |
| 567 | end |
| 568 | end |
| 569 | if or ge f 128 is l 0 1 |
| 570 | ret |
| 571 | end |
| 572 | a = asg l |
| 573 | if and ne a 0 is l a 8 |
| 574 | v = value at l add a 2 |
| 575 | if gt v 65536 |
| 576 | refuse 2 l |
| 577 | end |
| 578 | b = mul v width l at l add a 1 |
| 579 | put mem f add get mem f b |
| 580 | put st 7 add get st 7 b |
| 581 | if gt get st 7 65536 |
| 582 | refuse 2 l |
| 583 | end |
| 584 | if gt get mem f 65536 |
| 585 | refuse 2 l |
| 586 | end |
| 587 | end |
| 588 | end |
| 589 | fn scalls l ulong f ulong to bool |
| 590 | call = false |
| 591 | for p ulong get lc l bound 16384 |
| 592 | t = at l p |
| 593 | g = func t |
| 594 | if lt g 128 |
| 595 | a = add mul f 128 g |
| 596 | put edges a 1 |
| 597 | put reach a 1 |
| 598 | call = true |
| 599 | end |
| 600 | if ishost t |
| 601 | call = true |
| 602 | if eq get st 4 0 |
| 603 | if ne get fx f 1 |
| 604 | refuse 4 l |
| 605 | end |
| 606 | end |
| 607 | end |
| 608 | end |
| 609 | ret call |
| 610 | end |
| 611 | fn scan to void |
| 612 | for l ulong get st 1 bound 4096 |
| 613 | if eq get lc l 0 |
| 614 | continue |
| 615 | end |
| 616 | if is l 0 0 |
| 617 | continue |
| 618 | end |
| 619 | if is l 0 20 |
| 620 | if or is l 1 21 is l 2 21 |
| 621 | refuse 6 l |
| 622 | end |
| 623 | put st 6 1 |
| 624 | continue |
| 625 | end |
| 626 | if or is l 0 5 is l 0 6 |
| 627 | checkloop l |
| 628 | end |
| 629 | f = get lf l |
| 630 | salloc l f |
| 631 | if or ge f 128 is l 0 1 |
| 632 | continue |
| 633 | end |
| 634 | call = scalls l f |
| 635 | if and eq get st 4 0 and ne asg l 0 call |
| 636 | if not exempt l |
| 637 | if not used l at l 0 |
| 638 | refuse 3 l |
| 639 | end |
| 640 | end |
| 641 | end |
| 642 | if eq get fx f 2 |
| 643 | if is l 0 16 |
| 644 | note Pure functions may inspect arrays but cannot write even borrowed state. |
| 645 | refuse 5 l |
| 646 | end |
| 647 | end |
| 648 | if or is l 0 17 or is l 0 18 is l 0 19 |
| 649 | if ne get st 6 1 |
| 650 | refuse 6 l |
| 651 | end |
| 652 | end |
| 653 | end |
| 654 | end |
| 655 | fn crow i ulong k ulong n ulong to void |
| 656 | a = mul i 128 |
| 657 | b = mul k 128 |
| 658 | for j ulong n bound 128 |
| 659 | if ne get reach add b j 0 |
| 660 | put reach add a j 1 |
| 661 | end |
| 662 | end |
| 663 | end |
| 664 | fn closure to void |
| 665 | n = get st 2 |
| 666 | for k ulong n bound 128 |
| 667 | for i ulong n bound 128 |
| 668 | if ne get reach add mul i 128 k 0 |
| 669 | crow i k n |
| 670 | end |
| 671 | end |
| 672 | end |
| 673 | end |
| 674 | fn stops q ulong to bool |
| 675 | ret or is q 0 13 or is q 0 14 is q 0 15 |
| 676 | end |
| 677 | note No mutation of the checked depth between guard and recursive call. |
| 678 | fn unchanged s ulong e ulong argt ulong to bool |
| 679 | for h ulong sub e s bound 4096 |
| 680 | r = add s h |
| 681 | if ne asg r 0 |
| 682 | if same at r 0 argt |
| 683 | ret false |
| 684 | end |
| 685 | end |
| 686 | end |
| 687 | ret true |
| 688 | end |
| 689 | note Line p must be NAME = add depth 1, then if gt NAME LIM (LIM <= 64), an optional call statement, |
| 690 | note a stop, end: the stop is the last statement of the guard's then-block (no else, no nested block). |
| 691 | fn guarded p ulong l ulong argt ulong name ulong to bool |
| 692 | if not is p 2 35 |
| 693 | ret false |
| 694 | end |
| 695 | if not same at p 3 name |
| 696 | ret false |
| 697 | end |
| 698 | if ne number at p 4 1 |
| 699 | ret false |
| 700 | end |
| 701 | q = add p 1 |
| 702 | if not and is q 0 3 is q 1 36 |
| 703 | ret false |
| 704 | end |
| 705 | if not same at q 2 argt |
| 706 | ret false |
| 707 | end |
| 708 | lim = value at q 3 |
| 709 | if or eq lim 0 gt lim 64 |
| 710 | ret false |
| 711 | end |
| 712 | q = add q 1 |
| 713 | note Permit the existing nest.om stop-code call before the return; only a call to a unit function, |
| 714 | note never else or another structural line, so the stop belongs to the guard's then-block. |
| 715 | if not stops q |
| 716 | if ge func at q 0 128 |
| 717 | ret false |
| 718 | end |
| 719 | q = add q 1 |
| 720 | end |
| 721 | if not stops q |
| 722 | ret false |
| 723 | end |
| 724 | q = add q 1 |
| 725 | if not is q 0 2 |
| 726 | ret false |
| 727 | end |
| 728 | if ge q l |
| 729 | ret false |
| 730 | end |
| 731 | ret unchanged add q 1 l argt |
| 732 | end |
| 733 | note Lines p and l share one block instance: no line between them leaves the block (depth below dl) |
| 734 | note or starts its sibling else arm (else at depth dl). Equal depth alone is not enough. |
| 735 | fn sameblk p ulong l ulong dl ulong to bool |
| 736 | for h ulong sub l add p 1 bound 4096 |
| 737 | r = add add p 1 h |
| 738 | if lt get dep r dl |
| 739 | ret false |
| 740 | end |
| 741 | if and eq get dep r dl is r 0 4 |
| 742 | ret false |
| 743 | end |
| 744 | end |
| 745 | ret true |
| 746 | end |
| 747 | note A qualifying increasing edge has a canonical dominating guard in the same block instance. |
| 748 | fn increasing l ulong t ulong f ulong to bool |
| 749 | name = at get fs f 2 |
| 750 | argt = add t 1 |
| 751 | dl = get dep l |
| 752 | for p ulong l bound 4096 |
| 753 | if ne get lf p f |
| 754 | continue |
| 755 | end |
| 756 | if ne get dep p dl |
| 757 | continue |
| 758 | end |
| 759 | if eq asg p 0 |
| 760 | continue |
| 761 | end |
| 762 | if same at p 0 argt |
| 763 | if not sameblk p l dl |
| 764 | continue |
| 765 | end |
| 766 | ret guarded p l argt name |
| 767 | end |
| 768 | end |
| 769 | ret false |
| 770 | end |
| 771 | note Classify one call t to g on line r of f; keep all but guarded increasing in-SCC edges. |
| 772 | fn redge r ulong t ulong f ulong g ulong cyclic bool to void |
| 773 | a = add mul f 128 g |
| 774 | gg = mul g 128 |
| 775 | if eq get reach add gg g 0 |
| 776 | put weak a 1 |
| 777 | ret |
| 778 | end |
| 779 | inscc = and cyclic ne get reach add gg f 0 |
| 780 | if not inscc |
| 781 | put weak a 1 |
| 782 | if gt value add t 1 64 |
| 783 | refuse 1 r |
| 784 | end |
| 785 | ret |
| 786 | end |
| 787 | if same add t 1 at get fs f 2 |
| 788 | put weak a 1 |
| 789 | ret |
| 790 | end |
| 791 | if not increasing r t f |
| 792 | refuse 1 r |
| 793 | end |
| 794 | end |
| 795 | fn rline r ulong f ulong cyclic bool to void |
| 796 | for p ulong get lc r bound 16384 |
| 797 | t = at r p |
| 798 | g = func t |
| 799 | if lt g 128 |
| 800 | redge r t f g cyclic |
| 801 | end |
| 802 | end |
| 803 | end |
| 804 | fn isleaf i ulong n ulong to bool |
| 805 | b = mul i 128 |
| 806 | for j ulong n bound 128 |
| 807 | if ne get weak add b j 0 |
| 808 | if ne get alive j 0 |
| 809 | ret false |
| 810 | end |
| 811 | end |
| 812 | end |
| 813 | ret true |
| 814 | end |
| 815 | fn prune n ulong to void |
| 816 | for i ulong n bound 128 |
| 817 | put alive i 1 |
| 818 | end |
| 819 | for round ulong n bound 128 |
| 820 | for i ulong n bound 128 |
| 821 | if isleaf i n |
| 822 | put alive i 0 |
| 823 | end |
| 824 | end |
| 825 | end |
| 826 | end |
| 827 | fn recursion to void |
| 828 | n = get st 2 |
| 829 | for f ulong n bound 128 |
| 830 | h = get fs f |
| 831 | cyclic = ne get reach add mul f 128 f 0 |
| 832 | if cyclic |
| 833 | if ne get mem f 0 |
| 834 | refuse 1 h |
| 835 | end |
| 836 | if not is h 2 37 |
| 837 | refuse 1 h |
| 838 | end |
| 839 | end |
| 840 | for l ulong sub get fe f h bound 4096 |
| 841 | r = add add h l 1 |
| 842 | if is r 0 0 |
| 843 | continue |
| 844 | end |
| 845 | if and cyclic and ne asg r 0 same at r 0 at h 2 |
| 846 | refuse 1 r |
| 847 | end |
| 848 | rline r f cyclic |
| 849 | end |
| 850 | end |
| 851 | note DRA-311/omc leaf-removal analysis, applied after removing guarded increasing edges. |
| 852 | prune n |
| 853 | for i ulong n bound 128 |
| 854 | if ne get alive i 0 |
| 855 | refuse 1 get fs i |
| 856 | end |
| 857 | if eq get fx i 2 |
| 858 | for j ulong n bound 128 |
| 859 | if and ne get edges add mul i 128 j 0 ne get fx j 2 |
| 860 | refuse 5 get fs i |
| 861 | end |
| 862 | end |
| 863 | end |
| 864 | end |
| 865 | end |
| 866 | fn slurp fd int n ulong to ulong |
| 867 | total = n |
| 868 | while true bound 65536 |
| 869 | r = read fd src total sub len src total |
| 870 | if lt r 0 |
| 871 | exit 4 |
| 872 | end |
| 873 | if eq r 0 |
| 874 | ret total |
| 875 | end |
| 876 | total = add total ulong r |
| 877 | if ge total len src |
| 878 | stop 3 |
| 879 | end |
| 880 | end |
| 881 | stop 3 |
| 882 | ret 0 |
| 883 | end |
| 884 | fn main to int |
| 885 | init |
| 886 | ac = ulong argcnt |
| 887 | if gt ac 16 |
| 888 | if ne write 2 use 0 len use long len use |
| 889 | ret 4 |
| 890 | end |
| 891 | ret 2 |
| 892 | end |
| 893 | first = ulong 1 |
| 894 | if gt ac 1 |
| 895 | m = argread 1 arg 0 len arg |
| 896 | mode = eq m long len bmode |
| 897 | if mode |
| 898 | for i ulong len bmode |
| 899 | if ne get arg i get bmode i |
| 900 | mode = false |
| 901 | end |
| 902 | end |
| 903 | end |
| 904 | if mode |
| 905 | put st 4 1 |
| 906 | first = ulong 2 |
| 907 | end |
| 908 | end |
| 909 | n = ulong 0 |
| 910 | if eq ac first |
| 911 | n = slurp 0 0 |
| 912 | else |
| 913 | for j ulong sub ac first bound 16 |
| 914 | m = argread add first j arg 0 len arg |
| 915 | if or le m 0 ge m long len arg |
| 916 | ret 2 |
| 917 | end |
| 918 | fd = fopen arg 0 ulong m 0 0 |
| 919 | if lt fd 0 |
| 920 | ret 4 |
| 921 | end |
| 922 | n = slurp int fd n |
| 923 | if ne fclose int fd 0 |
| 924 | ret 4 |
| 925 | end |
| 926 | if gt n 0 |
| 927 | if ne get src sub n 1 10 |
| 928 | put src n 10 |
| 929 | n = add n 1 |
| 930 | if ge n len src |
| 931 | stop 3 |
| 932 | end |
| 933 | end |
| 934 | end |
| 935 | end |
| 936 | end |
| 937 | if eq n 0 |
| 938 | stop 3 |
| 939 | end |
| 940 | lex n |
| 941 | hosts |
| 942 | declarations |
| 943 | scan |
| 944 | closure |
| 945 | recursion |
| 946 | if ne write 1 pass 0 len pass long len pass |
| 947 | ret 4 |
| 948 | end |
| 949 | ret 0 |
| 950 | end |