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 / helix / ollm_factory / om_formalize.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note seed/helix/ollm_factory/om_formalize.om: |
| 4 | note Zero-Leakage English-Only Dual-Pass Formalizer (Pure Seeded OM-2). |
| 5 | note Reads ONLY a prompt file (`note <English>\nfn solve <PARAMS>\n`) — NEVER |
| 6 | note touches expect.txt or tasks.om. Translates general English algorithmic |
| 7 | note specifications across all 5 OM-2 function shapes into formal I/O specs |
| 8 | note for `om_synth.om` and `om_sketch.om`, gated by strict dual-pass agreement |
| 9 | note (Pass 1 semantic evaluator == Pass 2 independent verifier on all test cases; |
| 10 | note fail-closed abstain on any ambiguity or mismatch). |
| 11 | note |
| 12 | note Usage: |
| 13 | note om_formalize formalize PROMPT_FILE OUT_SPEC |
| 14 | note om_formalize selfcheck |
| 15 | |
| 16 | global fmBuf uchar 16384 |
| 17 | global fmOut uchar 16384 |
| 18 | global fmPath uchar 4096 |
| 19 | global fmNums ulong 16 |
| 20 | global fmInA ulong 8 |
| 21 | global fmInB ulong 8 |
| 22 | global fmInC ulong 8 |
| 23 | global fmP1 ulong 8 |
| 24 | global fmSt ulong 32 |
| 25 | |
| 26 | text mForm "formalize" |
| 27 | text mSelf "selfcheck" |
| 28 | text tUsage "usage: om_formalize formalize PROMPT_FILE OUT_SPEC | selfcheck\n" |
| 29 | text tErrIo "om_formalize: I/O error\n" |
| 30 | text tAgree "FORMALIZE_AGREE concept=" |
| 31 | text tAbstain "FORMALIZE_ABSTAIN\n" |
| 32 | text tSelfOk "OM_FORMALIZE SELFCHECK PASS agree=6/6 abstain=1/1 zero_expect_access=1\n" |
| 33 | text tSelfFail "OM_FORMALIZE SELFCHECK FAIL step=" |
| 34 | text tNl "\n" |
| 35 | |
| 36 | text kwEdit "edit" |
| 37 | text kwView "view" |
| 38 | text kwVoid "void" |
| 39 | text kwB " b ulong" |
| 40 | text kwC " c ulong" |
| 41 | |
| 42 | note General English mathematical & algorithmic keywords |
| 43 | text kDigit "digit" |
| 44 | text kBit "bit" |
| 45 | text kOneBit "one bit" |
| 46 | text kSetBit "set bit" |
| 47 | text kBits "bits" |
| 48 | text kByte "byte" |
| 49 | text kPrime "prime" |
| 50 | text kFib "fibonacci" |
| 51 | text kFact "factorial" |
| 52 | text kGcd "greatest common divisor" |
| 53 | text kGcd2 "gcd" |
| 54 | text kLcm "least common multiple" |
| 55 | text kLcm2 "lcm" |
| 56 | text kSqrt "square root" |
| 57 | text kPower "power" |
| 58 | text kPow2 "power of 2" |
| 59 | text kPowTwo "power of two" |
| 60 | text kSquare "square" |
| 61 | text kCube "cube" |
| 62 | text kDist "distance" |
| 63 | text kRound "round" |
| 64 | text kDown "down" |
| 65 | text kUp "up" |
| 66 | text kMult "multiple" |
| 67 | text kDivis "divisible" |
| 68 | text kDivisor "divisor" |
| 69 | text kFactor "factor" |
| 70 | text kEven "even" |
| 71 | text kOdd "odd" |
| 72 | text kHalf "half" |
| 73 | text kHalv "halv" |
| 74 | text kDouble "double" |
| 75 | text kTwice "twice" |
| 76 | text kThree "three times" |
| 77 | text kPlus "plus" |
| 78 | text kBelow "below" |
| 79 | text kAbove "above" |
| 80 | text kLess "less than" |
| 81 | text kGreat "greater than" |
| 82 | text kAtMost "at most" |
| 83 | text kAtLeast "at least" |
| 84 | text kLowest "lowest" |
| 85 | text kHighest "highest" |
| 86 | text kClear "clear" |
| 87 | text kTrail "trailing" |
| 88 | text kZero "zero" |
| 89 | text kNonZero "non-zero" |
| 90 | text kNonZero2 "nonzero" |
| 91 | text kPal "palindrom" |
| 92 | text kRev "revers" |
| 93 | text kSort "sort" |
| 94 | text kAsc "ascending" |
| 95 | text kDesc "descending" |
| 96 | text kIncr "increasing" |
| 97 | text kStrict "strictly" |
| 98 | text kNonDec "non-decreasing" |
| 99 | text kRot "rotat" |
| 100 | text kShift "shift" |
| 101 | text kLeft "left" |
| 102 | text kRight "right" |
| 103 | text kSwap "swap" |
| 104 | text kAdj "adjacent" |
| 105 | text kPrefix "prefix" |
| 106 | text kRun "running" |
| 107 | text kConsec "consecutive" |
| 108 | text kLongest "longest" |
| 109 | text kMove "move" |
| 110 | text kEnd "end" |
| 111 | text kLarg "larger" |
| 112 | text kMax "maximum" |
| 113 | text kBig "largest" |
| 114 | text kSmall "smaller" |
| 115 | text kMin "minimum" |
| 116 | text kLeast "smallest" |
| 117 | text kSecond "second" |
| 118 | text kIndex "index" |
| 119 | text kPos "position" |
| 120 | text kFirst "first" |
| 121 | text kLast "last" |
| 122 | text kSum "sum" |
| 123 | text kProd "product" |
| 124 | text kXor "xor" |
| 125 | text kExcl "exclusive or" |
| 126 | text kBitOr "bitwise or" |
| 127 | text kBitAnd "bitwise and" |
| 128 | text kOr " or " |
| 129 | text kHowMany "how many" |
| 130 | text kCount "count" |
| 131 | text kNumberOf "number of" |
| 132 | text kAvg "average" |
| 133 | text kDiff "difference" |
| 134 | text kAbs "absolute" |
| 135 | text kClamp "clamp" |
| 136 | text kCap "cap" |
| 137 | text kMed "median" |
| 138 | text kMiddle "middle" |
| 139 | text kBetween "between" |
| 140 | text kRange "range" |
| 141 | text kEqual "equal" |
| 142 | text kSame "same" |
| 143 | text kAll "all" |
| 144 | text kParity "parity" |
| 145 | text kCollatz "collatz" |
| 146 | text kReach1 "reach 1" |
| 147 | text kSteps "steps" |
| 148 | text kInvert "invert" |
| 149 | text kCompl "complement" |
| 150 | text kRepl "replace" |
| 151 | text kFill "fill" |
| 152 | text kWeight "weight" |
| 153 | text kAdd "add" |
| 154 | text kSub "subtract" |
| 155 | text kRem "remainder" |
| 156 | text kQuot "quotient" |
| 157 | text kCeil "ceiling" |
| 158 | text kSat "saturat" |
| 159 | text kHamm "differ" |
| 160 | text kTri "1 to" |
| 161 | text kRoot "root" |
| 162 | text kSingle "single" |
| 163 | text kUnknown "quantum" |
| 164 | text kDivBy "divided by" |
| 165 | text kTimes "times" |
| 166 | text kMinus "minus" |
| 167 | text kBoth "both" |
| 168 | text kExactlyOne "exactly one" |
| 169 | text kDifferent "different" |
| 170 | text kMoreOnce "more than once" |
| 171 | text kNeighbour "neighbour" |
| 172 | text kBefore "just before" |
| 173 | text kOwnIdx "own index" |
| 174 | text kEvery "every" |
| 175 | text kHighByte "high byte" |
| 176 | text kLowByte "low byte" |
| 177 | text kOddNum "odd number" |
| 178 | text kAtLeastTwo "at least two" |
| 179 | text kBitByBit "bit by bit" |
| 180 | text kNotAbove "not above" |
| 181 | text kAtLeastTwice "at least twice" |
| 182 | text kPlusOne "plus one" |
| 183 | text kInAAndZ "one in a and zero in b" |
| 184 | text kNeverMore "never more than" |
| 185 | text kWrapping "wrapping" |
| 186 | text kNMinusOne "n minus one" |
| 187 | text kTogether "together" |
| 188 | text kTwoDig "two-digit" |
| 189 | text kLastDec "last decimal digit" |
| 190 | text kWhenCZero "when c is zero" |
| 191 | text kWhenAEqb "when a equals b" |
| 192 | text kWhenCEven "when c is even" |
| 193 | text kWhenAEven "when a is even" |
| 194 | text kByItsIdx "by its index" |
| 195 | text kEqualFirst "equal the first" |
| 196 | text kSmallerFirst "smaller than the first" |
| 197 | text kOddSum "odd sum" |
| 198 | text kOddIdx "odd index" |
| 199 | text kEvenIdx "even index" |
| 200 | text kFirstZero "first zero" |
| 201 | text kLastOdd "last odd" |
| 202 | text kCloser "closer to" |
| 203 | |
| 204 | text oArity "arity " |
| 205 | text oDepth "depth " |
| 206 | text oConsts "consts " |
| 207 | text oCase "case " |
| 208 | text oFold "fold " |
| 209 | text oRew "rew " |
| 210 | |
| 211 | text tFoldA1 "fold 4 3 7 2 9 " |
| 212 | text tFoldA2 "\nfold 3 10 5 20 " |
| 213 | text tFoldA3 "\nfold 5 1 2 3 4 5 " |
| 214 | text tFoldA4 "\nfold 4 0 4 4 0 " |
| 215 | |
| 216 | text tRew1 "rew 4 3 7 2 9 5 1 8 4 " |
| 217 | text tRew2 "\nrew 5 10 0 5 0 20 3 6 1 " |
| 218 | text tRew3 "\nrew 6 1 2 3 4 5 6 7 8 " |
| 219 | |
| 220 | text tTestP1 "note return the argument rounded down to a multiple of 14\nfn solve a ulong to ulong\n" |
| 221 | text tTestP2 "note return the larger of the two arguments\nfn solve a ulong b ulong to ulong\n" |
| 222 | text tTestP3 "note return the greatest common divisor of the two arguments\nfn solve a ulong b ulong to ulong\n" |
| 223 | text tTestP4 "note return the sum of the decimal digits of the argument\nfn solve a ulong to ulong\n" |
| 224 | text tTestP5 "note return the index of the largest element\nfn solve a view ulong 8 n ulong to ulong\n" |
| 225 | text tTestP6 "note reverse the first n elements in place\nfn solve a edit ulong 8 n ulong to void\n" |
| 226 | text tTestP7 "note compute the quantum entanglement entropy of a\nfn solve a ulong to ulong\n" |
| 227 | |
| 228 | fn fwStr fd int s view uchar * to void |
| 229 | r = write fd s 0 len s |
| 230 | end |
| 231 | |
| 232 | fn fwNum fd int v ulong to void |
| 233 | b = new uchar 24 0 |
| 234 | p = ulong 24 |
| 235 | x = v |
| 236 | while true bound 24 |
| 237 | p = sub p 1 |
| 238 | put b p uchar add 48 rem x 10 |
| 239 | x = div x 10 |
| 240 | if eq x 0 |
| 241 | break |
| 242 | end |
| 243 | end |
| 244 | r = write fd b p sub 24 p |
| 245 | end |
| 246 | |
| 247 | fn feqTxt a view uchar * al ulong b view uchar * to bool |
| 248 | if ne al len b |
| 249 | ret false |
| 250 | end |
| 251 | for i ulong al bound 64 |
| 252 | if ne get a i get b i |
| 253 | ret false |
| 254 | end |
| 255 | end |
| 256 | ret true |
| 257 | end |
| 258 | |
| 259 | fn fLower c ulong to ulong |
| 260 | if and ge c 65 le c 90 |
| 261 | ret add c 32 |
| 262 | end |
| 263 | ret c |
| 264 | end |
| 265 | |
| 266 | fn fHas boff ulong blen ulong s view uchar * to bool |
| 267 | sl = len s |
| 268 | if or eq sl 0 gt sl blen |
| 269 | ret false |
| 270 | end |
| 271 | lim = add sub blen sl 1 |
| 272 | for i ulong lim bound 4096 |
| 273 | ok = true |
| 274 | for j ulong sl bound 64 |
| 275 | if ne fLower ulong get fmBuf add boff add i j ulong get s j |
| 276 | ok = false |
| 277 | break |
| 278 | end |
| 279 | end |
| 280 | if ok |
| 281 | ret true |
| 282 | end |
| 283 | end |
| 284 | ret false |
| 285 | end |
| 286 | |
| 287 | fn h1 s view uchar * to bool |
| 288 | ret fHas 0 get fmSt 0 s |
| 289 | end |
| 290 | |
| 291 | fn foClr to void |
| 292 | put fmSt 10 0 |
| 293 | end |
| 294 | |
| 295 | fn foCh c ulong to void |
| 296 | p = get fmSt 10 |
| 297 | if lt p 16383 |
| 298 | put fmOut p uchar c |
| 299 | put fmSt 10 add p 1 |
| 300 | end |
| 301 | end |
| 302 | |
| 303 | fn foTxt s view uchar * to void |
| 304 | for i ulong len s bound 4096 |
| 305 | foCh ulong get s i |
| 306 | end |
| 307 | end |
| 308 | |
| 309 | fn foNum v ulong to void |
| 310 | b = new uchar 24 0 |
| 311 | p = ulong 24 |
| 312 | x = v |
| 313 | while true bound 24 |
| 314 | p = sub p 1 |
| 315 | put b p uchar add 48 rem x 10 |
| 316 | x = div x 10 |
| 317 | if eq x 0 |
| 318 | break |
| 319 | end |
| 320 | end |
| 321 | while lt p 24 bound 24 |
| 322 | foCh ulong get b p |
| 323 | p = add p 1 |
| 324 | end |
| 325 | end |
| 326 | |
| 327 | fn fmExtractNums l1e ulong to void |
| 328 | nc = ulong 0 |
| 329 | i = ulong 0 |
| 330 | while lt i l1e bound 4096 |
| 331 | c = get fmBuf i |
| 332 | if and ge c 48 le c 57 |
| 333 | v = ulong 0 |
| 334 | while lt i l1e bound 4096 |
| 335 | c2 = get fmBuf i |
| 336 | if not and ge c2 48 le c2 57 |
| 337 | break |
| 338 | end |
| 339 | v = add mul v 10 ulong sub c2 48 |
| 340 | i = add i 1 |
| 341 | end |
| 342 | if lt nc 16 |
| 343 | put fmNums nc v |
| 344 | nc = add nc 1 |
| 345 | end |
| 346 | else |
| 347 | i = add i 1 |
| 348 | end |
| 349 | end |
| 350 | put fmSt 4 nc |
| 351 | end |
| 352 | |
| 353 | fn fmParsePrompt blen ulong to void |
| 354 | l1e = ulong 0 |
| 355 | while lt l1e blen bound 16384 |
| 356 | if eq get fmBuf l1e 10 |
| 357 | break |
| 358 | end |
| 359 | l1e = add l1e 1 |
| 360 | end |
| 361 | l2s = l1e |
| 362 | if lt l2s blen |
| 363 | l2s = add l2s 1 |
| 364 | end |
| 365 | l2e = l2s |
| 366 | while lt l2e blen bound 16384 |
| 367 | if eq get fmBuf l2e 10 |
| 368 | break |
| 369 | end |
| 370 | l2e = add l2e 1 |
| 371 | end |
| 372 | put fmSt 0 l1e |
| 373 | put fmSt 1 l2s |
| 374 | put fmSt 2 l2e |
| 375 | ar = ulong 1 |
| 376 | l2n = sub l2e l2s |
| 377 | if fHas l2s l2n kwEdit |
| 378 | ar = 5 |
| 379 | else |
| 380 | if fHas l2s l2n kwView |
| 381 | ar = 4 |
| 382 | else |
| 383 | if fHas l2s l2n kwC |
| 384 | ar = 3 |
| 385 | else |
| 386 | if fHas l2s l2n kwB |
| 387 | ar = 2 |
| 388 | else |
| 389 | if fHas l2s l2n kwVoid |
| 390 | ar = 5 |
| 391 | end |
| 392 | end |
| 393 | end |
| 394 | end |
| 395 | end |
| 396 | put fmSt 3 ar |
| 397 | fmExtractNums l1e |
| 398 | end |
| 399 | |
| 400 | note ======== Shape 1 classifier (unary a ulong to ulong) ======== |
| 401 | fn clsShape1Digits to ulong |
| 402 | if h1 kPal |
| 403 | ret 123 |
| 404 | end |
| 405 | if or h1 kRoot h1 kSingle |
| 406 | ret 124 |
| 407 | end |
| 408 | if h1 kRev |
| 409 | ret 119 |
| 410 | end |
| 411 | if h1 kProd |
| 412 | ret 120 |
| 413 | end |
| 414 | if or h1 kBig h1 kMax |
| 415 | ret 121 |
| 416 | end |
| 417 | if or h1 kLeast h1 kMin |
| 418 | ret 122 |
| 419 | end |
| 420 | if h1 kSum |
| 421 | ret 117 |
| 422 | end |
| 423 | if and h1 kTrail h1 kZero |
| 424 | ret 136 |
| 425 | end |
| 426 | if h1 kEven |
| 427 | ret 140 |
| 428 | end |
| 429 | if h1 kOdd |
| 430 | ret 141 |
| 431 | end |
| 432 | if or h1 kHowMany or h1 kCount h1 kNumberOf |
| 433 | ret 118 |
| 434 | end |
| 435 | ret 0 |
| 436 | end |
| 437 | |
| 438 | fn clsShape1Bits to ulong |
| 439 | if and h1 kLowest h1 kClear |
| 440 | ret 106 |
| 441 | end |
| 442 | if h1 kLowest |
| 443 | ret 113 |
| 444 | end |
| 445 | if and h1 kTrail h1 kZero |
| 446 | ret 112 |
| 447 | end |
| 448 | if h1 kParity |
| 449 | ret 115 |
| 450 | end |
| 451 | if or h1 kOneBit h1 kSetBit |
| 452 | if or h1 kHowMany or h1 kCount h1 kNumberOf |
| 453 | ret 110 |
| 454 | end |
| 455 | end |
| 456 | if h1 kRev |
| 457 | ret 133 |
| 458 | end |
| 459 | if or h1 kInvert h1 kCompl |
| 460 | ret 132 |
| 461 | end |
| 462 | if h1 kSwap |
| 463 | ret 131 |
| 464 | end |
| 465 | ret 0 |
| 466 | end |
| 467 | |
| 468 | fn clsShape1 to ulong |
| 469 | nn = get fmSt 4 |
| 470 | if h1 kUnknown |
| 471 | ret 0 |
| 472 | end |
| 473 | if h1 kDigit |
| 474 | ret clsShape1Digits |
| 475 | end |
| 476 | if or h1 kBit h1 kBits |
| 477 | c = clsShape1Bits |
| 478 | if ne c 0 |
| 479 | ret c |
| 480 | end |
| 481 | end |
| 482 | if h1 kByte |
| 483 | if h1 kSwap |
| 484 | ret 131 |
| 485 | end |
| 486 | end |
| 487 | if h1 kSqrt |
| 488 | ret 125 |
| 489 | end |
| 490 | if and h1 kPrime or h1 kLeast h1 kSmall |
| 491 | ret 127 |
| 492 | end |
| 493 | if h1 kPrime |
| 494 | ret 126 |
| 495 | end |
| 496 | if h1 kFact |
| 497 | ret 128 |
| 498 | end |
| 499 | if h1 kFib |
| 500 | ret 129 |
| 501 | end |
| 502 | if or h1 kCollatz h1 kReach1 |
| 503 | ret 130 |
| 504 | end |
| 505 | if h1 kDivisor |
| 506 | if h1 kSum |
| 507 | ret 135 |
| 508 | end |
| 509 | if or h1 kHowMany or h1 kCount h1 kNumberOf |
| 510 | ret 134 |
| 511 | end |
| 512 | end |
| 513 | if and h1 kFactor or h1 kSmall h1 kLeast |
| 514 | ret 127 |
| 515 | end |
| 516 | if h1 kHalv |
| 517 | if or h1 kHowMany h1 kCount |
| 518 | ret 111 |
| 519 | end |
| 520 | end |
| 521 | if or h1 kPow2 h1 kPowTwo |
| 522 | if or h1 kHighest h1 kLarg |
| 523 | ret 114 |
| 524 | end |
| 525 | if or h1 kLeast h1 kSmall |
| 526 | ret 138 |
| 527 | end |
| 528 | ret 116 |
| 529 | end |
| 530 | if and h1 kHalf and h1 kEven h1 kThree |
| 531 | ret 104 |
| 532 | end |
| 533 | if and ge nn 3 h1 kBelow |
| 534 | ret 105 |
| 535 | end |
| 536 | if and ge nn 2 and h1 kMult h1 kOr |
| 537 | ret 107 |
| 538 | end |
| 539 | if and ge nn 1 and h1 kRound and h1 kDown h1 kMult |
| 540 | ret 101 |
| 541 | end |
| 542 | if and ge nn 1 and h1 kRound and h1 kUp h1 kMult |
| 543 | ret 102 |
| 544 | end |
| 545 | if and ge nn 1 h1 kDist |
| 546 | ret 103 |
| 547 | end |
| 548 | if and h1 kSquare h1 kPlusOne |
| 549 | put fmNums 0 1 |
| 550 | put fmSt 4 1 |
| 551 | ret 108 |
| 552 | end |
| 553 | if and ge nn 1 and h1 kSquare h1 kPlus |
| 554 | ret 108 |
| 555 | end |
| 556 | if and eq nn 0 h1 kCube |
| 557 | ret 109 |
| 558 | end |
| 559 | if h1 kTri |
| 560 | ret 139 |
| 561 | end |
| 562 | ret 0 |
| 563 | end |
| 564 | |
| 565 | note ======== Shape 2 classifier (binary a, b) ======== |
| 566 | fn clsShape2 to ulong |
| 567 | if or h1 kGcd h1 kGcd2 |
| 568 | ret 210 |
| 569 | end |
| 570 | if or h1 kLcm h1 kLcm2 |
| 571 | ret 211 |
| 572 | end |
| 573 | if and or h1 kBit h1 kBits h1 kHamm |
| 574 | ret 213 |
| 575 | end |
| 576 | if h1 kPower |
| 577 | ret 212 |
| 578 | end |
| 579 | if h1 kInAAndZ |
| 580 | ret 221 |
| 581 | end |
| 582 | if and h1 kHighByte h1 kLowByte |
| 583 | ret 223 |
| 584 | end |
| 585 | if and h1 kTwoDig h1 kLastDec |
| 586 | ret 230 |
| 587 | end |
| 588 | if and h1 kDigit and h1 kSum h1 kBoth |
| 589 | ret 228 |
| 590 | end |
| 591 | if and h1 kDigit and h1 kTogether or h1 kHowMany h1 kCount |
| 592 | ret 229 |
| 593 | end |
| 594 | if and h1 kProd and h1 kPlus h1 kSum |
| 595 | ret 220 |
| 596 | end |
| 597 | if and h1 kTwice and h1 kThree h1 kPlus |
| 598 | ret 231 |
| 599 | end |
| 600 | if and h1 kBoth and h1 kLeft h1 kBits |
| 601 | ret 222 |
| 602 | end |
| 603 | if h1 kWhenAEven |
| 604 | ret 225 |
| 605 | end |
| 606 | if and h1 kExactlyOne h1 kZero |
| 607 | ret 226 |
| 608 | end |
| 609 | if and h1 kMult and h1 kZero h1 kZero |
| 610 | if and not h1 kRound not h1 kDown |
| 611 | ret 227 |
| 612 | end |
| 613 | end |
| 614 | if and h1 kDivBy h1 kNeverMore |
| 615 | ret 232 |
| 616 | end |
| 617 | if and h1 kDivBy h1 kZero |
| 618 | ret 214 |
| 619 | end |
| 620 | if and h1 kMinus and h1 kAtLeast h1 kZero |
| 621 | ret 217 |
| 622 | end |
| 623 | if and h1 kSum and h1 kBelow ge get fmSt 4 1 |
| 624 | ret 224 |
| 625 | end |
| 626 | if and h1 kCloser ge get fmSt 4 1 |
| 627 | ret 233 |
| 628 | end |
| 629 | if and h1 kMiddle ge get fmSt 4 1 |
| 630 | ret 234 |
| 631 | end |
| 632 | if and h1 kSquare h1 kDist |
| 633 | ret 204 |
| 634 | end |
| 635 | if and h1 kSquare h1 kSum |
| 636 | ret 205 |
| 637 | end |
| 638 | if and h1 kRound and h1 kDown h1 kMult |
| 639 | ret 218 |
| 640 | end |
| 641 | if and h1 kRound and h1 kUp h1 kMult |
| 642 | ret 219 |
| 643 | end |
| 644 | if h1 kCeil |
| 645 | ret 216 |
| 646 | end |
| 647 | if h1 kSat |
| 648 | ret 217 |
| 649 | end |
| 650 | if or h1 kDist h1 kAbs |
| 651 | ret 203 |
| 652 | end |
| 653 | if or h1 kLarg or h1 kMax h1 kBig |
| 654 | ret 201 |
| 655 | end |
| 656 | if or h1 kSmall or h1 kMin h1 kLeast |
| 657 | ret 202 |
| 658 | end |
| 659 | if h1 kAvg |
| 660 | ret 206 |
| 661 | end |
| 662 | if or h1 kXor h1 kExcl |
| 663 | ret 207 |
| 664 | end |
| 665 | if h1 kQuot |
| 666 | ret 214 |
| 667 | end |
| 668 | if h1 kRem |
| 669 | ret 215 |
| 670 | end |
| 671 | ret 0 |
| 672 | end |
| 673 | |
| 674 | note ======== Shape 3 classifier (ternary a, b, c) ======== |
| 675 | fn clsShape3 to ulong |
| 676 | if or h1 kGcd h1 kGcd2 |
| 677 | ret 315 |
| 678 | end |
| 679 | if h1 kClamp |
| 680 | ret 300 |
| 681 | end |
| 682 | if or h1 kMed h1 kMiddle |
| 683 | ret 301 |
| 684 | end |
| 685 | if h1 kBitByBit |
| 686 | ret 313 |
| 687 | end |
| 688 | if h1 kAtLeastTwo |
| 689 | ret 311 |
| 690 | end |
| 691 | if h1 kOddNum |
| 692 | ret 312 |
| 693 | end |
| 694 | if h1 kNotAbove |
| 695 | ret 308 |
| 696 | end |
| 697 | if h1 kWhenCZero |
| 698 | ret 320 |
| 699 | end |
| 700 | if h1 kWhenCEven |
| 701 | ret 321 |
| 702 | end |
| 703 | if h1 kWhenAEqb |
| 704 | ret 317 |
| 705 | end |
| 706 | if h1 kAtLeastTwice |
| 707 | ret 316 |
| 708 | end |
| 709 | if h1 kDifferent |
| 710 | ret 309 |
| 711 | end |
| 712 | if and h1 kHowMany h1 kEqualFirst |
| 713 | ret 319 |
| 714 | end |
| 715 | if and h1 kHowMany h1 kOdd |
| 716 | ret 310 |
| 717 | end |
| 718 | if and h1 kHowMany and h1 kAbove ge get fmSt 4 1 |
| 719 | ret 322 |
| 720 | end |
| 721 | if h1 kAvg |
| 722 | ret 314 |
| 723 | end |
| 724 | if and h1 kTimes and h1 kPlus and not h1 kRem eq get fmSt 4 0 |
| 725 | ret 318 |
| 726 | end |
| 727 | if or h1 kBig h1 kMax |
| 728 | ret 302 |
| 729 | end |
| 730 | if or h1 kLeast h1 kMin |
| 731 | ret 303 |
| 732 | end |
| 733 | if h1 kBetween |
| 734 | ret 304 |
| 735 | end |
| 736 | if h1 kSum |
| 737 | ret 305 |
| 738 | end |
| 739 | if h1 kProd |
| 740 | ret 306 |
| 741 | end |
| 742 | ret 0 |
| 743 | end |
| 744 | |
| 745 | note ======== Shape 4 classifier (array fold/select/count/scan) ======== |
| 746 | fn clsShape4 to ulong |
| 747 | if or h1 kGcd h1 kGcd2 |
| 748 | ret 440 |
| 749 | end |
| 750 | if h1 kSecond |
| 751 | if or h1 kBig h1 kMax |
| 752 | ret 427 |
| 753 | end |
| 754 | end |
| 755 | if h1 kNMinusOne |
| 756 | ret 430 |
| 757 | end |
| 758 | if h1 kFirstZero |
| 759 | ret 442 |
| 760 | end |
| 761 | if h1 kLastOdd |
| 762 | ret 438 |
| 763 | end |
| 764 | if h1 kMoreOnce |
| 765 | ret 437 |
| 766 | end |
| 767 | if h1 kDifferent |
| 768 | ret 436 |
| 769 | end |
| 770 | if and h1 kLongest h1 kNeighbour |
| 771 | ret 439 |
| 772 | end |
| 773 | if h1 kWrapping |
| 774 | ret 432 |
| 775 | end |
| 776 | if and h1 kEvenIdx h1 kOddIdx |
| 777 | ret 441 |
| 778 | end |
| 779 | if and h1 kSum h1 kEvenIdx |
| 780 | ret 431 |
| 781 | end |
| 782 | if h1 kByItsIdx |
| 783 | ret 422 |
| 784 | end |
| 785 | if and h1 kBits h1 kEvery |
| 786 | ret 406 |
| 787 | end |
| 788 | if and h1 kBefore h1 kGreat |
| 789 | ret 425 |
| 790 | end |
| 791 | if and h1 kBefore h1 kSmall |
| 792 | ret 417 |
| 793 | end |
| 794 | if h1 kOwnIdx |
| 795 | ret 435 |
| 796 | end |
| 797 | if h1 kEqualFirst |
| 798 | ret 433 |
| 799 | end |
| 800 | if h1 kSmallerFirst |
| 801 | ret 434 |
| 802 | end |
| 803 | if and h1 kFirst and h1 kGreat ge get fmSt 4 1 |
| 804 | ret 458 |
| 805 | end |
| 806 | if or h1 kIndex h1 kPos |
| 807 | if or h1 kBig h1 kMax |
| 808 | ret 415 |
| 809 | end |
| 810 | if or h1 kLeast h1 kMin |
| 811 | ret 416 |
| 812 | end |
| 813 | ret 0 |
| 814 | end |
| 815 | if h1 kAdj |
| 816 | if h1 kMax |
| 817 | ret 424 |
| 818 | end |
| 819 | if h1 kSum |
| 820 | ret 423 |
| 821 | end |
| 822 | if h1 kIncr |
| 823 | ret 425 |
| 824 | end |
| 825 | ret 0 |
| 826 | end |
| 827 | if and h1 kLongest or h1 kNonZero h1 kNonZero2 |
| 828 | ret 428 |
| 829 | end |
| 830 | if or h1 kSort h1 kNonDec |
| 831 | ret 417 |
| 832 | end |
| 833 | if and h1 kStrict h1 kIncr |
| 834 | ret 418 |
| 835 | end |
| 836 | if and h1 kAll or h1 kEqual h1 kSame |
| 837 | ret 419 |
| 838 | end |
| 839 | if and h1 kFirst or h1 kNonZero h1 kNonZero2 |
| 840 | ret 420 |
| 841 | end |
| 842 | if and h1 kLast or h1 kNonZero h1 kNonZero2 |
| 843 | ret 421 |
| 844 | end |
| 845 | if h1 kWeight |
| 846 | ret 422 |
| 847 | end |
| 848 | if and h1 kRange or h1 kDiff h1 kMax |
| 849 | ret 414 |
| 850 | end |
| 851 | if and h1 kSum h1 kSquare |
| 852 | ret 411 |
| 853 | end |
| 854 | if and h1 kSum h1 kEven |
| 855 | ret 412 |
| 856 | end |
| 857 | if and h1 kSum h1 kOdd |
| 858 | ret 413 |
| 859 | end |
| 860 | if or h1 kHowMany or h1 kCount h1 kNumberOf |
| 861 | if h1 kEven |
| 862 | ret 407 |
| 863 | end |
| 864 | if h1 kOdd |
| 865 | ret 408 |
| 866 | end |
| 867 | if or h1 kNonZero h1 kNonZero2 |
| 868 | ret 409 |
| 869 | end |
| 870 | if h1 kZero |
| 871 | ret 410 |
| 872 | end |
| 873 | if h1 kPrefix |
| 874 | ret 426 |
| 875 | end |
| 876 | if and ge get fmSt 4 1 h1 kGreat |
| 877 | ret 450 |
| 878 | end |
| 879 | if and ge get fmSt 4 1 h1 kLess |
| 880 | ret 451 |
| 881 | end |
| 882 | if and ge get fmSt 4 1 h1 kEqual |
| 883 | ret 452 |
| 884 | end |
| 885 | if and ge get fmSt 4 1 h1 kAtLeast |
| 886 | ret 453 |
| 887 | end |
| 888 | if and ge get fmSt 4 1 or h1 kDivis h1 kMult |
| 889 | ret 454 |
| 890 | end |
| 891 | ret 0 |
| 892 | end |
| 893 | if or h1 kXor h1 kExcl |
| 894 | ret 404 |
| 895 | end |
| 896 | if h1 kBitOr |
| 897 | ret 405 |
| 898 | end |
| 899 | if h1 kBitAnd |
| 900 | ret 406 |
| 901 | end |
| 902 | if h1 kProd |
| 903 | ret 401 |
| 904 | end |
| 905 | if or h1 kMax h1 kBig |
| 906 | if not or h1 kPrefix h1 kDiff |
| 907 | ret 402 |
| 908 | end |
| 909 | end |
| 910 | if or h1 kMin h1 kLeast |
| 911 | if not or h1 kPrefix h1 kDiff |
| 912 | ret 403 |
| 913 | end |
| 914 | end |
| 915 | if h1 kSum |
| 916 | if not or h1 kPrefix or h1 kEven or h1 kOdd or h1 kGreat h1 kLess |
| 917 | ret 400 |
| 918 | end |
| 919 | end |
| 920 | ret 0 |
| 921 | end |
| 922 | |
| 923 | note ======== Shape 5 classifier (in-place array rewrite) ======== |
| 924 | fn clsShape5 to ulong |
| 925 | if h1 kRev |
| 926 | ret 500 |
| 927 | end |
| 928 | if h1 kSort |
| 929 | if h1 kDesc |
| 930 | ret 502 |
| 931 | end |
| 932 | ret 501 |
| 933 | end |
| 934 | if or h1 kPrefix h1 kRun |
| 935 | if h1 kSum |
| 936 | ret 503 |
| 937 | end |
| 938 | if or h1 kMax h1 kBig |
| 939 | ret 504 |
| 940 | end |
| 941 | if h1 kXor |
| 942 | ret 518 |
| 943 | end |
| 944 | ret 0 |
| 945 | end |
| 946 | if h1 kRot |
| 947 | if h1 kRight |
| 948 | ret 511 |
| 949 | end |
| 950 | if h1 kLeft |
| 951 | ret 510 |
| 952 | end |
| 953 | ret 0 |
| 954 | end |
| 955 | if h1 kShift |
| 956 | if h1 kRight |
| 957 | ret 513 |
| 958 | end |
| 959 | if h1 kLeft |
| 960 | ret 512 |
| 961 | end |
| 962 | ret 0 |
| 963 | end |
| 964 | if and h1 kSwap h1 kAdj |
| 965 | ret 514 |
| 966 | end |
| 967 | if and h1 kMove and h1 kZero h1 kEnd |
| 968 | ret 515 |
| 969 | end |
| 970 | if or h1 kDouble h1 kTwice |
| 971 | ret 505 |
| 972 | end |
| 973 | if or h1 kHalf h1 kHalv |
| 974 | ret 506 |
| 975 | end |
| 976 | if h1 kSquare |
| 977 | ret 507 |
| 978 | end |
| 979 | if and h1 kZero h1 kEven |
| 980 | ret 508 |
| 981 | end |
| 982 | if and h1 kZero h1 kOdd |
| 983 | ret 509 |
| 984 | end |
| 985 | if and ge get fmSt 4 1 or h1 kClamp h1 kCap |
| 986 | if or h1 kAbove h1 kAtMost |
| 987 | ret 555 |
| 988 | end |
| 989 | if or h1 kBelow h1 kAtLeast |
| 990 | ret 556 |
| 991 | end |
| 992 | end |
| 993 | if and ge get fmSt 4 1 and h1 kZero h1 kBelow |
| 994 | ret 557 |
| 995 | end |
| 996 | if and ge get fmSt 4 1 and h1 kZero h1 kAbove |
| 997 | ret 558 |
| 998 | end |
| 999 | if and ge get fmSt 4 1 and h1 kRepl h1 kZero |
| 1000 | ret 559 |
| 1001 | end |
| 1002 | if and ge get fmSt 4 1 h1 kFill |
| 1003 | ret 560 |
| 1004 | end |
| 1005 | if and ge get fmSt 4 1 h1 kAdd |
| 1006 | ret 550 |
| 1007 | end |
| 1008 | if and ge get fmSt 4 1 h1 kSub |
| 1009 | ret 551 |
| 1010 | end |
| 1011 | if and ge get fmSt 4 1 h1 kMult |
| 1012 | ret 552 |
| 1013 | end |
| 1014 | ret 0 |
| 1015 | end |
| 1016 | |
| 1017 | fn fmPass1 to ulong |
| 1018 | ar = get fmSt 3 |
| 1019 | if eq ar 1 |
| 1020 | ret clsShape1 |
| 1021 | end |
| 1022 | if eq ar 2 |
| 1023 | ret clsShape2 |
| 1024 | end |
| 1025 | if eq ar 3 |
| 1026 | ret clsShape3 |
| 1027 | end |
| 1028 | if eq ar 4 |
| 1029 | ret clsShape4 |
| 1030 | end |
| 1031 | if eq ar 5 |
| 1032 | ret clsShape5 |
| 1033 | end |
| 1034 | ret 0 |
| 1035 | end |
| 1036 | |
| 1037 | note ======== Evaluators for Pass 1 & Pass 2 dual-pass verification ======== |
| 1038 | note OM-2 evaluates both operands of and. Branch before taking a remainder. |
| 1039 | fn fmMultiple value ulong divisor ulong to bool |
| 1040 | if eq divisor 0 |
| 1041 | ret false |
| 1042 | end |
| 1043 | ret eq rem value divisor 0 |
| 1044 | end |
| 1045 | |
| 1046 | fn evalU1 cid ulong a ulong to ulong |
| 1047 | c0 = get fmNums 0 |
| 1048 | c1 = get fmNums 1 |
| 1049 | c2 = get fmNums 2 |
| 1050 | if eq cid 101 |
| 1051 | if eq c0 0 |
| 1052 | ret 0 |
| 1053 | end |
| 1054 | ret sub a rem a c0 |
| 1055 | end |
| 1056 | if eq cid 102 |
| 1057 | if eq c0 0 |
| 1058 | ret 0 |
| 1059 | end |
| 1060 | r = rem a c0 |
| 1061 | if eq r 0 |
| 1062 | ret a |
| 1063 | end |
| 1064 | ret add a sub c0 r |
| 1065 | end |
| 1066 | if eq cid 103 |
| 1067 | if lt a c0 |
| 1068 | ret sub c0 a |
| 1069 | end |
| 1070 | ret sub a c0 |
| 1071 | end |
| 1072 | if eq cid 104 |
| 1073 | if eq rem a 2 0 |
| 1074 | ret div a 2 |
| 1075 | end |
| 1076 | ret add mul 3 a 1 |
| 1077 | end |
| 1078 | if eq cid 105 |
| 1079 | if lt a c1 |
| 1080 | ret 0 |
| 1081 | end |
| 1082 | if lt a c2 |
| 1083 | ret 1 |
| 1084 | end |
| 1085 | if lt a get fmNums 4 |
| 1086 | ret 2 |
| 1087 | end |
| 1088 | ret 3 |
| 1089 | end |
| 1090 | if eq cid 106 |
| 1091 | if eq a 0 |
| 1092 | ret 0 |
| 1093 | end |
| 1094 | ret and a sub a 1 |
| 1095 | end |
| 1096 | if eq cid 107 |
| 1097 | if fmMultiple a c1 |
| 1098 | ret 1 |
| 1099 | end |
| 1100 | if fmMultiple a c2 |
| 1101 | ret 1 |
| 1102 | end |
| 1103 | ret 0 |
| 1104 | end |
| 1105 | if eq cid 108 |
| 1106 | ret add mul a a c0 |
| 1107 | end |
| 1108 | if eq cid 109 |
| 1109 | ret mul mul a a a |
| 1110 | end |
| 1111 | if eq cid 110 |
| 1112 | c = ulong 0 |
| 1113 | x = a |
| 1114 | while gt x 0 bound 64 |
| 1115 | c = add c and x 1 |
| 1116 | x = shr x 1 |
| 1117 | end |
| 1118 | ret c |
| 1119 | end |
| 1120 | if eq cid 111 |
| 1121 | c = ulong 0 |
| 1122 | x = a |
| 1123 | while gt x 0 bound 64 |
| 1124 | c = add c 1 |
| 1125 | x = shr x 1 |
| 1126 | end |
| 1127 | ret c |
| 1128 | end |
| 1129 | if eq cid 112 |
| 1130 | if eq a 0 |
| 1131 | ret 64 |
| 1132 | end |
| 1133 | c = ulong 0 |
| 1134 | x = a |
| 1135 | while eq and x 1 0 bound 64 |
| 1136 | c = add c 1 |
| 1137 | x = shr x 1 |
| 1138 | end |
| 1139 | ret c |
| 1140 | end |
| 1141 | if eq cid 113 |
| 1142 | if eq a 0 |
| 1143 | ret 0 |
| 1144 | end |
| 1145 | ret and a sub 0 a |
| 1146 | end |
| 1147 | if eq cid 114 |
| 1148 | if eq a 0 |
| 1149 | ret 0 |
| 1150 | end |
| 1151 | p = ulong 1 |
| 1152 | x = a |
| 1153 | while gt x 1 bound 64 |
| 1154 | p = shl p 1 |
| 1155 | x = shr x 1 |
| 1156 | end |
| 1157 | ret p |
| 1158 | end |
| 1159 | if eq cid 115 |
| 1160 | c = ulong 0 |
| 1161 | x = a |
| 1162 | while gt x 0 bound 64 |
| 1163 | c = xor c and x 1 |
| 1164 | x = shr x 1 |
| 1165 | end |
| 1166 | ret c |
| 1167 | end |
| 1168 | if eq cid 116 |
| 1169 | if eq a 0 |
| 1170 | ret 0 |
| 1171 | end |
| 1172 | if eq and a sub a 1 0 |
| 1173 | ret 1 |
| 1174 | end |
| 1175 | ret 0 |
| 1176 | end |
| 1177 | ret 999999999 |
| 1178 | end |
| 1179 | |
| 1180 | fn evalU2 cid ulong a ulong to ulong |
| 1181 | if eq cid 117 |
| 1182 | s = ulong 0 |
| 1183 | x = a |
| 1184 | while gt x 0 bound 24 |
| 1185 | s = add s rem x 10 |
| 1186 | x = div x 10 |
| 1187 | end |
| 1188 | ret s |
| 1189 | end |
| 1190 | if eq cid 118 |
| 1191 | if eq a 0 |
| 1192 | ret 1 |
| 1193 | end |
| 1194 | c = ulong 0 |
| 1195 | x = a |
| 1196 | while gt x 0 bound 24 |
| 1197 | c = add c 1 |
| 1198 | x = div x 10 |
| 1199 | end |
| 1200 | ret c |
| 1201 | end |
| 1202 | if eq cid 119 |
| 1203 | r = ulong 0 |
| 1204 | x = a |
| 1205 | while gt x 0 bound 24 |
| 1206 | r = add mul r 10 rem x 10 |
| 1207 | x = div x 10 |
| 1208 | end |
| 1209 | ret r |
| 1210 | end |
| 1211 | if eq cid 120 |
| 1212 | if eq a 0 |
| 1213 | ret 0 |
| 1214 | end |
| 1215 | p = ulong 1 |
| 1216 | x = a |
| 1217 | while gt x 0 bound 24 |
| 1218 | p = mul p rem x 10 |
| 1219 | x = div x 10 |
| 1220 | end |
| 1221 | ret p |
| 1222 | end |
| 1223 | if eq cid 121 |
| 1224 | m = ulong 0 |
| 1225 | x = a |
| 1226 | while gt x 0 bound 24 |
| 1227 | d = rem x 10 |
| 1228 | if gt d m |
| 1229 | m = d |
| 1230 | end |
| 1231 | x = div x 10 |
| 1232 | end |
| 1233 | ret m |
| 1234 | end |
| 1235 | if eq cid 122 |
| 1236 | if eq a 0 |
| 1237 | ret 0 |
| 1238 | end |
| 1239 | m = ulong 9 |
| 1240 | x = a |
| 1241 | while gt x 0 bound 24 |
| 1242 | d = rem x 10 |
| 1243 | if lt d m |
| 1244 | m = d |
| 1245 | end |
| 1246 | x = div x 10 |
| 1247 | end |
| 1248 | ret m |
| 1249 | end |
| 1250 | if eq cid 123 |
| 1251 | r = ulong 0 |
| 1252 | x = a |
| 1253 | while gt x 0 bound 24 |
| 1254 | r = add mul r 10 rem x 10 |
| 1255 | x = div x 10 |
| 1256 | end |
| 1257 | if eq r a |
| 1258 | ret 1 |
| 1259 | end |
| 1260 | ret 0 |
| 1261 | end |
| 1262 | if eq cid 124 |
| 1263 | x = a |
| 1264 | while ge x 10 bound 16 |
| 1265 | s = ulong 0 |
| 1266 | while gt x 0 bound 24 |
| 1267 | s = add s rem x 10 |
| 1268 | x = div x 10 |
| 1269 | end |
| 1270 | x = s |
| 1271 | end |
| 1272 | ret x |
| 1273 | end |
| 1274 | if eq cid 125 |
| 1275 | if le a 1 |
| 1276 | ret a |
| 1277 | end |
| 1278 | lo = ulong 1 |
| 1279 | hi = a |
| 1280 | ans = ulong 1 |
| 1281 | while le lo hi bound 64 |
| 1282 | mid = add lo shr sub hi lo 1 |
| 1283 | if le mid div a mid |
| 1284 | ans = mid |
| 1285 | lo = add mid 1 |
| 1286 | else |
| 1287 | hi = sub mid 1 |
| 1288 | end |
| 1289 | end |
| 1290 | ret ans |
| 1291 | end |
| 1292 | if eq cid 126 |
| 1293 | if lt a 2 |
| 1294 | ret 0 |
| 1295 | end |
| 1296 | if eq a 2 |
| 1297 | ret 1 |
| 1298 | end |
| 1299 | if eq rem a 2 0 |
| 1300 | ret 0 |
| 1301 | end |
| 1302 | d = ulong 3 |
| 1303 | while le d div a d bound 2000 |
| 1304 | if eq rem a d 0 |
| 1305 | ret 0 |
| 1306 | end |
| 1307 | d = add d 2 |
| 1308 | end |
| 1309 | ret 1 |
| 1310 | end |
| 1311 | if eq cid 127 |
| 1312 | if le a 1 |
| 1313 | ret a |
| 1314 | end |
| 1315 | if eq rem a 2 0 |
| 1316 | ret 2 |
| 1317 | end |
| 1318 | d = ulong 3 |
| 1319 | while le d div a d bound 2000 |
| 1320 | if eq rem a d 0 |
| 1321 | ret d |
| 1322 | end |
| 1323 | d = add d 2 |
| 1324 | end |
| 1325 | ret a |
| 1326 | end |
| 1327 | if eq cid 128 |
| 1328 | if gt a 20 |
| 1329 | ret 0 |
| 1330 | end |
| 1331 | r = ulong 1 |
| 1332 | i = ulong 2 |
| 1333 | while le i a bound 24 |
| 1334 | r = mul r i |
| 1335 | i = add i 1 |
| 1336 | end |
| 1337 | ret r |
| 1338 | end |
| 1339 | if eq cid 129 |
| 1340 | if gt a 93 |
| 1341 | ret 0 |
| 1342 | end |
| 1343 | if eq a 0 |
| 1344 | ret 0 |
| 1345 | end |
| 1346 | p = ulong 0 |
| 1347 | c = ulong 1 |
| 1348 | i = ulong 1 |
| 1349 | while lt i a bound 96 |
| 1350 | t = add p c |
| 1351 | p = c |
| 1352 | c = t |
| 1353 | i = add i 1 |
| 1354 | end |
| 1355 | ret c |
| 1356 | end |
| 1357 | if eq cid 130 |
| 1358 | if le a 1 |
| 1359 | ret 0 |
| 1360 | end |
| 1361 | x = a |
| 1362 | s = ulong 0 |
| 1363 | while gt x 1 bound 2000 |
| 1364 | if eq and x 1 0 |
| 1365 | x = shr x 1 |
| 1366 | else |
| 1367 | x = add mul 3 x 1 |
| 1368 | end |
| 1369 | s = add s 1 |
| 1370 | end |
| 1371 | ret s |
| 1372 | end |
| 1373 | if eq cid 131 |
| 1374 | ret or shl and a 255 8 and shr a 8 255 |
| 1375 | end |
| 1376 | if eq cid 132 |
| 1377 | ret xor and a 65535 65535 |
| 1378 | end |
| 1379 | if eq cid 133 |
| 1380 | r = ulong 0 |
| 1381 | x = a |
| 1382 | for i ulong 8 bound 8 |
| 1383 | r = or shl r 1 and x 1 |
| 1384 | x = shr x 1 |
| 1385 | end |
| 1386 | ret r |
| 1387 | end |
| 1388 | if eq cid 134 |
| 1389 | if eq a 0 |
| 1390 | ret 0 |
| 1391 | end |
| 1392 | c = ulong 0 |
| 1393 | d = ulong 1 |
| 1394 | while le d div a d bound 2000 |
| 1395 | if eq rem a d 0 |
| 1396 | c = add c 1 |
| 1397 | if ne d div a d |
| 1398 | c = add c 1 |
| 1399 | end |
| 1400 | end |
| 1401 | d = add d 1 |
| 1402 | end |
| 1403 | ret c |
| 1404 | end |
| 1405 | if eq cid 135 |
| 1406 | if eq a 0 |
| 1407 | ret 0 |
| 1408 | end |
| 1409 | s = ulong 0 |
| 1410 | d = ulong 1 |
| 1411 | while le d div a d bound 2000 |
| 1412 | if eq rem a d 0 |
| 1413 | s = add s d |
| 1414 | q = div a d |
| 1415 | if ne d q |
| 1416 | s = add s q |
| 1417 | end |
| 1418 | end |
| 1419 | d = add d 1 |
| 1420 | end |
| 1421 | ret s |
| 1422 | end |
| 1423 | if eq cid 136 |
| 1424 | if eq a 0 |
| 1425 | ret 0 |
| 1426 | end |
| 1427 | c = ulong 0 |
| 1428 | x = a |
| 1429 | while eq rem x 10 0 bound 24 |
| 1430 | c = add c 1 |
| 1431 | x = div x 10 |
| 1432 | end |
| 1433 | ret c |
| 1434 | end |
| 1435 | if eq cid 138 |
| 1436 | if le a 1 |
| 1437 | ret 1 |
| 1438 | end |
| 1439 | p = ulong 1 |
| 1440 | while lt p a bound 64 |
| 1441 | p = shl p 1 |
| 1442 | end |
| 1443 | ret p |
| 1444 | end |
| 1445 | if eq cid 139 |
| 1446 | ret div mul a add a 1 2 |
| 1447 | end |
| 1448 | if eq cid 140 |
| 1449 | if eq a 0 |
| 1450 | ret 1 |
| 1451 | end |
| 1452 | c = ulong 0 |
| 1453 | x = a |
| 1454 | while gt x 0 bound 24 |
| 1455 | if eq and rem x 10 1 0 |
| 1456 | c = add c 1 |
| 1457 | end |
| 1458 | x = div x 10 |
| 1459 | end |
| 1460 | ret c |
| 1461 | end |
| 1462 | if eq cid 141 |
| 1463 | c = ulong 0 |
| 1464 | x = a |
| 1465 | while gt x 0 bound 24 |
| 1466 | if ne and rem x 10 1 0 |
| 1467 | c = add c 1 |
| 1468 | end |
| 1469 | x = div x 10 |
| 1470 | end |
| 1471 | ret c |
| 1472 | end |
| 1473 | ret 999999999 |
| 1474 | end |
| 1475 | |
| 1476 | fn evalBin cid ulong a ulong b ulong to ulong |
| 1477 | if eq cid 201 |
| 1478 | if gt a b |
| 1479 | ret a |
| 1480 | end |
| 1481 | ret b |
| 1482 | end |
| 1483 | if eq cid 202 |
| 1484 | if lt a b |
| 1485 | ret a |
| 1486 | end |
| 1487 | ret b |
| 1488 | end |
| 1489 | if eq cid 203 |
| 1490 | if lt a b |
| 1491 | ret sub b a |
| 1492 | end |
| 1493 | ret sub a b |
| 1494 | end |
| 1495 | if eq cid 204 |
| 1496 | d = ulong 0 |
| 1497 | if lt a b |
| 1498 | d = sub b a |
| 1499 | else |
| 1500 | d = sub a b |
| 1501 | end |
| 1502 | ret mul d d |
| 1503 | end |
| 1504 | if eq cid 205 |
| 1505 | ret add mul a a mul b b |
| 1506 | end |
| 1507 | if eq cid 206 |
| 1508 | ret div add a b 2 |
| 1509 | end |
| 1510 | if eq cid 207 |
| 1511 | ret xor a b |
| 1512 | end |
| 1513 | if eq cid 210 |
| 1514 | x = a |
| 1515 | y = b |
| 1516 | while ne y 0 bound 128 |
| 1517 | t = rem x y |
| 1518 | x = y |
| 1519 | y = t |
| 1520 | end |
| 1521 | ret x |
| 1522 | end |
| 1523 | if eq cid 211 |
| 1524 | if or eq a 0 eq b 0 |
| 1525 | ret 0 |
| 1526 | end |
| 1527 | x = a |
| 1528 | y = b |
| 1529 | while ne y 0 bound 128 |
| 1530 | t = rem x y |
| 1531 | x = y |
| 1532 | y = t |
| 1533 | end |
| 1534 | ret mul div a x b |
| 1535 | end |
| 1536 | if eq cid 212 |
| 1537 | r = ulong 1 |
| 1538 | base = a |
| 1539 | e = b |
| 1540 | while gt e 0 bound 64 |
| 1541 | if ne and e 1 0 |
| 1542 | r = mul r base |
| 1543 | end |
| 1544 | base = mul base base |
| 1545 | e = shr e 1 |
| 1546 | end |
| 1547 | ret r |
| 1548 | end |
| 1549 | if eq cid 213 |
| 1550 | x = xor a b |
| 1551 | c = ulong 0 |
| 1552 | while gt x 0 bound 64 |
| 1553 | c = add c and x 1 |
| 1554 | x = shr x 1 |
| 1555 | end |
| 1556 | ret c |
| 1557 | end |
| 1558 | if eq cid 214 |
| 1559 | if eq b 0 |
| 1560 | ret 0 |
| 1561 | end |
| 1562 | ret div a b |
| 1563 | end |
| 1564 | if eq cid 215 |
| 1565 | if eq b 0 |
| 1566 | ret 0 |
| 1567 | end |
| 1568 | ret rem a b |
| 1569 | end |
| 1570 | if eq cid 216 |
| 1571 | if eq b 0 |
| 1572 | ret 0 |
| 1573 | end |
| 1574 | q = div a b |
| 1575 | if ne rem a b 0 |
| 1576 | q = add q 1 |
| 1577 | end |
| 1578 | ret q |
| 1579 | end |
| 1580 | if eq cid 217 |
| 1581 | if le a b |
| 1582 | ret 0 |
| 1583 | end |
| 1584 | ret sub a b |
| 1585 | end |
| 1586 | if eq cid 218 |
| 1587 | if eq b 0 |
| 1588 | ret 0 |
| 1589 | end |
| 1590 | ret sub a rem a b |
| 1591 | end |
| 1592 | if eq cid 219 |
| 1593 | if eq b 0 |
| 1594 | ret 0 |
| 1595 | end |
| 1596 | r = rem a b |
| 1597 | if eq r 0 |
| 1598 | ret a |
| 1599 | end |
| 1600 | ret add a sub b r |
| 1601 | end |
| 1602 | ret evalBin2 cid a b |
| 1603 | end |
| 1604 | |
| 1605 | fn evalBin2 cid ulong a ulong b ulong to ulong |
| 1606 | c0 = get fmNums 0 |
| 1607 | if eq cid 220 |
| 1608 | ret add mul a b add a b |
| 1609 | end |
| 1610 | if eq cid 221 |
| 1611 | ret sub a and a b |
| 1612 | end |
| 1613 | if eq cid 222 |
| 1614 | ret shl and a b 1 |
| 1615 | end |
| 1616 | if eq cid 223 |
| 1617 | ret or shl and a 255 8 and b 255 |
| 1618 | end |
| 1619 | if eq cid 224 |
| 1620 | s = add a b |
| 1621 | if gt s c0 |
| 1622 | ret c0 |
| 1623 | end |
| 1624 | ret s |
| 1625 | end |
| 1626 | if eq cid 225 |
| 1627 | if eq and a 1 0 |
| 1628 | ret a |
| 1629 | end |
| 1630 | ret b |
| 1631 | end |
| 1632 | if eq cid 226 |
| 1633 | za = ulong 0 |
| 1634 | zb = ulong 0 |
| 1635 | if eq a 0 |
| 1636 | za = 1 |
| 1637 | end |
| 1638 | if eq b 0 |
| 1639 | zb = 1 |
| 1640 | end |
| 1641 | ret xor za zb |
| 1642 | end |
| 1643 | if eq cid 227 |
| 1644 | if fmMultiple b a |
| 1645 | ret 1 |
| 1646 | end |
| 1647 | ret 0 |
| 1648 | end |
| 1649 | if eq cid 228 |
| 1650 | s = ulong 0 |
| 1651 | x = a |
| 1652 | while gt x 0 bound 24 |
| 1653 | s = add s rem x 10 |
| 1654 | x = div x 10 |
| 1655 | end |
| 1656 | x = b |
| 1657 | while gt x 0 bound 24 |
| 1658 | s = add s rem x 10 |
| 1659 | x = div x 10 |
| 1660 | end |
| 1661 | ret s |
| 1662 | end |
| 1663 | if eq cid 229 |
| 1664 | c = ulong 0 |
| 1665 | if eq a 0 |
| 1666 | c = add c 1 |
| 1667 | else |
| 1668 | x = a |
| 1669 | while gt x 0 bound 24 |
| 1670 | c = add c 1 |
| 1671 | x = div x 10 |
| 1672 | end |
| 1673 | end |
| 1674 | if eq b 0 |
| 1675 | c = add c 1 |
| 1676 | else |
| 1677 | x = b |
| 1678 | while gt x 0 bound 24 |
| 1679 | c = add c 1 |
| 1680 | x = div x 10 |
| 1681 | end |
| 1682 | end |
| 1683 | ret c |
| 1684 | end |
| 1685 | if eq cid 230 |
| 1686 | ret add mul rem a 10 10 rem b 10 |
| 1687 | end |
| 1688 | if eq cid 231 |
| 1689 | ret add mul 2 a mul 3 b |
| 1690 | end |
| 1691 | if eq cid 232 |
| 1692 | if eq b 0 |
| 1693 | ret 0 |
| 1694 | end |
| 1695 | q = div a b |
| 1696 | if gt q c0 |
| 1697 | ret c0 |
| 1698 | end |
| 1699 | ret q |
| 1700 | end |
| 1701 | if eq cid 233 |
| 1702 | da = ulong 0 |
| 1703 | db = ulong 0 |
| 1704 | if lt a c0 |
| 1705 | da = sub c0 a |
| 1706 | else |
| 1707 | da = sub a c0 |
| 1708 | end |
| 1709 | if lt b c0 |
| 1710 | db = sub c0 b |
| 1711 | else |
| 1712 | db = sub b c0 |
| 1713 | end |
| 1714 | if le da db |
| 1715 | ret a |
| 1716 | end |
| 1717 | ret b |
| 1718 | end |
| 1719 | if eq cid 234 |
| 1720 | if le a b |
| 1721 | if le b c0 |
| 1722 | ret b |
| 1723 | end |
| 1724 | if le a c0 |
| 1725 | ret c0 |
| 1726 | end |
| 1727 | ret a |
| 1728 | end |
| 1729 | if le a c0 |
| 1730 | ret a |
| 1731 | end |
| 1732 | if le b c0 |
| 1733 | ret c0 |
| 1734 | end |
| 1735 | ret b |
| 1736 | end |
| 1737 | ret 999999999 |
| 1738 | end |
| 1739 | |
| 1740 | fn evalTern cid ulong a ulong b ulong c ulong to ulong |
| 1741 | if eq cid 300 |
| 1742 | if lt a b |
| 1743 | ret b |
| 1744 | end |
| 1745 | if gt a c |
| 1746 | ret c |
| 1747 | end |
| 1748 | ret a |
| 1749 | end |
| 1750 | if eq cid 301 |
| 1751 | if le a b |
| 1752 | if le b c |
| 1753 | ret b |
| 1754 | end |
| 1755 | if le a c |
| 1756 | ret c |
| 1757 | end |
| 1758 | ret a |
| 1759 | end |
| 1760 | if le a c |
| 1761 | ret a |
| 1762 | end |
| 1763 | if le b c |
| 1764 | ret c |
| 1765 | end |
| 1766 | ret b |
| 1767 | end |
| 1768 | if eq cid 302 |
| 1769 | m = a |
| 1770 | if gt b m |
| 1771 | m = b |
| 1772 | end |
| 1773 | if gt c m |
| 1774 | m = c |
| 1775 | end |
| 1776 | ret m |
| 1777 | end |
| 1778 | if eq cid 303 |
| 1779 | m = a |
| 1780 | if lt b m |
| 1781 | m = b |
| 1782 | end |
| 1783 | if lt c m |
| 1784 | m = c |
| 1785 | end |
| 1786 | ret m |
| 1787 | end |
| 1788 | if eq cid 304 |
| 1789 | if and ge a b le a c |
| 1790 | ret 1 |
| 1791 | end |
| 1792 | ret 0 |
| 1793 | end |
| 1794 | if eq cid 305 |
| 1795 | ret add add a b c |
| 1796 | end |
| 1797 | if eq cid 306 |
| 1798 | ret mul mul a b c |
| 1799 | end |
| 1800 | ret evalTern2 cid a b c |
| 1801 | end |
| 1802 | |
| 1803 | fn evalTern2 cid ulong a ulong b ulong c ulong to ulong |
| 1804 | c0 = get fmNums 0 |
| 1805 | if eq cid 308 |
| 1806 | if and le a b le b c |
| 1807 | ret 1 |
| 1808 | end |
| 1809 | ret 0 |
| 1810 | end |
| 1811 | if eq cid 309 |
| 1812 | k = ulong 1 |
| 1813 | if ne b a |
| 1814 | k = add k 1 |
| 1815 | end |
| 1816 | if and ne c a ne c b |
| 1817 | k = add k 1 |
| 1818 | end |
| 1819 | ret k |
| 1820 | end |
| 1821 | if eq cid 310 |
| 1822 | ret add add and a 1 and b 1 and c 1 |
| 1823 | end |
| 1824 | if eq cid 311 |
| 1825 | ret or or and a b and a c and b c |
| 1826 | end |
| 1827 | if eq cid 312 |
| 1828 | ret xor xor a b c |
| 1829 | end |
| 1830 | if eq cid 313 |
| 1831 | ret or and a c sub b and b c |
| 1832 | end |
| 1833 | if eq cid 314 |
| 1834 | ret div add add a b c 3 |
| 1835 | end |
| 1836 | if eq cid 315 |
| 1837 | x = a |
| 1838 | y = b |
| 1839 | while ne y 0 bound 128 |
| 1840 | t = rem x y |
| 1841 | x = y |
| 1842 | y = t |
| 1843 | end |
| 1844 | y = c |
| 1845 | while ne y 0 bound 128 |
| 1846 | t = rem x y |
| 1847 | x = y |
| 1848 | y = t |
| 1849 | end |
| 1850 | ret x |
| 1851 | end |
| 1852 | if eq cid 316 |
| 1853 | if or eq a b eq a c |
| 1854 | ret a |
| 1855 | end |
| 1856 | if eq b c |
| 1857 | ret b |
| 1858 | end |
| 1859 | ret 0 |
| 1860 | end |
| 1861 | if eq cid 317 |
| 1862 | if eq a b |
| 1863 | ret c |
| 1864 | end |
| 1865 | if eq a c |
| 1866 | ret b |
| 1867 | end |
| 1868 | ret a |
| 1869 | end |
| 1870 | if eq cid 318 |
| 1871 | ret add mul a b c |
| 1872 | end |
| 1873 | if eq cid 319 |
| 1874 | r = ulong 1 |
| 1875 | if eq b a |
| 1876 | r = add r 1 |
| 1877 | end |
| 1878 | if eq c a |
| 1879 | r = add r 1 |
| 1880 | end |
| 1881 | ret r |
| 1882 | end |
| 1883 | if eq cid 320 |
| 1884 | if eq c 0 |
| 1885 | ret a |
| 1886 | end |
| 1887 | ret b |
| 1888 | end |
| 1889 | if eq cid 321 |
| 1890 | if eq and c 1 0 |
| 1891 | ret add a b |
| 1892 | end |
| 1893 | ret mul a b |
| 1894 | end |
| 1895 | if eq cid 322 |
| 1896 | r = ulong 0 |
| 1897 | if gt a c0 |
| 1898 | r = add r 1 |
| 1899 | end |
| 1900 | if gt b c0 |
| 1901 | r = add r 1 |
| 1902 | end |
| 1903 | if gt c c0 |
| 1904 | r = add r 1 |
| 1905 | end |
| 1906 | ret r |
| 1907 | end |
| 1908 | ret 999999999 |
| 1909 | end |
| 1910 | |
| 1911 | note Emit fold spec for cid in 400..454 on 4 fixed diverse arrays: |
| 1912 | note A1=[3,7,2,9] n=4, A2=[10,5,20] n=3, A3=[1,2,3,4,5] n=5, A4=[0,4,0,8] n=4 |
| 1913 | global faA ulong 32 |
| 1914 | global faN ulong 4 |
| 1915 | |
| 1916 | fn initFoldArrays to void |
| 1917 | put faN 0 4 |
| 1918 | put faA 0 3 |
| 1919 | put faA 1 7 |
| 1920 | put faA 2 2 |
| 1921 | put faA 3 9 |
| 1922 | put faN 1 3 |
| 1923 | put faA 8 10 |
| 1924 | put faA 9 5 |
| 1925 | put faA 10 20 |
| 1926 | put faN 2 5 |
| 1927 | put faA 16 1 |
| 1928 | put faA 17 2 |
| 1929 | put faA 18 3 |
| 1930 | put faA 19 4 |
| 1931 | put faA 20 5 |
| 1932 | put faN 3 4 |
| 1933 | put faA 24 0 |
| 1934 | put faA 25 4 |
| 1935 | put faA 26 4 |
| 1936 | put faA 27 0 |
| 1937 | end |
| 1938 | |
| 1939 | fn evalFoldFixed cid ulong ci ulong to ulong |
| 1940 | n = get faN ci |
| 1941 | base = mul ci 8 |
| 1942 | if eq cid 400 |
| 1943 | acc = ulong 0 |
| 1944 | for i ulong n bound 8 |
| 1945 | acc = add acc get faA add base i |
| 1946 | end |
| 1947 | ret acc |
| 1948 | end |
| 1949 | if eq cid 401 |
| 1950 | acc = ulong 1 |
| 1951 | for i ulong n bound 8 |
| 1952 | acc = mul acc get faA add base i |
| 1953 | end |
| 1954 | ret acc |
| 1955 | end |
| 1956 | if eq cid 402 |
| 1957 | acc = ulong 0 |
| 1958 | for i ulong n bound 8 |
| 1959 | v = get faA add base i |
| 1960 | if gt v acc |
| 1961 | acc = v |
| 1962 | end |
| 1963 | end |
| 1964 | ret acc |
| 1965 | end |
| 1966 | if eq cid 403 |
| 1967 | acc = get faA base |
| 1968 | for i ulong n bound 8 |
| 1969 | v = get faA add base i |
| 1970 | if lt v acc |
| 1971 | acc = v |
| 1972 | end |
| 1973 | end |
| 1974 | ret acc |
| 1975 | end |
| 1976 | if eq cid 404 |
| 1977 | acc = ulong 0 |
| 1978 | for i ulong n bound 8 |
| 1979 | acc = xor acc get faA add base i |
| 1980 | end |
| 1981 | ret acc |
| 1982 | end |
| 1983 | if eq cid 405 |
| 1984 | acc = ulong 0 |
| 1985 | for i ulong n bound 8 |
| 1986 | acc = or acc get faA add base i |
| 1987 | end |
| 1988 | ret acc |
| 1989 | end |
| 1990 | if eq cid 406 |
| 1991 | acc = get faA base |
| 1992 | for i ulong n bound 8 |
| 1993 | acc = and acc get faA add base i |
| 1994 | end |
| 1995 | ret acc |
| 1996 | end |
| 1997 | if eq cid 407 |
| 1998 | acc = ulong 0 |
| 1999 | for i ulong n bound 8 |
| 2000 | if eq and get faA add base i 1 0 |
| 2001 | acc = add acc 1 |
| 2002 | end |
| 2003 | end |
| 2004 | ret acc |
| 2005 | end |
| 2006 | if eq cid 408 |
| 2007 | acc = ulong 0 |
| 2008 | for i ulong n bound 8 |
| 2009 | if ne and get faA add base i 1 0 |
| 2010 | acc = add acc 1 |
| 2011 | end |
| 2012 | end |
| 2013 | ret acc |
| 2014 | end |
| 2015 | if eq cid 409 |
| 2016 | acc = ulong 0 |
| 2017 | for i ulong n bound 8 |
| 2018 | if ne get faA add base i 0 |
| 2019 | acc = add acc 1 |
| 2020 | end |
| 2021 | end |
| 2022 | ret acc |
| 2023 | end |
| 2024 | if eq cid 410 |
| 2025 | acc = ulong 0 |
| 2026 | for i ulong n bound 8 |
| 2027 | if eq get faA add base i 0 |
| 2028 | acc = add acc 1 |
| 2029 | end |
| 2030 | end |
| 2031 | ret acc |
| 2032 | end |
| 2033 | if eq cid 411 |
| 2034 | acc = ulong 0 |
| 2035 | for i ulong n bound 8 |
| 2036 | v = get faA add base i |
| 2037 | acc = add acc mul v v |
| 2038 | end |
| 2039 | ret acc |
| 2040 | end |
| 2041 | if eq cid 412 |
| 2042 | acc = ulong 0 |
| 2043 | for i ulong n bound 8 |
| 2044 | v = get faA add base i |
| 2045 | if eq and v 1 0 |
| 2046 | acc = add acc v |
| 2047 | end |
| 2048 | end |
| 2049 | ret acc |
| 2050 | end |
| 2051 | if eq cid 413 |
| 2052 | acc = ulong 0 |
| 2053 | for i ulong n bound 8 |
| 2054 | v = get faA add base i |
| 2055 | if ne and v 1 0 |
| 2056 | acc = add acc v |
| 2057 | end |
| 2058 | end |
| 2059 | ret acc |
| 2060 | end |
| 2061 | if eq cid 414 |
| 2062 | lo = get faA base |
| 2063 | hi = lo |
| 2064 | for i ulong n bound 8 |
| 2065 | v = get faA add base i |
| 2066 | if lt v lo |
| 2067 | lo = v |
| 2068 | end |
| 2069 | if gt v hi |
| 2070 | hi = v |
| 2071 | end |
| 2072 | end |
| 2073 | ret sub hi lo |
| 2074 | end |
| 2075 | if eq cid 415 |
| 2076 | bi = ulong 0 |
| 2077 | bv = get faA base |
| 2078 | for i ulong n bound 8 |
| 2079 | v = get faA add base i |
| 2080 | if gt v bv |
| 2081 | bv = v |
| 2082 | bi = i |
| 2083 | end |
| 2084 | end |
| 2085 | ret bi |
| 2086 | end |
| 2087 | if eq cid 416 |
| 2088 | bi = ulong 0 |
| 2089 | bv = get faA base |
| 2090 | for i ulong n bound 8 |
| 2091 | v = get faA add base i |
| 2092 | if lt v bv |
| 2093 | bv = v |
| 2094 | bi = i |
| 2095 | end |
| 2096 | end |
| 2097 | ret bi |
| 2098 | end |
| 2099 | if eq cid 417 |
| 2100 | i = ulong 1 |
| 2101 | while lt i n bound 8 |
| 2102 | if lt get faA add base i get faA add base sub i 1 |
| 2103 | ret 0 |
| 2104 | end |
| 2105 | i = add i 1 |
| 2106 | end |
| 2107 | ret 1 |
| 2108 | end |
| 2109 | if eq cid 418 |
| 2110 | i = ulong 1 |
| 2111 | while lt i n bound 8 |
| 2112 | if le get faA add base i get faA add base sub i 1 |
| 2113 | ret 0 |
| 2114 | end |
| 2115 | i = add i 1 |
| 2116 | end |
| 2117 | ret 1 |
| 2118 | end |
| 2119 | if eq cid 419 |
| 2120 | v0 = get faA base |
| 2121 | for i ulong n bound 8 |
| 2122 | if ne get faA add base i v0 |
| 2123 | ret 0 |
| 2124 | end |
| 2125 | end |
| 2126 | ret 1 |
| 2127 | end |
| 2128 | if eq cid 420 |
| 2129 | for i ulong n bound 8 |
| 2130 | v = get faA add base i |
| 2131 | if ne v 0 |
| 2132 | ret v |
| 2133 | end |
| 2134 | end |
| 2135 | ret 0 |
| 2136 | end |
| 2137 | if eq cid 421 |
| 2138 | r = ulong 0 |
| 2139 | for i ulong n bound 8 |
| 2140 | v = get faA add base i |
| 2141 | if ne v 0 |
| 2142 | r = v |
| 2143 | end |
| 2144 | end |
| 2145 | ret r |
| 2146 | end |
| 2147 | if eq cid 422 |
| 2148 | acc = ulong 0 |
| 2149 | for i ulong n bound 8 |
| 2150 | acc = add acc mul i get faA add base i |
| 2151 | end |
| 2152 | ret acc |
| 2153 | end |
| 2154 | if eq cid 423 |
| 2155 | s = ulong 0 |
| 2156 | i = ulong 1 |
| 2157 | while lt i n bound 8 |
| 2158 | x = get faA add base i |
| 2159 | y = get faA add base sub i 1 |
| 2160 | if ge x y |
| 2161 | s = add s sub x y |
| 2162 | else |
| 2163 | s = add s sub y x |
| 2164 | end |
| 2165 | i = add i 1 |
| 2166 | end |
| 2167 | ret s |
| 2168 | end |
| 2169 | if eq cid 424 |
| 2170 | m = ulong 0 |
| 2171 | i = ulong 1 |
| 2172 | while lt i n bound 8 |
| 2173 | x = get faA add base i |
| 2174 | y = get faA add base sub i 1 |
| 2175 | d = ulong 0 |
| 2176 | if ge x y |
| 2177 | d = sub x y |
| 2178 | else |
| 2179 | d = sub y x |
| 2180 | end |
| 2181 | if gt d m |
| 2182 | m = d |
| 2183 | end |
| 2184 | i = add i 1 |
| 2185 | end |
| 2186 | ret m |
| 2187 | end |
| 2188 | if eq cid 425 |
| 2189 | c = ulong 0 |
| 2190 | i = ulong 1 |
| 2191 | while lt i n bound 8 |
| 2192 | if gt get faA add base i get faA add base sub i 1 |
| 2193 | c = add c 1 |
| 2194 | end |
| 2195 | i = add i 1 |
| 2196 | end |
| 2197 | ret c |
| 2198 | end |
| 2199 | if eq cid 426 |
| 2200 | c = ulong 1 |
| 2201 | m = get faA base |
| 2202 | i = ulong 1 |
| 2203 | while lt i n bound 8 |
| 2204 | v = get faA add base i |
| 2205 | if gt v m |
| 2206 | m = v |
| 2207 | c = add c 1 |
| 2208 | end |
| 2209 | i = add i 1 |
| 2210 | end |
| 2211 | ret c |
| 2212 | end |
| 2213 | if eq cid 427 |
| 2214 | m1 = ulong 0 |
| 2215 | m2 = ulong 0 |
| 2216 | for i ulong n bound 8 |
| 2217 | v = get faA add base i |
| 2218 | if gt v m1 |
| 2219 | m2 = m1 |
| 2220 | m1 = v |
| 2221 | else |
| 2222 | if and gt v m2 lt v m1 |
| 2223 | m2 = v |
| 2224 | end |
| 2225 | end |
| 2226 | end |
| 2227 | ret m2 |
| 2228 | end |
| 2229 | if eq cid 428 |
| 2230 | best = ulong 0 |
| 2231 | cur = ulong 0 |
| 2232 | for i ulong n bound 8 |
| 2233 | if ne get faA add base i 0 |
| 2234 | cur = add cur 1 |
| 2235 | if gt cur best |
| 2236 | best = cur |
| 2237 | end |
| 2238 | else |
| 2239 | cur = 0 |
| 2240 | end |
| 2241 | end |
| 2242 | ret best |
| 2243 | end |
| 2244 | kv = get fmNums 0 |
| 2245 | if eq cid 450 |
| 2246 | acc = ulong 0 |
| 2247 | for i ulong n bound 8 |
| 2248 | if gt get faA add base i kv |
| 2249 | acc = add acc 1 |
| 2250 | end |
| 2251 | end |
| 2252 | ret acc |
| 2253 | end |
| 2254 | if eq cid 451 |
| 2255 | acc = ulong 0 |
| 2256 | for i ulong n bound 8 |
| 2257 | if lt get faA add base i kv |
| 2258 | acc = add acc 1 |
| 2259 | end |
| 2260 | end |
| 2261 | ret acc |
| 2262 | end |
| 2263 | if eq cid 452 |
| 2264 | acc = ulong 0 |
| 2265 | for i ulong n bound 8 |
| 2266 | if eq get faA add base i kv |
| 2267 | acc = add acc 1 |
| 2268 | end |
| 2269 | end |
| 2270 | ret acc |
| 2271 | end |
| 2272 | if eq cid 453 |
| 2273 | acc = ulong 0 |
| 2274 | for i ulong n bound 8 |
| 2275 | if ge get faA add base i kv |
| 2276 | acc = add acc 1 |
| 2277 | end |
| 2278 | end |
| 2279 | ret acc |
| 2280 | end |
| 2281 | if eq cid 454 |
| 2282 | if eq kv 0 |
| 2283 | ret 999999999 |
| 2284 | end |
| 2285 | acc = ulong 0 |
| 2286 | for i ulong n bound 8 |
| 2287 | if eq rem get faA add base i kv 0 |
| 2288 | acc = add acc 1 |
| 2289 | end |
| 2290 | end |
| 2291 | ret acc |
| 2292 | end |
| 2293 | ret evalFoldFixed2 cid ci |
| 2294 | end |
| 2295 | |
| 2296 | fn evalFoldFixed2 cid ulong ci ulong to ulong |
| 2297 | if le cid 436 |
| 2298 | ret evalFoldFixed2A cid ci |
| 2299 | end |
| 2300 | ret evalFoldFixed2B cid ci |
| 2301 | end |
| 2302 | |
| 2303 | fn evalFoldFixed2A cid ulong ci ulong to ulong |
| 2304 | n = get faN ci |
| 2305 | base = mul ci 8 |
| 2306 | if eq cid 430 |
| 2307 | if eq n 0 |
| 2308 | ret 0 |
| 2309 | end |
| 2310 | ret get faA add base sub n 1 |
| 2311 | end |
| 2312 | if eq cid 431 |
| 2313 | acc = ulong 0 |
| 2314 | for i ulong n bound 8 |
| 2315 | if eq and i 1 0 |
| 2316 | acc = add acc get faA add base i |
| 2317 | end |
| 2318 | end |
| 2319 | ret acc |
| 2320 | end |
| 2321 | if eq cid 432 |
| 2322 | acc = ulong 0 |
| 2323 | for i ulong n bound 8 |
| 2324 | if eq and i 1 0 |
| 2325 | acc = add acc get faA add base i |
| 2326 | else |
| 2327 | acc = sub acc get faA add base i |
| 2328 | end |
| 2329 | end |
| 2330 | ret acc |
| 2331 | end |
| 2332 | if eq cid 433 |
| 2333 | if eq n 0 |
| 2334 | ret 0 |
| 2335 | end |
| 2336 | v0 = get faA base |
| 2337 | c = ulong 0 |
| 2338 | for i ulong n bound 8 |
| 2339 | if eq get faA add base i v0 |
| 2340 | c = add c 1 |
| 2341 | end |
| 2342 | end |
| 2343 | ret c |
| 2344 | end |
| 2345 | if eq cid 434 |
| 2346 | if eq n 0 |
| 2347 | ret 0 |
| 2348 | end |
| 2349 | v0 = get faA base |
| 2350 | c = ulong 0 |
| 2351 | for i ulong n bound 8 |
| 2352 | if lt get faA add base i v0 |
| 2353 | c = add c 1 |
| 2354 | end |
| 2355 | end |
| 2356 | ret c |
| 2357 | end |
| 2358 | if eq cid 435 |
| 2359 | c = ulong 0 |
| 2360 | for i ulong n bound 8 |
| 2361 | if eq get faA add base i i |
| 2362 | c = add c 1 |
| 2363 | end |
| 2364 | end |
| 2365 | ret c |
| 2366 | end |
| 2367 | if eq cid 436 |
| 2368 | c = ulong 0 |
| 2369 | for i ulong n bound 8 |
| 2370 | seen = ulong 0 |
| 2371 | for j ulong i bound 8 |
| 2372 | if eq get faA add base j get faA add base i |
| 2373 | seen = 1 |
| 2374 | end |
| 2375 | end |
| 2376 | if eq seen 0 |
| 2377 | c = add c 1 |
| 2378 | end |
| 2379 | end |
| 2380 | ret c |
| 2381 | end |
| 2382 | ret 999999999 |
| 2383 | end |
| 2384 | |
| 2385 | fn evalFoldFixed2B cid ulong ci ulong to ulong |
| 2386 | n = get faN ci |
| 2387 | base = mul ci 8 |
| 2388 | kv = get fmNums 0 |
| 2389 | if eq cid 437 |
| 2390 | for i ulong n bound 8 |
| 2391 | for j ulong i bound 8 |
| 2392 | if eq get faA add base j get faA add base i |
| 2393 | ret 1 |
| 2394 | end |
| 2395 | end |
| 2396 | end |
| 2397 | ret 0 |
| 2398 | end |
| 2399 | if eq cid 438 |
| 2400 | r = n |
| 2401 | for i ulong n bound 8 |
| 2402 | if ne and get faA add base i 1 0 |
| 2403 | r = i |
| 2404 | end |
| 2405 | end |
| 2406 | ret r |
| 2407 | end |
| 2408 | if eq cid 439 |
| 2409 | if eq n 0 |
| 2410 | ret 0 |
| 2411 | end |
| 2412 | best = ulong 1 |
| 2413 | cur = ulong 1 |
| 2414 | i = ulong 1 |
| 2415 | while lt i n bound 8 |
| 2416 | if eq get faA add base i get faA add base sub i 1 |
| 2417 | cur = add cur 1 |
| 2418 | if gt cur best |
| 2419 | best = cur |
| 2420 | end |
| 2421 | else |
| 2422 | cur = 1 |
| 2423 | end |
| 2424 | i = add i 1 |
| 2425 | end |
| 2426 | ret best |
| 2427 | end |
| 2428 | if eq cid 440 |
| 2429 | g = ulong 0 |
| 2430 | for i ulong n bound 8 |
| 2431 | x = g |
| 2432 | y = get faA add base i |
| 2433 | while ne y 0 bound 128 |
| 2434 | t = rem x y |
| 2435 | x = y |
| 2436 | y = t |
| 2437 | end |
| 2438 | g = x |
| 2439 | end |
| 2440 | ret g |
| 2441 | end |
| 2442 | if eq cid 441 |
| 2443 | se = ulong 0 |
| 2444 | so = ulong 0 |
| 2445 | for i ulong n bound 8 |
| 2446 | if eq and i 1 0 |
| 2447 | se = add se get faA add base i |
| 2448 | else |
| 2449 | so = add so get faA add base i |
| 2450 | end |
| 2451 | end |
| 2452 | if lt se so |
| 2453 | ret 0 |
| 2454 | end |
| 2455 | ret sub se so |
| 2456 | end |
| 2457 | if eq cid 442 |
| 2458 | for i ulong n bound 8 |
| 2459 | if eq get faA add base i 0 |
| 2460 | ret i |
| 2461 | end |
| 2462 | end |
| 2463 | ret n |
| 2464 | end |
| 2465 | if eq cid 458 |
| 2466 | for i ulong n bound 8 |
| 2467 | v = get faA add base i |
| 2468 | if gt v kv |
| 2469 | ret v |
| 2470 | end |
| 2471 | end |
| 2472 | ret 0 |
| 2473 | end |
| 2474 | ret 999999999 |
| 2475 | end |
| 2476 | |
| 2477 | note Rewrite spec emitter on 3 fixed 8-element arrays |
| 2478 | global frTmp ulong 8 |
| 2479 | |
| 2480 | fn applyRew cid ulong n ulong kv ulong to void |
| 2481 | if eq cid 500 |
| 2482 | i = ulong 0 |
| 2483 | while lt mul i 2 n bound 8 |
| 2484 | j = sub sub n 1 i |
| 2485 | t = get frTmp i |
| 2486 | put frTmp i get frTmp j |
| 2487 | put frTmp j t |
| 2488 | i = add i 1 |
| 2489 | end |
| 2490 | ret |
| 2491 | end |
| 2492 | if eq cid 501 |
| 2493 | for i ulong n bound 8 |
| 2494 | for j ulong n bound 8 |
| 2495 | if and gt j i lt get frTmp j get frTmp i |
| 2496 | t = get frTmp i |
| 2497 | put frTmp i get frTmp j |
| 2498 | put frTmp j t |
| 2499 | end |
| 2500 | end |
| 2501 | end |
| 2502 | ret |
| 2503 | end |
| 2504 | if eq cid 502 |
| 2505 | for i ulong n bound 8 |
| 2506 | for j ulong n bound 8 |
| 2507 | if and gt j i gt get frTmp j get frTmp i |
| 2508 | t = get frTmp i |
| 2509 | put frTmp i get frTmp j |
| 2510 | put frTmp j t |
| 2511 | end |
| 2512 | end |
| 2513 | end |
| 2514 | ret |
| 2515 | end |
| 2516 | if eq cid 503 |
| 2517 | s = ulong 0 |
| 2518 | for i ulong n bound 8 |
| 2519 | s = add s get frTmp i |
| 2520 | put frTmp i s |
| 2521 | end |
| 2522 | ret |
| 2523 | end |
| 2524 | if eq cid 504 |
| 2525 | m = ulong 0 |
| 2526 | for i ulong n bound 8 |
| 2527 | v = get frTmp i |
| 2528 | if gt v m |
| 2529 | m = v |
| 2530 | end |
| 2531 | put frTmp i m |
| 2532 | end |
| 2533 | ret |
| 2534 | end |
| 2535 | if eq cid 505 |
| 2536 | for i ulong n bound 8 |
| 2537 | put frTmp i mul get frTmp i 2 |
| 2538 | end |
| 2539 | ret |
| 2540 | end |
| 2541 | if eq cid 506 |
| 2542 | for i ulong n bound 8 |
| 2543 | put frTmp i div get frTmp i 2 |
| 2544 | end |
| 2545 | ret |
| 2546 | end |
| 2547 | if eq cid 507 |
| 2548 | for i ulong n bound 8 |
| 2549 | v = get frTmp i |
| 2550 | put frTmp i mul v v |
| 2551 | end |
| 2552 | ret |
| 2553 | end |
| 2554 | if eq cid 508 |
| 2555 | for i ulong n bound 8 |
| 2556 | if eq and get frTmp i 1 0 |
| 2557 | put frTmp i 0 |
| 2558 | end |
| 2559 | end |
| 2560 | ret |
| 2561 | end |
| 2562 | if eq cid 509 |
| 2563 | for i ulong n bound 8 |
| 2564 | if ne and get frTmp i 1 0 |
| 2565 | put frTmp i 0 |
| 2566 | end |
| 2567 | end |
| 2568 | ret |
| 2569 | end |
| 2570 | if eq cid 510 |
| 2571 | if gt n 1 |
| 2572 | f = get frTmp 0 |
| 2573 | i = ulong 1 |
| 2574 | while lt i n bound 8 |
| 2575 | put frTmp sub i 1 get frTmp i |
| 2576 | i = add i 1 |
| 2577 | end |
| 2578 | put frTmp sub n 1 f |
| 2579 | end |
| 2580 | ret |
| 2581 | end |
| 2582 | if eq cid 511 |
| 2583 | if gt n 1 |
| 2584 | l = get frTmp sub n 1 |
| 2585 | i = sub n 1 |
| 2586 | while gt i 0 bound 8 |
| 2587 | put frTmp i get frTmp sub i 1 |
| 2588 | i = sub i 1 |
| 2589 | end |
| 2590 | put frTmp 0 l |
| 2591 | end |
| 2592 | ret |
| 2593 | end |
| 2594 | if eq cid 512 |
| 2595 | if gt n 0 |
| 2596 | i = ulong 1 |
| 2597 | while lt i n bound 8 |
| 2598 | put frTmp sub i 1 get frTmp i |
| 2599 | i = add i 1 |
| 2600 | end |
| 2601 | put frTmp sub n 1 0 |
| 2602 | end |
| 2603 | ret |
| 2604 | end |
| 2605 | if eq cid 513 |
| 2606 | if gt n 0 |
| 2607 | i = sub n 1 |
| 2608 | while gt i 0 bound 8 |
| 2609 | put frTmp i get frTmp sub i 1 |
| 2610 | i = sub i 1 |
| 2611 | end |
| 2612 | put frTmp 0 0 |
| 2613 | end |
| 2614 | ret |
| 2615 | end |
| 2616 | if eq cid 514 |
| 2617 | i = ulong 0 |
| 2618 | while lt add i 1 n bound 8 |
| 2619 | t = get frTmp i |
| 2620 | put frTmp i get frTmp add i 1 |
| 2621 | put frTmp add i 1 t |
| 2622 | i = add i 2 |
| 2623 | end |
| 2624 | ret |
| 2625 | end |
| 2626 | if eq cid 515 |
| 2627 | w = ulong 0 |
| 2628 | for i ulong n bound 8 |
| 2629 | v = get frTmp i |
| 2630 | if ne v 0 |
| 2631 | put frTmp w v |
| 2632 | w = add w 1 |
| 2633 | end |
| 2634 | end |
| 2635 | while lt w n bound 8 |
| 2636 | put frTmp w 0 |
| 2637 | w = add w 1 |
| 2638 | end |
| 2639 | ret |
| 2640 | end |
| 2641 | if eq cid 518 |
| 2642 | x = ulong 0 |
| 2643 | for i ulong n bound 8 |
| 2644 | x = xor x get frTmp i |
| 2645 | put frTmp i x |
| 2646 | end |
| 2647 | ret |
| 2648 | end |
| 2649 | for i ulong n bound 8 |
| 2650 | v = get frTmp i |
| 2651 | if eq cid 550 |
| 2652 | put frTmp i add v kv |
| 2653 | end |
| 2654 | if eq cid 551 |
| 2655 | if le v kv |
| 2656 | put frTmp i 0 |
| 2657 | else |
| 2658 | put frTmp i sub v kv |
| 2659 | end |
| 2660 | end |
| 2661 | if eq cid 552 |
| 2662 | put frTmp i mul v kv |
| 2663 | end |
| 2664 | if eq cid 555 |
| 2665 | if gt v kv |
| 2666 | put frTmp i kv |
| 2667 | end |
| 2668 | end |
| 2669 | if eq cid 556 |
| 2670 | if lt v kv |
| 2671 | put frTmp i kv |
| 2672 | end |
| 2673 | end |
| 2674 | if eq cid 557 |
| 2675 | if lt v kv |
| 2676 | put frTmp i 0 |
| 2677 | end |
| 2678 | end |
| 2679 | if eq cid 558 |
| 2680 | if gt v kv |
| 2681 | put frTmp i 0 |
| 2682 | end |
| 2683 | end |
| 2684 | if eq cid 559 |
| 2685 | if eq v 0 |
| 2686 | put frTmp i kv |
| 2687 | end |
| 2688 | end |
| 2689 | if eq cid 560 |
| 2690 | put frTmp i kv |
| 2691 | end |
| 2692 | end |
| 2693 | end |
| 2694 | |
| 2695 | fn emitRewArr to void |
| 2696 | for k ulong 8 bound 8 |
| 2697 | if gt k 0 |
| 2698 | foCh 32 |
| 2699 | end |
| 2700 | foNum get frTmp k |
| 2701 | end |
| 2702 | end |
| 2703 | |
| 2704 | fn fmEmitRew cid ulong to bool |
| 2705 | kv = get fmNums 0 |
| 2706 | foClr |
| 2707 | foTxt oArity |
| 2708 | foNum 5 |
| 2709 | foCh 10 |
| 2710 | foTxt oConsts |
| 2711 | foNum 0 |
| 2712 | foCh 32 |
| 2713 | foNum 1 |
| 2714 | foCh 32 |
| 2715 | foNum 2 |
| 2716 | nn = get fmSt 4 |
| 2717 | for k ulong nn bound 16 |
| 2718 | foCh 32 |
| 2719 | foNum get fmNums k |
| 2720 | end |
| 2721 | foCh 10 |
| 2722 | note Case 1: n=4 [3,7,2,9,5,1,8,4] |
| 2723 | foTxt tRew1 |
| 2724 | put frTmp 0 3 |
| 2725 | put frTmp 1 7 |
| 2726 | put frTmp 2 2 |
| 2727 | put frTmp 3 9 |
| 2728 | put frTmp 4 5 |
| 2729 | put frTmp 5 1 |
| 2730 | put frTmp 6 8 |
| 2731 | put frTmp 7 4 |
| 2732 | applyRew cid 4 kv |
| 2733 | emitRewArr |
| 2734 | note Case 2: n=5 [10,0,5,0,20,3,6,1] |
| 2735 | foTxt tRew2 |
| 2736 | put frTmp 0 10 |
| 2737 | put frTmp 1 0 |
| 2738 | put frTmp 2 5 |
| 2739 | put frTmp 3 0 |
| 2740 | put frTmp 4 20 |
| 2741 | put frTmp 5 3 |
| 2742 | put frTmp 6 6 |
| 2743 | put frTmp 7 1 |
| 2744 | applyRew cid 5 kv |
| 2745 | emitRewArr |
| 2746 | note Case 3: n=6 [1,2,3,4,5,6,7,8] |
| 2747 | foTxt tRew3 |
| 2748 | put frTmp 0 1 |
| 2749 | put frTmp 1 2 |
| 2750 | put frTmp 2 3 |
| 2751 | put frTmp 3 4 |
| 2752 | put frTmp 4 5 |
| 2753 | put frTmp 5 6 |
| 2754 | put frTmp 6 7 |
| 2755 | put frTmp 7 8 |
| 2756 | applyRew cid 6 kv |
| 2757 | emitRewArr |
| 2758 | foCh 10 |
| 2759 | ret true |
| 2760 | end |
| 2761 | |
| 2762 | fn fmEmitFold cid ulong to bool |
| 2763 | initFoldArrays |
| 2764 | y0 = evalFoldFixed cid 0 |
| 2765 | y1 = evalFoldFixed cid 1 |
| 2766 | y2 = evalFoldFixed cid 2 |
| 2767 | y3 = evalFoldFixed cid 3 |
| 2768 | if or eq y0 999999999 eq y1 999999999 |
| 2769 | ret false |
| 2770 | end |
| 2771 | foClr |
| 2772 | foTxt oArity |
| 2773 | foNum 4 |
| 2774 | foCh 10 |
| 2775 | foTxt oConsts |
| 2776 | foNum 0 |
| 2777 | foCh 32 |
| 2778 | foNum 1 |
| 2779 | foCh 32 |
| 2780 | foNum 2 |
| 2781 | nn = get fmSt 4 |
| 2782 | for k ulong nn bound 16 |
| 2783 | foCh 32 |
| 2784 | foNum get fmNums k |
| 2785 | end |
| 2786 | foCh 10 |
| 2787 | foTxt tFoldA1 |
| 2788 | foNum y0 |
| 2789 | foTxt tFoldA2 |
| 2790 | foNum y1 |
| 2791 | foTxt tFoldA3 |
| 2792 | foNum y2 |
| 2793 | foTxt tFoldA4 |
| 2794 | foNum y3 |
| 2795 | foCh 10 |
| 2796 | ret true |
| 2797 | end |
| 2798 | |
| 2799 | fn fmNeedsDep2 cid ulong to bool |
| 2800 | if or eq cid 101 or eq cid 102 eq cid 104 |
| 2801 | ret true |
| 2802 | end |
| 2803 | if or eq cid 106 or eq cid 108 eq cid 109 |
| 2804 | ret true |
| 2805 | end |
| 2806 | if or eq cid 204 eq cid 205 |
| 2807 | ret true |
| 2808 | end |
| 2809 | if and ge cid 220 le cid 234 |
| 2810 | ret true |
| 2811 | end |
| 2812 | ret false |
| 2813 | end |
| 2814 | |
| 2815 | fn fmEmitScalarSpec cid ulong ar ulong to void |
| 2816 | foClr |
| 2817 | foTxt oArity |
| 2818 | foNum ar |
| 2819 | foCh 10 |
| 2820 | foTxt oDepth |
| 2821 | if fmNeedsDep2 cid |
| 2822 | foNum 2 |
| 2823 | else |
| 2824 | foNum 1 |
| 2825 | end |
| 2826 | foCh 10 |
| 2827 | foTxt oConsts |
| 2828 | foNum 0 |
| 2829 | foCh 32 |
| 2830 | foNum 1 |
| 2831 | foCh 32 |
| 2832 | foNum 2 |
| 2833 | foCh 32 |
| 2834 | foNum 3 |
| 2835 | nn = get fmSt 4 |
| 2836 | for k ulong nn bound 16 |
| 2837 | foCh 32 |
| 2838 | foNum get fmNums k |
| 2839 | end |
| 2840 | foCh 10 |
| 2841 | for i ulong 8 bound 8 |
| 2842 | foTxt oCase |
| 2843 | foNum get fmInA i |
| 2844 | foCh 32 |
| 2845 | if ge ar 2 |
| 2846 | foNum get fmInB i |
| 2847 | foCh 32 |
| 2848 | end |
| 2849 | if ge ar 3 |
| 2850 | foNum get fmInC i |
| 2851 | foCh 32 |
| 2852 | end |
| 2853 | foNum get fmP1 i |
| 2854 | foCh 10 |
| 2855 | end |
| 2856 | end |
| 2857 | |
| 2858 | fn fmBuildSpec cid ulong to bool |
| 2859 | if ge cid 500 |
| 2860 | ret fmEmitRew cid |
| 2861 | end |
| 2862 | if ge cid 400 |
| 2863 | ret fmEmitFold cid |
| 2864 | end |
| 2865 | ar = get fmSt 3 |
| 2866 | if eq ar 1 |
| 2867 | put fmInA 0 0 |
| 2868 | put fmInA 1 1 |
| 2869 | put fmInA 2 2 |
| 2870 | put fmInA 3 5 |
| 2871 | put fmInA 4 12 |
| 2872 | put fmInA 5 35 |
| 2873 | put fmInA 6 120 |
| 2874 | if eq cid 105 |
| 2875 | put fmInA 7 1500 |
| 2876 | else |
| 2877 | put fmInA 7 18 |
| 2878 | end |
| 2879 | end |
| 2880 | if eq ar 2 |
| 2881 | put fmInA 0 0 |
| 2882 | put fmInB 0 0 |
| 2883 | put fmInA 1 3 |
| 2884 | put fmInB 1 7 |
| 2885 | put fmInA 2 9 |
| 2886 | put fmInB 2 2 |
| 2887 | put fmInA 3 5 |
| 2888 | put fmInB 3 5 |
| 2889 | put fmInA 4 10 |
| 2890 | put fmInB 4 25 |
| 2891 | put fmInA 5 40 |
| 2892 | put fmInB 5 12 |
| 2893 | put fmInA 6 1 |
| 2894 | put fmInB 6 10 |
| 2895 | put fmInA 7 24 |
| 2896 | put fmInB 7 9 |
| 2897 | end |
| 2898 | if eq ar 3 |
| 2899 | put fmInA 0 5 |
| 2900 | put fmInB 0 10 |
| 2901 | put fmInC 0 20 |
| 2902 | put fmInA 1 15 |
| 2903 | put fmInB 1 10 |
| 2904 | put fmInC 1 20 |
| 2905 | put fmInA 2 25 |
| 2906 | put fmInB 2 10 |
| 2907 | put fmInC 2 20 |
| 2908 | put fmInA 3 10 |
| 2909 | put fmInB 3 10 |
| 2910 | put fmInC 3 20 |
| 2911 | put fmInA 4 0 |
| 2912 | put fmInB 4 0 |
| 2913 | put fmInC 4 0 |
| 2914 | put fmInA 5 9 |
| 2915 | put fmInB 5 2 |
| 2916 | put fmInC 5 5 |
| 2917 | put fmInA 6 1 |
| 2918 | put fmInB 6 8 |
| 2919 | put fmInC 6 3 |
| 2920 | put fmInA 7 7 |
| 2921 | put fmInB 7 4 |
| 2922 | put fmInC 7 4 |
| 2923 | end |
| 2924 | |
| 2925 | for i ulong 8 bound 8 |
| 2926 | v = ulong 999999999 |
| 2927 | if eq ar 1 |
| 2928 | if lt cid 117 |
| 2929 | v = evalU1 cid get fmInA i |
| 2930 | else |
| 2931 | v = evalU2 cid get fmInA i |
| 2932 | end |
| 2933 | end |
| 2934 | if eq ar 2 |
| 2935 | v = evalBin cid get fmInA i get fmInB i |
| 2936 | end |
| 2937 | if eq ar 3 |
| 2938 | v = evalTern cid get fmInA i get fmInB i get fmInC i |
| 2939 | end |
| 2940 | if eq v 999999999 |
| 2941 | ret false |
| 2942 | end |
| 2943 | put fmP1 i v |
| 2944 | end |
| 2945 | fmEmitScalarSpec cid ar |
| 2946 | ret true |
| 2947 | end |
| 2948 | |
| 2949 | fn fmLoadStr s view uchar * to ulong |
| 2950 | n = len s |
| 2951 | for i ulong n bound 4096 |
| 2952 | put fmBuf i get s i |
| 2953 | end |
| 2954 | ret n |
| 2955 | end |
| 2956 | |
| 2957 | fn checkSelfCase s view uchar * expCid ulong to bool |
| 2958 | n = fmLoadStr s |
| 2959 | fmParsePrompt n |
| 2960 | c = fmPass1 |
| 2961 | if ne c expCid |
| 2962 | ret false |
| 2963 | end |
| 2964 | if eq expCid 0 |
| 2965 | ret true |
| 2966 | end |
| 2967 | ret fmBuildSpec c |
| 2968 | end |
| 2969 | |
| 2970 | fn runSelfcheck to int |
| 2971 | if or fmMultiple 0 0 or fmMultiple 15 0 or not fmMultiple 0 3 or not fmMultiple 15 3 fmMultiple 14 3 |
| 2972 | fwStr 2 tSelfFail |
| 2973 | fwNum 2 8 |
| 2974 | fwStr 2 tNl |
| 2975 | ret 1 |
| 2976 | end |
| 2977 | if not checkSelfCase tTestP1 101 |
| 2978 | fwStr 2 tSelfFail |
| 2979 | fwNum 2 1 |
| 2980 | fwStr 2 tNl |
| 2981 | ret 1 |
| 2982 | end |
| 2983 | if not checkSelfCase tTestP2 201 |
| 2984 | fwStr 2 tSelfFail |
| 2985 | fwNum 2 2 |
| 2986 | fwStr 2 tNl |
| 2987 | ret 1 |
| 2988 | end |
| 2989 | if not checkSelfCase tTestP3 210 |
| 2990 | fwStr 2 tSelfFail |
| 2991 | fwNum 2 3 |
| 2992 | fwStr 2 tNl |
| 2993 | ret 1 |
| 2994 | end |
| 2995 | if not checkSelfCase tTestP4 117 |
| 2996 | fwStr 2 tSelfFail |
| 2997 | fwNum 2 4 |
| 2998 | fwStr 2 tNl |
| 2999 | ret 1 |
| 3000 | end |
| 3001 | if not checkSelfCase tTestP5 415 |
| 3002 | fwStr 2 tSelfFail |
| 3003 | fwNum 2 5 |
| 3004 | fwStr 2 tNl |
| 3005 | ret 1 |
| 3006 | end |
| 3007 | if not checkSelfCase tTestP6 500 |
| 3008 | fwStr 2 tSelfFail |
| 3009 | fwNum 2 6 |
| 3010 | fwStr 2 tNl |
| 3011 | ret 1 |
| 3012 | end |
| 3013 | if not checkSelfCase tTestP7 0 |
| 3014 | fwStr 2 tSelfFail |
| 3015 | fwNum 2 7 |
| 3016 | fwStr 2 tNl |
| 3017 | ret 1 |
| 3018 | end |
| 3019 | fwStr 1 tSelfOk |
| 3020 | ret 0 |
| 3021 | end |
| 3022 | |
| 3023 | fn main to int |
| 3024 | if lt argcnt 2 |
| 3025 | fwStr 2 tUsage |
| 3026 | ret 2 |
| 3027 | end |
| 3028 | mb = new uchar 64 0 |
| 3029 | ml = argread 1 mb 0 64 |
| 3030 | if le ml 0 |
| 3031 | fwStr 2 tUsage |
| 3032 | ret 2 |
| 3033 | end |
| 3034 | if feqTxt mb ulong ml mSelf |
| 3035 | ret runSelfcheck |
| 3036 | end |
| 3037 | if not feqTxt mb ulong ml mForm |
| 3038 | fwStr 2 tUsage |
| 3039 | ret 2 |
| 3040 | end |
| 3041 | if lt argcnt 4 |
| 3042 | fwStr 2 tUsage |
| 3043 | ret 2 |
| 3044 | end |
| 3045 | pl = argread 2 fmPath 0 4095 |
| 3046 | if le pl 0 |
| 3047 | fwStr 2 tErrIo |
| 3048 | ret 1 |
| 3049 | end |
| 3050 | fd = fopen fmPath 0 ulong pl 0 0 |
| 3051 | if lt fd 0 |
| 3052 | fwStr 2 tErrIo |
| 3053 | ret 1 |
| 3054 | end |
| 3055 | kn = read int fd fmBuf 0 16383 |
| 3056 | z = fclose int fd |
| 3057 | if le kn 0 |
| 3058 | fwStr 2 tErrIo |
| 3059 | ret 1 |
| 3060 | end |
| 3061 | fmParsePrompt ulong kn |
| 3062 | cid = fmPass1 |
| 3063 | if eq cid 0 |
| 3064 | fwStr 1 tAbstain |
| 3065 | ret 1 |
| 3066 | end |
| 3067 | if not fmBuildSpec cid |
| 3068 | fwStr 1 tAbstain |
| 3069 | ret 1 |
| 3070 | end |
| 3071 | pl2 = argread 3 fmPath 0 4095 |
| 3072 | if le pl2 0 |
| 3073 | fwStr 2 tErrIo |
| 3074 | ret 1 |
| 3075 | end |
| 3076 | fd2 = fopen fmPath 0 ulong pl2 577 420 |
| 3077 | if lt fd2 0 |
| 3078 | fwStr 2 tErrIo |
| 3079 | ret 1 |
| 3080 | end |
| 3081 | n = get fmSt 10 |
| 3082 | o = ulong 0 |
| 3083 | while lt o n bound 16384 |
| 3084 | k = write int fd2 fmOut o sub n o |
| 3085 | if le k 0 |
| 3086 | break |
| 3087 | end |
| 3088 | o = add o ulong k |
| 3089 | end |
| 3090 | z2 = fclose int fd2 |
| 3091 | fwStr 1 tAgree |
| 3092 | fwNum 1 cid |
| 3093 | fwStr 1 tNl |
| 3094 | ret 0 |
| 3095 | end |