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 / train / omega-llm / tools / bench / bench.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: AGPL-3.0-only |
| 3 | note bench.om: the Omega coding benchmark of Omega LLM. One prompt per behaviour, graded by |
| 4 | note compiling the model's function body and running hidden cases, with no help from the harness: |
| 5 | note one sample at temperature 0, no example filter, and the model has to end its own function. |
| 6 | note |
| 7 | note bench table TASKS OMC WORK print the expectation table of the references |
| 8 | note bench check TASKS EXPECT OMC WORK the table equals EXPECT and no two tasks agree |
| 9 | note bench prompts TASKS WORK write WORK/prompt-ID |
| 10 | note bench sample TASKS WORK OLLM CMD CK [MERGES] WORK/answer-ID = OLLM CMD CK 42 128 0 PROMPT [MERGES] |
| 11 | note bench score TASKS EXPECT OMC WORK [CORPUS] grade WORK/answer-ID |
| 12 | note bench seen TASKS CORPUS tasks whose reference occurs in CORPUS |
| 13 | note |
| 14 | note TASKS (tasks.om) is Omega source. Its `note in1 X`, `note in2 X Y`, `note in3 X Y Z`, `note arr |
| 15 | note v0 .. v7` and `note cnt N` lines are the shared inputs; every task is `note task ID FAMILY`, |
| 16 | note `note say INSTRUCTION` and a reference function `fn tNNN PARAMS` .. `end`. PARAMS is one of |
| 17 | note five shapes: 1 `a ulong to ulong`, 2 `a ulong b ulong to ulong`, 3 `a ulong b ulong c ulong to |
| 18 | note ulong`, 4 `a view ulong 8 n ulong to ulong`, 5 `a edit ulong 8 n ulong to void`. Shapes 1 .. 3 |
| 19 | note run on every in1/in2/in3 line, shapes 4 and 5 on every arr with every cnt; shape 5's result is |
| 20 | note the array afterwards. A row of the table is `ID v v ..`, one row per task in file order. |
| 21 | note The prompt is `note INSTRUCTION`, newline, `fn solve PARAMS`, newline; the answer is what the |
| 22 | note model writes after it. Its body runs to the `end` that closes the function (if, while and for |
| 23 | note open a block). Verdicts: pass (the answer is exactly that body and every case holds), passcut |
| 24 | note (the body passes but text follows it: the model did not stop), wrong (a case fails, a trap, or |
| 25 | note a wrong exit), nocompile, noend (no closing end), refused (the body says exit or trap, which |
| 26 | note could fake the result), missing (no answer file), timeout. The headline counts pass only. |
| 27 | note Lines: `R ID FAMILY VERDICT`, then per family `F FAMILY tasks pass passcut wrong nocompile noend |
| 28 | note refused missing timeout seen`, then `SCORE tasks N pass P passcut C seen K`. A task whose |
| 29 | note reference occurs in CORPUS (same text after renaming its names, `bench seen`) is counted as seen |
| 30 | note and left out of N, P and C: it measures recall, not coding. |
| 31 | note Candidate programs run under execpure (OMEGESE section 10: Landlock, seccomp, no new files or |
| 32 | note processes, CPU and memory ceilings); 127 from it means the sandbox is not available and ends |
| 33 | note the run with exit 70 instead of a verdict. Compiles have a 60 s deadline, runs 10 s. |
| 34 | note Exits: 0 done (check: PASS), 1 check failed, 2 usage, 64 a path or packet too long, 65 TASKS |
| 35 | note malformed (stderr names the byte), 66 EXPECT does not fit TASKS, 70 I/O or sandbox, 71 a |
| 36 | note sample command failed. Paths are at most 4096 bytes (Linux PATH_MAX); every table grows with |
| 37 | note its input. |
| 38 | |
| 39 | text lin1 "note in1 " |
| 40 | text lin2 "note in2 " |
| 41 | text lin3 "note in3 " |
| 42 | text larr "note arr " |
| 43 | text lcnt "note cnt " |
| 44 | text ltask "note task " |
| 45 | text lsay "note say " |
| 46 | text lfn "fn " |
| 47 | text lnote "note" |
| 48 | text twif "if" |
| 49 | text twwhile "while" |
| 50 | text twfor "for" |
| 51 | text twend "end" |
| 52 | text twexit "exit" |
| 53 | text twtrap "trap" |
| 54 | text tweq "=" |
| 55 | text twto "to" |
| 56 | text twview "view" |
| 57 | text twedit "edit" |
| 58 | text sg1 "a ulong to ulong" |
| 59 | text sg2 "a ulong b ulong to ulong" |
| 60 | text sg3 "a ulong b ulong c ulong to ulong" |
| 61 | text sg4 "a view ulong 8 n ulong to ulong" |
| 62 | text sg5 "a edit ulong 8 n ulong to void" |
| 63 | text tnull "/dev/null" |
| 64 | text fpsrc "bench-p.om" |
| 65 | text fpbin "bench-p" |
| 66 | text fpout "bench-out" |
| 67 | text fpprm "prompt-" |
| 68 | text fpans "answer-" |
| 69 | text ctable "table" |
| 70 | text ccheck "check" |
| 71 | text cprompts "prompts" |
| 72 | text csample "sample" |
| 73 | text cscore "score" |
| 74 | text cseen "seen" |
| 75 | text a42 "42" |
| 76 | text a128 "128" |
| 77 | text a0 "0" |
| 78 | text gpre "fn prv v ulong to void\nd = new uchar 24 0\ni = ulong 24\nx = v\nk = true\nwhile k bound 24\ni = sub i 1\nput d i uchar add 48 rem x 10\nx = div x 10\nif eq x 0\nk = false\nend\nend\ni = sub i 1\nput d i 32\nw = write 1 d i sub 24 i\nend\nfn prl to void\nd = new uchar 1 10\nw = write 1 d 0 1\nend\nfn pra a view ulong 8 to void\nfor i ulong 8\nprv get a i\nend\nend\n" |
| 79 | text gfill0 "fn bench_fill a edit ulong 8 k ulong to void\n" |
| 80 | text gifk "if eq k " |
| 81 | text gputa "put a " |
| 82 | text gend "end\n" |
| 83 | text gidt "text id" |
| 84 | text gquo " \"" |
| 85 | text gquoz "\"\n" |
| 86 | text gfn "fn " |
| 87 | text growh "fn row" |
| 88 | text growz " to void\n" |
| 89 | text garr0 "arr = new ulong 8 0\n" |
| 90 | text gwid "w = write 1 id" |
| 91 | text gwid2 " 0 len id" |
| 92 | text gprl "prl\nend\n" |
| 93 | text gprv "prv " |
| 94 | text gsul " ulong " |
| 95 | text gfillc "bench_fill arr ulong " |
| 96 | text garrul " arr ulong " |
| 97 | text gpra "pra arr\n" |
| 98 | text gmain0 "fn main to int\n" |
| 99 | text growc "row" |
| 100 | text gmainz "ret 0\nend\n" |
| 101 | text gsolve "fn solve " |
| 102 | text gifne "if ne solve" |
| 103 | text gifget "if ne get arr " |
| 104 | text gfail "\nret 83\nend\n" |
| 105 | text gret77 "ret 77\nend\n" |
| 106 | text gcall "solve" |
| 107 | text gnote "note " |
| 108 | text epath "bench: a path is over 4096 bytes\n" |
| 109 | text epack "bench: an argument packet is over 65536 bytes\n" |
| 110 | text eio "bench: I/O failure\n" |
| 111 | text eargs "bench: usage: bench table|check|prompts|sample|score|seen ... (see the head of bench.om)\n" |
| 112 | text etask "bench: TASKS malformed at byte " |
| 113 | text eexp "bench: EXPECT does not fit TASKS at task " |
| 114 | text esand "bench: the execpure sandbox is not available here (exit 127 from the candidate)\n" |
| 115 | text ecomp "bench: the references do not compile or run: status " |
| 116 | text msame "SAME_BEHAVIOUR " |
| 117 | text mdiff "EXPECT_DIFFERS\n" |
| 118 | text mpass "CHECK PASS tasks " |
| 119 | text mfail "CHECK FAIL tasks " |
| 120 | text mcase " inputs " |
| 121 | text msep " minsep " |
| 122 | text msfail "SAMPLE_FAIL " |
| 123 | text mscore "SCORE tasks " |
| 124 | text mspass " pass " |
| 125 | text mscut " passcut " |
| 126 | text msseen " seen " |
| 127 | text mseen "SEEN " |
| 128 | text mseens "SEENSUM tasks " |
| 129 | text mseenf " functions " |
| 130 | text v1 "pass" |
| 131 | text v2 "passcut" |
| 132 | text v3 "wrong" |
| 133 | text v4 "nocompile" |
| 134 | text v5 "noend" |
| 135 | text v6 "refused" |
| 136 | text v7 "missing" |
| 137 | text v8 "timeout" |
| 138 | text v9 "seen" |
| 139 | |
| 140 | note mem holds every file read (tasks, expectations, an answer, a corpus, a table) one after the |
| 141 | note other; st[6] is the fill. prog is the program or prompt being generated (st[2] bytes). |
| 142 | note tk has 16 words per task: 0 id, 1 its length, 2 family, 3 length, 4 instruction, 5 length, |
| 143 | note 6 params, 7 length, 8 body, 9 length (through the closing end, no newline), 10 shape, 11 the |
| 144 | note reference's name, 12 length, 13 normal form in nrm, 14 length, 15 verdict or seen mark. |
| 145 | note inp has 3 words per input line: kind (1 .. 3 scalar shapes, 4 arr, 5 cnt), text, length. |
| 146 | note nrm holds normal forms (st[24] bytes), nmt the (offset, length) names of the function being |
| 147 | note normalised (st[25] names). |
| 148 | note st: 0 tasks, 1 input lines, 2 prog bytes, 3 path bytes, 4 packet bytes, 5 stdout bytes, 6 mem |
| 149 | note fill, 7 packet records, 8 9 pending instruction, 10 11 pending id, 12 13 pending family, 14 |
| 150 | note task pending, 15 arr lines, 16 cnt lines, 17 18 19 in1 in2 in3 lines, 26 WORK argument, 27 OMC |
| 151 | note argument, 28 29 the expectation cursor and its row end. |
| 152 | global mem uchar * |
| 153 | global prog uchar * |
| 154 | global tk ulong * |
| 155 | global inp ulong * |
| 156 | global nrm uchar * |
| 157 | global nmt ulong * |
| 158 | global st ulong 32 |
| 159 | global pth uchar 4096 |
| 160 | global pk uchar 65536 |
| 161 | global wst uchar 4 |
| 162 | global ob uchar 65536 |
| 163 | global dg uchar 24 |
| 164 | |
| 165 | note ======== stdout, stderr |
| 166 | |
| 167 | fn oflush to void |
| 168 | n = get st 5 |
| 169 | if gt n 0 |
| 170 | w = write 1 ob 0 n |
| 171 | put st 5 0 |
| 172 | end |
| 173 | end |
| 174 | |
| 175 | fn oc c ulong to void |
| 176 | n = get st 5 |
| 177 | if ge n 65536 |
| 178 | oflush |
| 179 | n = 0 |
| 180 | end |
| 181 | put ob n uchar c |
| 182 | put st 5 add n 1 |
| 183 | end |
| 184 | |
| 185 | fn ot t view uchar * to void |
| 186 | for i ulong len t bound 9223372036854775807 |
| 187 | oc ulong get t i |
| 188 | end |
| 189 | end |
| 190 | |
| 191 | fn omem o ulong n ulong to void |
| 192 | for i ulong n bound 9223372036854775807 |
| 193 | oc ulong get mem add o i |
| 194 | end |
| 195 | end |
| 196 | |
| 197 | note v in decimal into dg; the index of its first digit (digits end at 24) |
| 198 | fn udec v ulong to ulong |
| 199 | i = ulong 24 |
| 200 | x = v |
| 201 | k = true |
| 202 | while k bound 24 |
| 203 | i = sub i 1 |
| 204 | put dg i uchar add 48 rem x 10 |
| 205 | x = div x 10 |
| 206 | if eq x 0 |
| 207 | k = false |
| 208 | end |
| 209 | end |
| 210 | ret i |
| 211 | end |
| 212 | |
| 213 | fn ou v ulong to void |
| 214 | i = udec v |
| 215 | while lt i 24 bound 24 |
| 216 | oc ulong get dg i |
| 217 | i = add i 1 |
| 218 | end |
| 219 | end |
| 220 | |
| 221 | note message t on stderr, then exit c |
| 222 | fn die t view uchar * c int to void |
| 223 | oflush |
| 224 | w = write 2 t 0 len t |
| 225 | exit c |
| 226 | end |
| 227 | |
| 228 | note message t, the number v and a newline on stderr, then exit c |
| 229 | fn dien t view uchar * v ulong c int to void |
| 230 | oflush |
| 231 | w = write 2 t 0 len t |
| 232 | i = udec v |
| 233 | w = write 2 dg i sub 24 i |
| 234 | put dg 0 10 |
| 235 | w = write 2 dg 0 1 |
| 236 | exit c |
| 237 | end |
| 238 | |
| 239 | note ======== paths and files |
| 240 | |
| 241 | fn pclr to void |
| 242 | put st 3 0 |
| 243 | end |
| 244 | |
| 245 | fn pch c ulong to void |
| 246 | n = get st 3 |
| 247 | if ge n 4096 |
| 248 | die epath 64 |
| 249 | end |
| 250 | put pth n uchar c |
| 251 | put st 3 add n 1 |
| 252 | end |
| 253 | |
| 254 | fn ptx t view uchar * to void |
| 255 | for i ulong len t |
| 256 | pch ulong get t i |
| 257 | end |
| 258 | end |
| 259 | |
| 260 | note argument i onto the path |
| 261 | fn parg i ulong to void |
| 262 | n = get st 3 |
| 263 | r = argread i pth n sub 4096 n |
| 264 | if lt r 0 |
| 265 | die eargs 2 |
| 266 | end |
| 267 | put st 3 add n ulong r |
| 268 | end |
| 269 | |
| 270 | note the path WORK/t |
| 271 | fn wpath t view uchar * to void |
| 272 | pclr |
| 273 | parg get st 26 |
| 274 | pch 47 |
| 275 | ptx t |
| 276 | end |
| 277 | |
| 278 | note the path WORK/t followed by task i's id |
| 279 | fn wpid t view uchar * i ulong to void |
| 280 | wpath t |
| 281 | o = tfd i 0 |
| 282 | for j ulong tfd i 1 bound 4096 |
| 283 | pch ulong get mem add o j |
| 284 | end |
| 285 | end |
| 286 | |
| 287 | note the file at the path into mem at the fill; its length, or 2^64 - 1 when it cannot be opened |
| 288 | fn fload to ulong |
| 289 | fd = fopen pth 0 get st 3 0 0 |
| 290 | if lt fd 0 |
| 291 | ret 18446744073709551615 |
| 292 | end |
| 293 | sz = fseek int fd 0 2 |
| 294 | if lt sz 0 |
| 295 | die eio 70 |
| 296 | end |
| 297 | z = fseek int fd 0 0 |
| 298 | b = get st 6 |
| 299 | e = add b ulong sz |
| 300 | r = enlarge mem add e 1 |
| 301 | if lt r 0 |
| 302 | die eio 70 |
| 303 | end |
| 304 | o = b |
| 305 | while lt o e bound 9223372036854775807 |
| 306 | k = read int fd mem o sub e o |
| 307 | if le k 0 |
| 308 | die eio 70 |
| 309 | end |
| 310 | o = add o ulong k |
| 311 | end |
| 312 | z = fclose int fd |
| 313 | put st 6 e |
| 314 | ret ulong sz |
| 315 | end |
| 316 | |
| 317 | note argument i's file into mem; its offset (the length is the new fill minus it) |
| 318 | fn aload i ulong to ulong |
| 319 | pclr |
| 320 | parg i |
| 321 | b = get st 6 |
| 322 | if eq fload 18446744073709551615 |
| 323 | die eio 70 |
| 324 | end |
| 325 | ret b |
| 326 | end |
| 327 | |
| 328 | note the path opened for reading, or created and emptied with mode md when wr |
| 329 | fn popen wr bool md int to int |
| 330 | r = long 0 |
| 331 | if wr |
| 332 | r = fopen pth 0 get st 3 577 md |
| 333 | else |
| 334 | r = fopen pth 0 get st 3 0 0 |
| 335 | end |
| 336 | if lt r 0 |
| 337 | die eio 70 |
| 338 | end |
| 339 | ret int r |
| 340 | end |
| 341 | |
| 342 | note prog[0, st2) into the path, created with mode md |
| 343 | fn fsave md int to void |
| 344 | fd = popen true md |
| 345 | n = get st 2 |
| 346 | o = ulong 0 |
| 347 | while lt o n bound 9223372036854775807 |
| 348 | k = write fd prog o sub n o |
| 349 | if le k 0 |
| 350 | die eio 70 |
| 351 | end |
| 352 | o = add o ulong k |
| 353 | end |
| 354 | z = fclose fd |
| 355 | end |
| 356 | |
| 357 | note ======== the generated text |
| 358 | |
| 359 | fn gc c ulong to void |
| 360 | n = get st 2 |
| 361 | if ge n len prog |
| 362 | r = enlarge prog add mul n 2 4096 |
| 363 | if lt r 0 |
| 364 | die eio 70 |
| 365 | end |
| 366 | end |
| 367 | put prog n uchar c |
| 368 | put st 2 add n 1 |
| 369 | end |
| 370 | |
| 371 | fn gtx t view uchar * to void |
| 372 | for i ulong len t bound 9223372036854775807 |
| 373 | gc ulong get t i |
| 374 | end |
| 375 | end |
| 376 | |
| 377 | fn gmem o ulong n ulong to void |
| 378 | for i ulong n bound 9223372036854775807 |
| 379 | gc ulong get mem add o i |
| 380 | end |
| 381 | end |
| 382 | |
| 383 | fn gu v ulong to void |
| 384 | i = udec v |
| 385 | while lt i 24 bound 24 |
| 386 | gc ulong get dg i |
| 387 | i = add i 1 |
| 388 | end |
| 389 | end |
| 390 | |
| 391 | note ======== processes |
| 392 | |
| 393 | fn kclr to void |
| 394 | put st 4 2 |
| 395 | put st 7 0 |
| 396 | end |
| 397 | |
| 398 | fn kb c ulong to void |
| 399 | n = get st 4 |
| 400 | if ge n 65536 |
| 401 | die epack 64 |
| 402 | end |
| 403 | put pk n uchar c |
| 404 | put st 4 add n 1 |
| 405 | end |
| 406 | |
| 407 | note start a record of n bytes |
| 408 | fn krec n ulong to void |
| 409 | if gt n 65535 |
| 410 | die epack 64 |
| 411 | end |
| 412 | kb and n 255 |
| 413 | kb shr n 8 |
| 414 | put st 7 add get st 7 1 |
| 415 | end |
| 416 | |
| 417 | note the path as the next record |
| 418 | fn kpath to void |
| 419 | n = get st 3 |
| 420 | krec n |
| 421 | for i ulong n bound 4096 |
| 422 | kb ulong get pth i |
| 423 | end |
| 424 | end |
| 425 | |
| 426 | fn ktx t view uchar * to void |
| 427 | krec len t |
| 428 | for i ulong len t |
| 429 | kb ulong get t i |
| 430 | end |
| 431 | end |
| 432 | |
| 433 | note argument i as the next record |
| 434 | fn karg i ulong to void |
| 435 | pclr |
| 436 | parg i |
| 437 | kpath |
| 438 | end |
| 439 | |
| 440 | note prog[0, st2) as the next record |
| 441 | fn kprog to void |
| 442 | n = get st 2 |
| 443 | krec n |
| 444 | for i ulong n bound 65536 |
| 445 | kb ulong get prog i |
| 446 | end |
| 447 | end |
| 448 | |
| 449 | fn kfin to void |
| 450 | n = get st 7 |
| 451 | put pk 0 uchar and n 255 |
| 452 | put pk 1 uchar shr n 8 |
| 453 | end |
| 454 | |
| 455 | note the child: fi is stdin, fo stdout, stderr /dev/null; pure runs the packet under execpure |
| 456 | fn child fi int fo int pure bool to void |
| 457 | r = dupfd fi 0 0 |
| 458 | r = dupfd fo 1 0 |
| 459 | fd = fopen tnull 0 len tnull 1 0 |
| 460 | if ge fd 0 |
| 461 | r = dupfd int fd 2 0 |
| 462 | end |
| 463 | if pure |
| 464 | r = execpure pk 0 get st 4 |
| 465 | else |
| 466 | r = execprog pk 0 get st 4 |
| 467 | end |
| 468 | exit 127 |
| 469 | end |
| 470 | |
| 471 | fn spawn fi int fo int pure bool to long |
| 472 | kfin |
| 473 | pid = fork |
| 474 | if lt pid 0 |
| 475 | die eio 70 |
| 476 | end |
| 477 | if eq pid 0 |
| 478 | child fi fo pure |
| 479 | end |
| 480 | ret pid |
| 481 | end |
| 482 | |
| 483 | note wait for pid at most ms milliseconds: its exit status, 256 + the signal that ended it, or |
| 484 | note 1000 when the deadline passed and it was killed |
| 485 | fn waitp pid long ms ulong to long |
| 486 | dl = add ulong monons mul ms 1000000 |
| 487 | w = long 0 |
| 488 | while eq w 0 bound 9223372036854775807 |
| 489 | w = waitpid int pid wst 0 4 1 |
| 490 | if eq w 0 |
| 491 | if ge ulong monons dl |
| 492 | r = killpid int pid 9 |
| 493 | w = waitpid int pid wst 0 4 0 |
| 494 | ret 1000 |
| 495 | end |
| 496 | r = sleepns 500000 |
| 497 | end |
| 498 | end |
| 499 | if lt w 0 |
| 500 | die eio 70 |
| 501 | end |
| 502 | sig = and ulong get wst 0 127 |
| 503 | if ne sig 0 |
| 504 | ret long add 256 sig |
| 505 | end |
| 506 | ret long get wst 1 |
| 507 | end |
| 508 | |
| 509 | note compile WORK/bench-p.om (prog, saved here) into WORK/bench-p; the compiler's status |
| 510 | fn compile to long |
| 511 | wpath fpsrc |
| 512 | fsave 420 |
| 513 | fi = popen false 0 |
| 514 | wpath fpbin |
| 515 | fo = popen true 493 |
| 516 | kclr |
| 517 | karg get st 27 |
| 518 | pid = spawn fi fo false |
| 519 | z = fclose fi |
| 520 | z = fclose fo |
| 521 | ret waitp pid 60000 |
| 522 | end |
| 523 | |
| 524 | note run WORK/bench-p under execpure, stdout into WORK/bench-out when tofile; its status |
| 525 | fn runp tofile bool to long |
| 526 | pclr |
| 527 | ptx tnull |
| 528 | fi = popen false 0 |
| 529 | fo = int 0 |
| 530 | if tofile |
| 531 | wpath fpout |
| 532 | fo = popen true 420 |
| 533 | else |
| 534 | r = fopen pth 0 get st 3 1 0 |
| 535 | if lt r 0 |
| 536 | die eio 70 |
| 537 | end |
| 538 | fo = int r |
| 539 | end |
| 540 | wpath fpbin |
| 541 | kclr |
| 542 | kpath |
| 543 | pid = spawn fi fo true |
| 544 | z = fclose fi |
| 545 | z = fclose fo |
| 546 | s = waitp pid 10000 |
| 547 | if eq s 127 |
| 548 | die esand 70 |
| 549 | end |
| 550 | ret s |
| 551 | end |
| 552 | |
| 553 | note ======== reading TASKS |
| 554 | |
| 555 | note the newline that ends the line at p, or e |
| 556 | fn lend p ulong e ulong to ulong |
| 557 | q = p |
| 558 | while lt q e bound 9223372036854775807 |
| 559 | if eq get mem q 10 |
| 560 | ret q |
| 561 | end |
| 562 | q = add q 1 |
| 563 | end |
| 564 | ret e |
| 565 | end |
| 566 | |
| 567 | note the end of the word at p: the next space, tab or e |
| 568 | fn wordend p ulong e ulong to ulong |
| 569 | q = p |
| 570 | while lt q e bound 9223372036854775807 |
| 571 | c = get mem q |
| 572 | if or eq c 32 eq c 9 |
| 573 | ret q |
| 574 | end |
| 575 | q = add q 1 |
| 576 | end |
| 577 | ret e |
| 578 | end |
| 579 | |
| 580 | note p moved over spaces and tabs, not past e |
| 581 | fn skipsp p ulong e ulong to ulong |
| 582 | q = p |
| 583 | while lt q e bound 9223372036854775807 |
| 584 | c = get mem q |
| 585 | if and ne c 32 ne c 9 |
| 586 | ret q |
| 587 | end |
| 588 | q = add q 1 |
| 589 | end |
| 590 | ret e |
| 591 | end |
| 592 | |
| 593 | note whether mem[p, e) starts with t |
| 594 | fn sw p ulong e ulong t view uchar * to bool |
| 595 | n = len t |
| 596 | if gt add p n e |
| 597 | ret false |
| 598 | end |
| 599 | for i ulong n |
| 600 | if ne get mem add p i get t i |
| 601 | ret false |
| 602 | end |
| 603 | end |
| 604 | ret true |
| 605 | end |
| 606 | |
| 607 | note whether mem[p, e) is exactly t |
| 608 | fn meq p ulong e ulong t view uchar * to bool |
| 609 | if ne sub e p len t |
| 610 | ret false |
| 611 | end |
| 612 | ret sw p e t |
| 613 | end |
| 614 | |
| 615 | note whether mem[a, a + n) equals mem[b, b + m) |
| 616 | fn mm a ulong n ulong b ulong m ulong to bool |
| 617 | if ne n m |
| 618 | ret false |
| 619 | end |
| 620 | for i ulong n bound 9223372036854775807 |
| 621 | if ne get mem add a i get mem add b i |
| 622 | ret false |
| 623 | end |
| 624 | end |
| 625 | ret true |
| 626 | end |
| 627 | |
| 628 | fn bad p ulong to void |
| 629 | dien etask p 65 |
| 630 | end |
| 631 | |
| 632 | note the decimal number mem[p, e) (1 to 20 digits) |
| 633 | fn dec p ulong e ulong to ulong |
| 634 | if or ge p e gt sub e p 20 |
| 635 | bad p |
| 636 | end |
| 637 | v = ulong 0 |
| 638 | q = p |
| 639 | while lt q e bound 20 |
| 640 | c = ulong get mem q |
| 641 | if or lt c 48 gt c 57 |
| 642 | bad p |
| 643 | end |
| 644 | v = add mul v 10 sub c 48 |
| 645 | q = add q 1 |
| 646 | end |
| 647 | ret v |
| 648 | end |
| 649 | |
| 650 | note the number of words in mem[p, e), each a decimal number |
| 651 | fn nwords p ulong e ulong to ulong |
| 652 | n = ulong 0 |
| 653 | q = skipsp p e |
| 654 | while lt q e bound 9223372036854775807 |
| 655 | w = wordend q e |
| 656 | x = dec q w |
| 657 | n = add n 1 |
| 658 | q = skipsp w e |
| 659 | end |
| 660 | ret n |
| 661 | end |
| 662 | |
| 663 | fn tfd i ulong k ulong to ulong |
| 664 | ret get tk add mul i 16 k |
| 665 | end |
| 666 | |
| 667 | fn tput i ulong k ulong v ulong to void |
| 668 | put tk add mul i 16 k v |
| 669 | end |
| 670 | |
| 671 | fn ifd r ulong k ulong to ulong |
| 672 | ret get inp add mul r 3 k |
| 673 | end |
| 674 | |
| 675 | note an input line of kind k with text mem[o, e): its word count must fit the kind |
| 676 | fn addinp k ulong o ulong e ulong to void |
| 677 | want = k |
| 678 | if eq k 4 |
| 679 | want = 8 |
| 680 | end |
| 681 | if eq k 5 |
| 682 | want = 1 |
| 683 | end |
| 684 | if ne nwords o e want |
| 685 | bad o |
| 686 | end |
| 687 | n = get st 1 |
| 688 | r = enlarge inp mul add n 1 3 |
| 689 | if lt r 0 |
| 690 | die eio 70 |
| 691 | end |
| 692 | b = mul n 3 |
| 693 | put inp b k |
| 694 | put inp add b 1 o |
| 695 | put inp add b 2 sub e o |
| 696 | put st 1 add n 1 |
| 697 | if le k 3 |
| 698 | put st add 16 k add get st add 16 k 1 |
| 699 | end |
| 700 | if eq k 4 |
| 701 | put st 15 add get st 15 1 |
| 702 | end |
| 703 | if eq k 5 |
| 704 | put st 16 add get st 16 1 |
| 705 | end |
| 706 | end |
| 707 | |
| 708 | note the record of the j-th input line of kind k |
| 709 | fn inth k ulong j ulong to ulong |
| 710 | c = ulong 0 |
| 711 | for r ulong get st 1 bound 9223372036854775807 |
| 712 | if eq ifd r 0 k |
| 713 | if eq c j |
| 714 | ret r |
| 715 | end |
| 716 | c = add c 1 |
| 717 | end |
| 718 | end |
| 719 | die eio 70 |
| 720 | ret 0 |
| 721 | end |
| 722 | |
| 723 | note the kind of the line mem[p, q): 1 .. 5 an input, 6 task, 7 say, 8 a function, 0 other |
| 724 | fn lkind p ulong q ulong to ulong |
| 725 | if sw p q lin1 |
| 726 | ret 1 |
| 727 | end |
| 728 | if sw p q lin2 |
| 729 | ret 2 |
| 730 | end |
| 731 | if sw p q lin3 |
| 732 | ret 3 |
| 733 | end |
| 734 | if sw p q larr |
| 735 | ret 4 |
| 736 | end |
| 737 | if sw p q lcnt |
| 738 | ret 5 |
| 739 | end |
| 740 | if sw p q ltask |
| 741 | ret 6 |
| 742 | end |
| 743 | if sw p q lsay |
| 744 | ret 7 |
| 745 | end |
| 746 | if sw p q lfn |
| 747 | ret 8 |
| 748 | end |
| 749 | ret 0 |
| 750 | end |
| 751 | |
| 752 | note whether the first word of the line mem[p, q) is t |
| 753 | fn fw p ulong q ulong t view uchar * to bool |
| 754 | a = skipsp p q |
| 755 | ret meq a wordend a q t |
| 756 | end |
| 757 | |
| 758 | note one past the line end of the `end` that closes the function whose body starts at b (so the |
| 759 | note result minus 1 is that line's newline, or e), 0 when it is not closed before e |
| 760 | fn bodyend b ulong e ulong to ulong |
| 761 | d = ulong 1 |
| 762 | p = b |
| 763 | while lt p e bound 9223372036854775807 |
| 764 | q = lend p e |
| 765 | if or fw p q twif or fw p q twwhile fw p q twfor |
| 766 | d = add d 1 |
| 767 | end |
| 768 | if fw p q twend |
| 769 | d = sub d 1 |
| 770 | if eq d 0 |
| 771 | ret add q 1 |
| 772 | end |
| 773 | end |
| 774 | p = add q 1 |
| 775 | end |
| 776 | ret 0 |
| 777 | end |
| 778 | |
| 779 | note the shape of the params mem[o, q) |
| 780 | fn shapeof o ulong q ulong to ulong |
| 781 | if meq o q sg1 |
| 782 | ret 1 |
| 783 | end |
| 784 | if meq o q sg2 |
| 785 | ret 2 |
| 786 | end |
| 787 | if meq o q sg3 |
| 788 | ret 3 |
| 789 | end |
| 790 | if meq o q sg4 |
| 791 | ret 4 |
| 792 | end |
| 793 | if meq o q sg5 |
| 794 | ret 5 |
| 795 | end |
| 796 | bad o |
| 797 | ret 0 |
| 798 | end |
| 799 | |
| 800 | note `note task ID FAMILY` at mem[p, q) |
| 801 | fn ptask p ulong q ulong to void |
| 802 | w = wordend p q |
| 803 | if or eq w p ge add w 1 q |
| 804 | bad p |
| 805 | end |
| 806 | put st 10 p |
| 807 | put st 11 sub w p |
| 808 | put st 12 add w 1 |
| 809 | put st 13 sub q add w 1 |
| 810 | put st 14 1 |
| 811 | put st 9 0 |
| 812 | end |
| 813 | |
| 814 | note the reference function whose `fn ` is at p, its line ending at q: a task; the newline (or |
| 815 | note e) that ends its closing end |
| 816 | fn pfn p ulong q ulong e ulong to ulong |
| 817 | if or eq get st 14 0 eq get st 9 0 |
| 818 | bad p |
| 819 | end |
| 820 | nm = add p 3 |
| 821 | w = wordend nm q |
| 822 | if or ge w q ne get mem nm 116 |
| 823 | bad p |
| 824 | end |
| 825 | z = bodyend add q 1 e |
| 826 | if eq z 0 |
| 827 | bad p |
| 828 | end |
| 829 | n = get st 0 |
| 830 | r = enlarge tk mul add n 1 16 |
| 831 | if lt r 0 |
| 832 | die eio 70 |
| 833 | end |
| 834 | pfn2 n nm w q |
| 835 | tput n 9 sub sub z 1 add q 1 |
| 836 | put st 0 add n 1 |
| 837 | put st 14 0 |
| 838 | ret sub z 1 |
| 839 | end |
| 840 | |
| 841 | fn pfn2 n ulong nm ulong w ulong q ulong to void |
| 842 | tput n 0 get st 10 |
| 843 | tput n 1 get st 11 |
| 844 | tput n 2 get st 12 |
| 845 | tput n 3 get st 13 |
| 846 | tput n 4 get st 8 |
| 847 | tput n 5 get st 9 |
| 848 | tput n 6 add w 1 |
| 849 | tput n 7 sub q add w 1 |
| 850 | tput n 8 add q 1 |
| 851 | tput n 10 shapeof add w 1 q |
| 852 | tput n 11 nm |
| 853 | tput n 12 sub w nm |
| 854 | tput n 15 0 |
| 855 | end |
| 856 | |
| 857 | note TASKS at mem[b, e) into tk and inp |
| 858 | fn parse b ulong e ulong to void |
| 859 | p = b |
| 860 | while lt p e bound 9223372036854775807 |
| 861 | q = lend p e |
| 862 | k = lkind p q |
| 863 | if and ge k 1 le k 5 |
| 864 | addinp k add p 9 q |
| 865 | end |
| 866 | if eq k 6 |
| 867 | ptask add p 10 q |
| 868 | end |
| 869 | if eq k 7 |
| 870 | put st 8 add p 9 |
| 871 | put st 9 sub q add p 9 |
| 872 | end |
| 873 | if eq k 8 |
| 874 | q = pfn p q e |
| 875 | end |
| 876 | p = add q 1 |
| 877 | end |
| 878 | if or eq get st 0 0 eq get st 14 1 |
| 879 | bad e |
| 880 | end |
| 881 | end |
| 882 | |
| 883 | note argument i as TASKS |
| 884 | fn ltasks i ulong to void |
| 885 | b = aload i |
| 886 | parse b get st 6 |
| 887 | end |
| 888 | |
| 889 | note the cases of shape sh |
| 890 | fn ncases sh ulong to ulong |
| 891 | if le sh 3 |
| 892 | ret get st add 16 sh |
| 893 | end |
| 894 | ret mul get st 15 get st 16 |
| 895 | end |
| 896 | |
| 897 | note ======== generated programs |
| 898 | |
| 899 | note ` ulong X` for every word X of mem[o, o + n) |
| 900 | fn gargs o ulong n ulong to void |
| 901 | e = add o n |
| 902 | p = skipsp o e |
| 903 | while lt p e bound 9223372036854775807 |
| 904 | w = wordend p e |
| 905 | gtx gsul |
| 906 | gmem p sub w p |
| 907 | p = skipsp w e |
| 908 | end |
| 909 | end |
| 910 | |
| 911 | note the eight puts of arr line mem[o, o + n) |
| 912 | fn gfillr o ulong n ulong to void |
| 913 | e = add o n |
| 914 | p = skipsp o e |
| 915 | for i ulong 8 |
| 916 | w = wordend p e |
| 917 | gtx gputa |
| 918 | gu i |
| 919 | gc 32 |
| 920 | gmem p sub w p |
| 921 | gc 10 |
| 922 | p = skipsp w e |
| 923 | end |
| 924 | end |
| 925 | |
| 926 | note bench_fill: array k of the arr lines into a |
| 927 | fn gfill to void |
| 928 | gtx gfill0 |
| 929 | for j ulong get st 15 bound 9223372036854775807 |
| 930 | r = inth 4 j |
| 931 | gtx gifk |
| 932 | gu j |
| 933 | gc 10 |
| 934 | gfillr ifd r 1 ifd r 2 |
| 935 | gtx gend |
| 936 | end |
| 937 | gtx gend |
| 938 | end |
| 939 | |
| 940 | note the scalar rows of task i (shape sh) for the table |
| 941 | fn growsc i ulong sh ulong to void |
| 942 | for j ulong ncases sh bound 9223372036854775807 |
| 943 | r = inth sh j |
| 944 | gtx gprv |
| 945 | gmem tfd i 11 tfd i 12 |
| 946 | gargs ifd r 1 ifd r 2 |
| 947 | gc 10 |
| 948 | end |
| 949 | end |
| 950 | |
| 951 | note one array case of task i for the table: arr line a, cnt record rc |
| 952 | fn growa1 i ulong sh ulong a ulong rc ulong to void |
| 953 | gtx gfillc |
| 954 | gu a |
| 955 | gc 10 |
| 956 | if eq sh 4 |
| 957 | gtx gprv |
| 958 | end |
| 959 | gmem tfd i 11 tfd i 12 |
| 960 | gtx garrul |
| 961 | gmem ifd rc 1 ifd rc 2 |
| 962 | gc 10 |
| 963 | if eq sh 5 |
| 964 | gtx gpra |
| 965 | end |
| 966 | end |
| 967 | |
| 968 | fn growar i ulong sh ulong to void |
| 969 | for a ulong get st 15 bound 9223372036854775807 |
| 970 | for c ulong get st 16 bound 9223372036854775807 |
| 971 | growa1 i sh a inth 5 c |
| 972 | end |
| 973 | end |
| 974 | end |
| 975 | |
| 976 | note `fn rowN to void`: task i's row of the table |
| 977 | fn growfn i ulong to void |
| 978 | sh = tfd i 10 |
| 979 | gtx growh |
| 980 | gu i |
| 981 | gtx growz |
| 982 | if ge sh 4 |
| 983 | gtx garr0 |
| 984 | end |
| 985 | gtx gwid |
| 986 | gu i |
| 987 | gtx gwid2 |
| 988 | gu i |
| 989 | gc 10 |
| 990 | if le sh 3 |
| 991 | growsc i sh |
| 992 | else |
| 993 | growar i sh |
| 994 | end |
| 995 | gtx gprl |
| 996 | end |
| 997 | |
| 998 | note the table program: every reference, one row function each, main calls them in order |
| 999 | fn gtable to void |
| 1000 | put st 2 0 |
| 1001 | gtx gpre |
| 1002 | gfill |
| 1003 | nt = get st 0 |
| 1004 | for i ulong nt bound 9223372036854775807 |
| 1005 | gtx gidt |
| 1006 | gu i |
| 1007 | gtx gquo |
| 1008 | gmem tfd i 0 tfd i 1 |
| 1009 | gtx gquoz |
| 1010 | end |
| 1011 | for j ulong nt bound 9223372036854775807 |
| 1012 | gtx gfn |
| 1013 | gmem tfd j 11 add add tfd j 12 1 tfd j 7 |
| 1014 | gc 10 |
| 1015 | gmem tfd j 8 tfd j 9 |
| 1016 | gc 10 |
| 1017 | growfn j |
| 1018 | end |
| 1019 | gtx gmain0 |
| 1020 | for k ulong nt bound 9223372036854775807 |
| 1021 | gtx growc |
| 1022 | gu k |
| 1023 | gc 10 |
| 1024 | end |
| 1025 | gtx gmainz |
| 1026 | end |
| 1027 | |
| 1028 | note the next expected value of the row at the cursor |
| 1029 | fn gexp i ulong to void |
| 1030 | p = get st 28 |
| 1031 | e = get st 29 |
| 1032 | if ge p e |
| 1033 | dien eexp i 66 |
| 1034 | end |
| 1035 | w = wordend p e |
| 1036 | gmem p sub w p |
| 1037 | put st 28 skipsp w e |
| 1038 | end |
| 1039 | |
| 1040 | note the scalar cases of task i for the score program |
| 1041 | fn gscsc i ulong sh ulong to void |
| 1042 | for j ulong ncases sh bound 9223372036854775807 |
| 1043 | r = inth sh j |
| 1044 | gtx gifne |
| 1045 | gargs ifd r 1 ifd r 2 |
| 1046 | gtx gsul |
| 1047 | gexp i |
| 1048 | gtx gfail |
| 1049 | end |
| 1050 | end |
| 1051 | |
| 1052 | note one array case of task i for the score program |
| 1053 | fn gsca1 i ulong sh ulong a ulong rc ulong to void |
| 1054 | gtx gfillc |
| 1055 | gu a |
| 1056 | gc 10 |
| 1057 | if eq sh 4 |
| 1058 | gtx gifne |
| 1059 | gtx garrul |
| 1060 | gmem ifd rc 1 ifd rc 2 |
| 1061 | gtx gsul |
| 1062 | gexp i |
| 1063 | gtx gfail |
| 1064 | ret |
| 1065 | end |
| 1066 | gtx gcall |
| 1067 | gtx garrul |
| 1068 | gmem ifd rc 1 ifd rc 2 |
| 1069 | gc 10 |
| 1070 | for x ulong 8 |
| 1071 | gtx gifget |
| 1072 | gu x |
| 1073 | gtx gsul |
| 1074 | gexp i |
| 1075 | gtx gfail |
| 1076 | end |
| 1077 | end |
| 1078 | |
| 1079 | fn gscar i ulong sh ulong to void |
| 1080 | for a ulong get st 15 bound 9223372036854775807 |
| 1081 | for c ulong get st 16 bound 9223372036854775807 |
| 1082 | gsca1 i sh a inth 5 c |
| 1083 | end |
| 1084 | end |
| 1085 | end |
| 1086 | |
| 1087 | note the score program of task i with the answer body mem[bo, bo + bn); the expectation cursor is |
| 1088 | note on the task's row |
| 1089 | fn gscore i ulong bo ulong bn ulong to void |
| 1090 | put st 2 0 |
| 1091 | sh = tfd i 10 |
| 1092 | if ge sh 4 |
| 1093 | gfill |
| 1094 | end |
| 1095 | gtx gsolve |
| 1096 | gmem tfd i 6 tfd i 7 |
| 1097 | gc 10 |
| 1098 | gmem bo bn |
| 1099 | gc 10 |
| 1100 | gtx gmain0 |
| 1101 | if ge sh 4 |
| 1102 | gtx garr0 |
| 1103 | end |
| 1104 | if le sh 3 |
| 1105 | gscsc i sh |
| 1106 | else |
| 1107 | gscar i sh |
| 1108 | end |
| 1109 | if ne get st 28 get st 29 |
| 1110 | dien eexp i 66 |
| 1111 | end |
| 1112 | gtx gret77 |
| 1113 | end |
| 1114 | |
| 1115 | note the prompt of task i into prog |
| 1116 | fn gprompt i ulong to void |
| 1117 | put st 2 0 |
| 1118 | gtx gnote |
| 1119 | gmem tfd i 4 tfd i 5 |
| 1120 | gc 10 |
| 1121 | gtx gsolve |
| 1122 | gmem tfd i 6 tfd i 7 |
| 1123 | gc 10 |
| 1124 | end |
| 1125 | |
| 1126 | note ======== table and check |
| 1127 | |
| 1128 | note build and run the table program; the table's offset in mem (it ends at the fill) |
| 1129 | fn mktable to ulong |
| 1130 | gtable |
| 1131 | s = compile |
| 1132 | if ne s 0 |
| 1133 | dien ecomp ulong s 1 |
| 1134 | end |
| 1135 | s = runp true |
| 1136 | if ne s 0 |
| 1137 | dien ecomp ulong s 1 |
| 1138 | end |
| 1139 | wpath fpout |
| 1140 | b = get st 6 |
| 1141 | if eq fload 18446744073709551615 |
| 1142 | die eio 70 |
| 1143 | end |
| 1144 | ret b |
| 1145 | end |
| 1146 | |
| 1147 | fn cmdtable to void |
| 1148 | if ne argcnt 5 |
| 1149 | die eargs 2 |
| 1150 | end |
| 1151 | put st 27 3 |
| 1152 | put st 26 4 |
| 1153 | ltasks 2 |
| 1154 | b = mktable |
| 1155 | omem b sub get st 6 b |
| 1156 | oflush |
| 1157 | end |
| 1158 | |
| 1159 | note the fields in which the rows mem[a, ae) and mem[b, be) differ (both start after their id) |
| 1160 | fn rowdiff a ulong ae ulong b ulong be ulong to ulong |
| 1161 | n = ulong 0 |
| 1162 | p = skipsp a ae |
| 1163 | q = skipsp b be |
| 1164 | while and lt p ae lt q be bound 9223372036854775807 |
| 1165 | w = wordend p ae |
| 1166 | x = wordend q be |
| 1167 | if not mm p sub w p q sub x q |
| 1168 | n = add n 1 |
| 1169 | end |
| 1170 | p = skipsp w ae |
| 1171 | q = skipsp x be |
| 1172 | end |
| 1173 | ret n |
| 1174 | end |
| 1175 | |
| 1176 | note the start of row i of the table at mem[b, e) (rows are lines), checking that it carries task |
| 1177 | note i's id; the row's values start after the id |
| 1178 | fn rowat b ulong e ulong i ulong to ulong |
| 1179 | p = b |
| 1180 | for j ulong i bound 9223372036854775807 |
| 1181 | p = add lend p e 1 |
| 1182 | end |
| 1183 | if ge p e |
| 1184 | dien eexp i 66 |
| 1185 | end |
| 1186 | w = wordend p lend p e |
| 1187 | if not mm p sub w p tfd i 0 tfd i 1 |
| 1188 | dien eexp i 66 |
| 1189 | end |
| 1190 | ret w |
| 1191 | end |
| 1192 | |
| 1193 | note the smallest number of differing fields over every pair of tasks of one shape in the table at |
| 1194 | note mem[b, e); each pair that does not differ at all is printed |
| 1195 | fn minsep b ulong e ulong to ulong |
| 1196 | m = ulong 18446744073709551615 |
| 1197 | nt = get st 0 |
| 1198 | for i ulong nt bound 9223372036854775807 |
| 1199 | a = rowat b e i |
| 1200 | for j ulong i bound 9223372036854775807 |
| 1201 | if eq tfd i 10 tfd j 10 |
| 1202 | c = rowat b e j |
| 1203 | d = rowdiff a lend a e c lend c e |
| 1204 | if eq d 0 |
| 1205 | ot msame |
| 1206 | omem tfd j 0 tfd j 1 |
| 1207 | oc 32 |
| 1208 | omem tfd i 0 tfd i 1 |
| 1209 | oc 10 |
| 1210 | end |
| 1211 | if lt d m |
| 1212 | m = d |
| 1213 | end |
| 1214 | end |
| 1215 | end |
| 1216 | end |
| 1217 | ret m |
| 1218 | end |
| 1219 | |
| 1220 | fn cmdcheck to void |
| 1221 | if ne argcnt 6 |
| 1222 | die eargs 2 |
| 1223 | end |
| 1224 | put st 27 4 |
| 1225 | put st 26 5 |
| 1226 | ltasks 2 |
| 1227 | xb = aload 3 |
| 1228 | xe = get st 6 |
| 1229 | b = mktable |
| 1230 | e = get st 6 |
| 1231 | ok = mm xb sub xe xb b sub e b |
| 1232 | if not ok |
| 1233 | ot mdiff |
| 1234 | end |
| 1235 | m = minsep b e |
| 1236 | if eq m 0 |
| 1237 | ok = false |
| 1238 | end |
| 1239 | if ok |
| 1240 | ot mpass |
| 1241 | else |
| 1242 | ot mfail |
| 1243 | end |
| 1244 | ou get st 0 |
| 1245 | ot mcase |
| 1246 | ou get st 1 |
| 1247 | ot msep |
| 1248 | ou m |
| 1249 | oc 10 |
| 1250 | oflush |
| 1251 | if not ok |
| 1252 | exit 1 |
| 1253 | end |
| 1254 | end |
| 1255 | |
| 1256 | note ======== prompts and samples |
| 1257 | |
| 1258 | fn cmdprompts to void |
| 1259 | if ne argcnt 4 |
| 1260 | die eargs 2 |
| 1261 | end |
| 1262 | put st 26 3 |
| 1263 | ltasks 2 |
| 1264 | for i ulong get st 0 bound 9223372036854775807 |
| 1265 | gprompt i |
| 1266 | wpid fpprm i |
| 1267 | fsave 420 |
| 1268 | end |
| 1269 | end |
| 1270 | |
| 1271 | note sample TASKS WORK OLLM CMD CK [MERGES]: one answer file per task |
| 1272 | fn cmdsample to void |
| 1273 | na = ulong argcnt |
| 1274 | if and ne na 7 ne na 8 |
| 1275 | die eargs 2 |
| 1276 | end |
| 1277 | put st 26 3 |
| 1278 | ltasks 2 |
| 1279 | for i ulong get st 0 bound 9223372036854775807 |
| 1280 | s = sample1 i na |
| 1281 | if ne s 0 |
| 1282 | ot msfail |
| 1283 | omem tfd i 0 tfd i 1 |
| 1284 | oc 32 |
| 1285 | ou ulong s |
| 1286 | oc 10 |
| 1287 | oflush |
| 1288 | exit 71 |
| 1289 | end |
| 1290 | end |
| 1291 | end |
| 1292 | |
| 1293 | fn sample1 i ulong na ulong to long |
| 1294 | gprompt i |
| 1295 | pclr |
| 1296 | ptx tnull |
| 1297 | fi = popen false 0 |
| 1298 | wpid fpans i |
| 1299 | fo = popen true 420 |
| 1300 | kclr |
| 1301 | karg 4 |
| 1302 | karg 5 |
| 1303 | karg 6 |
| 1304 | ktx a42 |
| 1305 | ktx a128 |
| 1306 | ktx a0 |
| 1307 | kprog |
| 1308 | if eq na 8 |
| 1309 | karg 7 |
| 1310 | end |
| 1311 | pid = spawn fi fo false |
| 1312 | z = fclose fi |
| 1313 | z = fclose fo |
| 1314 | ret waitp pid 3600000 |
| 1315 | end |
| 1316 | |
| 1317 | note ======== normal forms (seen) |
| 1318 | |
| 1319 | note the index of the name mem[o, o + n) in nmt, or st25 when it is not there |
| 1320 | fn nmfind o ulong n ulong to ulong |
| 1321 | c = get st 25 |
| 1322 | for i ulong c bound 9223372036854775807 |
| 1323 | if mm o n get nmt mul i 2 get nmt add mul i 2 1 |
| 1324 | ret i |
| 1325 | end |
| 1326 | end |
| 1327 | ret c |
| 1328 | end |
| 1329 | |
| 1330 | fn nmadd o ulong n ulong to void |
| 1331 | c = get st 25 |
| 1332 | if lt nmfind o n c |
| 1333 | ret |
| 1334 | end |
| 1335 | r = enlarge nmt mul add c 1 2 |
| 1336 | if lt r 0 |
| 1337 | die eio 70 |
| 1338 | end |
| 1339 | put nmt mul c 2 o |
| 1340 | put nmt add mul c 2 1 n |
| 1341 | put st 25 add c 1 |
| 1342 | end |
| 1343 | |
| 1344 | fn nc c ulong to void |
| 1345 | n = get st 24 |
| 1346 | if ge n len nrm |
| 1347 | r = enlarge nrm add mul n 2 4096 |
| 1348 | if lt r 0 |
| 1349 | die eio 70 |
| 1350 | end |
| 1351 | end |
| 1352 | put nrm n uchar c |
| 1353 | put st 24 add n 1 |
| 1354 | end |
| 1355 | |
| 1356 | note the names the fn line mem[p, q) declares: the function, then each parameter |
| 1357 | fn nmsig p ulong q ulong to void |
| 1358 | a = skipsp add p 3 q |
| 1359 | w = wordend a q |
| 1360 | nmadd a sub w a |
| 1361 | a = skipsp w q |
| 1362 | while lt a q bound 9223372036854775807 |
| 1363 | w = wordend a q |
| 1364 | if meq a w twto |
| 1365 | ret |
| 1366 | end |
| 1367 | nmadd a sub w a |
| 1368 | a = skipsp w q |
| 1369 | w = wordend a q |
| 1370 | if or meq a w twview meq a w twedit |
| 1371 | a = skipsp w q |
| 1372 | w = wordend a q |
| 1373 | a = skipsp w q |
| 1374 | w = wordend a q |
| 1375 | end |
| 1376 | a = skipsp w q |
| 1377 | end |
| 1378 | end |
| 1379 | |
| 1380 | note the names the body line mem[p, q) declares: `NAME = ..` and `for NAME ..` |
| 1381 | fn nmline p ulong q ulong to void |
| 1382 | a = skipsp p q |
| 1383 | w = wordend a q |
| 1384 | b = skipsp w q |
| 1385 | x = wordend b q |
| 1386 | if ge b q |
| 1387 | ret |
| 1388 | end |
| 1389 | if meq a w twfor |
| 1390 | nmadd b sub x b |
| 1391 | ret |
| 1392 | end |
| 1393 | if meq b x tweq |
| 1394 | nmadd a sub w a |
| 1395 | end |
| 1396 | end |
| 1397 | |
| 1398 | note the line mem[p, q) in normal form onto nrm: words joined by one space, declared names as |
| 1399 | note v and their index, a newline; blank and note lines add nothing |
| 1400 | fn nline p ulong q ulong to void |
| 1401 | a = skipsp p q |
| 1402 | if or ge a q meq a wordend a q lnote |
| 1403 | ret |
| 1404 | end |
| 1405 | first = true |
| 1406 | while lt a q bound 9223372036854775807 |
| 1407 | w = wordend a q |
| 1408 | if not first |
| 1409 | nc 32 |
| 1410 | end |
| 1411 | first = false |
| 1412 | nword a sub w a |
| 1413 | a = skipsp w q |
| 1414 | end |
| 1415 | nc 10 |
| 1416 | end |
| 1417 | |
| 1418 | fn nword a ulong n ulong to void |
| 1419 | i = nmfind a n |
| 1420 | if lt i get st 25 |
| 1421 | nc 118 |
| 1422 | d = udec i |
| 1423 | while lt d 24 bound 24 |
| 1424 | nc ulong get dg d |
| 1425 | d = add d 1 |
| 1426 | end |
| 1427 | ret |
| 1428 | end |
| 1429 | for j ulong n bound 9223372036854775807 |
| 1430 | nc ulong get mem add a j |
| 1431 | end |
| 1432 | end |
| 1433 | |
| 1434 | note the function at mem[p ..) (its fn line ends at q, its closing end line at z) in normal form |
| 1435 | note onto nrm |
| 1436 | fn nfn p ulong q ulong z ulong to void |
| 1437 | put st 25 0 |
| 1438 | nmsig p q |
| 1439 | a = add q 1 |
| 1440 | while lt a z bound 9223372036854775807 |
| 1441 | b = lend a z |
| 1442 | nmline a b |
| 1443 | a = add b 1 |
| 1444 | end |
| 1445 | a = p |
| 1446 | while lt a z bound 9223372036854775807 |
| 1447 | b = lend a z |
| 1448 | nline a b |
| 1449 | a = add b 1 |
| 1450 | end |
| 1451 | end |
| 1452 | |
| 1453 | note every task's reference in normal form (tk 13, 14) |
| 1454 | fn ntasks to void |
| 1455 | for i ulong get st 0 bound 9223372036854775807 |
| 1456 | p = sub tfd i 11 3 |
| 1457 | q = sub tfd i 8 1 |
| 1458 | z = add tfd i 8 tfd i 9 |
| 1459 | b = get st 24 |
| 1460 | nfn p q z |
| 1461 | tput i 13 b |
| 1462 | tput i 14 sub get st 24 b |
| 1463 | end |
| 1464 | end |
| 1465 | |
| 1466 | note whether nrm[a, a + n) equals nrm[b, b + n) |
| 1467 | fn nsame a ulong b ulong n ulong to bool |
| 1468 | for i ulong n bound 9223372036854775807 |
| 1469 | if ne get nrm add a i get nrm add b i |
| 1470 | ret false |
| 1471 | end |
| 1472 | end |
| 1473 | ret true |
| 1474 | end |
| 1475 | |
| 1476 | note mark (tk 15 = 9) every task whose normal form equals nrm[b, fill) |
| 1477 | fn nmark b ulong to void |
| 1478 | n = sub get st 24 b |
| 1479 | for i ulong get st 0 bound 9223372036854775807 |
| 1480 | if eq tfd i 14 n |
| 1481 | if nsame tfd i 13 b n |
| 1482 | tput i 15 9 |
| 1483 | end |
| 1484 | end |
| 1485 | end |
| 1486 | end |
| 1487 | |
| 1488 | note mark the tasks whose reference is a function of the corpus at mem[b, e); the functions read |
| 1489 | fn nscan b ulong e ulong to ulong |
| 1490 | f = ulong 0 |
| 1491 | p = b |
| 1492 | while lt p e bound 9223372036854775807 |
| 1493 | q = lend p e |
| 1494 | if sw p q lfn |
| 1495 | z = bodyend add q 1 e |
| 1496 | if ne z 0 |
| 1497 | m = get st 24 |
| 1498 | nfn p q sub z 1 |
| 1499 | nmark m |
| 1500 | put st 24 m |
| 1501 | f = add f 1 |
| 1502 | q = sub z 1 |
| 1503 | end |
| 1504 | end |
| 1505 | p = add q 1 |
| 1506 | end |
| 1507 | ret f |
| 1508 | end |
| 1509 | |
| 1510 | fn cmdseen to void |
| 1511 | if ne argcnt 4 |
| 1512 | die eargs 2 |
| 1513 | end |
| 1514 | ltasks 2 |
| 1515 | ntasks |
| 1516 | b = aload 3 |
| 1517 | f = nscan b get st 6 |
| 1518 | k = ulong 0 |
| 1519 | for i ulong get st 0 bound 9223372036854775807 |
| 1520 | if eq tfd i 15 9 |
| 1521 | ot mseen |
| 1522 | omem tfd i 0 tfd i 1 |
| 1523 | oc 10 |
| 1524 | k = add k 1 |
| 1525 | end |
| 1526 | end |
| 1527 | ot mseens |
| 1528 | ou get st 0 |
| 1529 | ot msseen |
| 1530 | ou k |
| 1531 | ot mseenf |
| 1532 | ou f |
| 1533 | oc 10 |
| 1534 | oflush |
| 1535 | end |
| 1536 | |
| 1537 | note ======== score |
| 1538 | |
| 1539 | note whether the body mem[b, e) says exit or trap |
| 1540 | fn banned b ulong e ulong to bool |
| 1541 | p = b |
| 1542 | while lt p e bound 9223372036854775807 |
| 1543 | q = lend p e |
| 1544 | a = skipsp p q |
| 1545 | while lt a q bound 9223372036854775807 |
| 1546 | w = wordend a q |
| 1547 | if or meq a w twexit meq a w twtrap |
| 1548 | ret true |
| 1549 | end |
| 1550 | a = skipsp w q |
| 1551 | end |
| 1552 | p = add q 1 |
| 1553 | end |
| 1554 | ret false |
| 1555 | end |
| 1556 | |
| 1557 | note whether mem[p, e) holds anything but spaces, tabs, newlines and carriage returns |
| 1558 | fn more p ulong e ulong to bool |
| 1559 | for i ulong sub e p bound 9223372036854775807 |
| 1560 | c = get mem add p i |
| 1561 | if and and ne c 32 ne c 9 and ne c 10 ne c 13 |
| 1562 | ret true |
| 1563 | end |
| 1564 | end |
| 1565 | ret false |
| 1566 | end |
| 1567 | |
| 1568 | note the verdict of task i from the answer at mem[ao, ae), the expectation cursor on its row |
| 1569 | fn judge i ulong ao ulong ae ulong to ulong |
| 1570 | z = bodyend ao ae |
| 1571 | if eq z 0 |
| 1572 | ret 5 |
| 1573 | end |
| 1574 | q = sub z 1 |
| 1575 | if banned ao q |
| 1576 | ret 6 |
| 1577 | end |
| 1578 | gscore i ao sub q ao |
| 1579 | s = compile |
| 1580 | if eq s 1000 |
| 1581 | ret 8 |
| 1582 | end |
| 1583 | if ne s 0 |
| 1584 | ret 4 |
| 1585 | end |
| 1586 | s = runp false |
| 1587 | if eq s 1000 |
| 1588 | ret 8 |
| 1589 | end |
| 1590 | if ne s 77 |
| 1591 | ret 3 |
| 1592 | end |
| 1593 | if more q ae |
| 1594 | ret 2 |
| 1595 | end |
| 1596 | ret 1 |
| 1597 | end |
| 1598 | |
| 1599 | fn vname v ulong to void |
| 1600 | if eq v 1 |
| 1601 | ot v1 |
| 1602 | end |
| 1603 | if eq v 2 |
| 1604 | ot v2 |
| 1605 | end |
| 1606 | if eq v 3 |
| 1607 | ot v3 |
| 1608 | end |
| 1609 | if eq v 4 |
| 1610 | ot v4 |
| 1611 | end |
| 1612 | if eq v 5 |
| 1613 | ot v5 |
| 1614 | end |
| 1615 | if eq v 6 |
| 1616 | ot v6 |
| 1617 | end |
| 1618 | if eq v 7 |
| 1619 | ot v7 |
| 1620 | end |
| 1621 | if eq v 8 |
| 1622 | ot v8 |
| 1623 | end |
| 1624 | if eq v 9 |
| 1625 | ot v9 |
| 1626 | end |
| 1627 | end |
| 1628 | |
| 1629 | note grade task i: load its answer, judge it, print its R line, keep the verdict in tk 15 |
| 1630 | fn score1 i ulong xb ulong xe ulong mark ulong to void |
| 1631 | v = tfd i 15 |
| 1632 | if ne v 9 |
| 1633 | a = rowat xb xe i |
| 1634 | put st 28 skipsp a lend a xe |
| 1635 | put st 29 lend a xe |
| 1636 | put st 6 mark |
| 1637 | wpid fpans i |
| 1638 | n = fload |
| 1639 | v = 7 |
| 1640 | if ne n 18446744073709551615 |
| 1641 | v = judge i mark add mark n |
| 1642 | end |
| 1643 | tput i 15 v |
| 1644 | end |
| 1645 | oc 82 |
| 1646 | oc 32 |
| 1647 | omem tfd i 0 tfd i 1 |
| 1648 | oc 32 |
| 1649 | omem tfd i 2 tfd i 3 |
| 1650 | oc 32 |
| 1651 | vname v |
| 1652 | oc 10 |
| 1653 | oflush |
| 1654 | end |
| 1655 | |
| 1656 | note the tasks of task i's family with verdict v |
| 1657 | fn famcnt i ulong v ulong to ulong |
| 1658 | n = ulong 0 |
| 1659 | for j ulong get st 0 bound 9223372036854775807 |
| 1660 | if mm tfd i 2 tfd i 3 tfd j 2 tfd j 3 |
| 1661 | if or eq v 0 eq tfd j 15 v |
| 1662 | n = add n 1 |
| 1663 | end |
| 1664 | end |
| 1665 | end |
| 1666 | ret n |
| 1667 | end |
| 1668 | |
| 1669 | note whether an earlier task has task i's family |
| 1670 | fn famold i ulong to bool |
| 1671 | for j ulong i bound 9223372036854775807 |
| 1672 | if mm tfd i 2 tfd i 3 tfd j 2 tfd j 3 |
| 1673 | ret true |
| 1674 | end |
| 1675 | end |
| 1676 | ret false |
| 1677 | end |
| 1678 | |
| 1679 | note the tasks with verdict v |
| 1680 | fn vcnt v ulong to ulong |
| 1681 | n = ulong 0 |
| 1682 | for j ulong get st 0 bound 9223372036854775807 |
| 1683 | if eq tfd j 15 v |
| 1684 | n = add n 1 |
| 1685 | end |
| 1686 | end |
| 1687 | ret n |
| 1688 | end |
| 1689 | |
| 1690 | fn summary to void |
| 1691 | for i ulong get st 0 bound 9223372036854775807 |
| 1692 | if not famold i |
| 1693 | oc 70 |
| 1694 | oc 32 |
| 1695 | omem tfd i 2 tfd i 3 |
| 1696 | oc 32 |
| 1697 | ou famcnt i 0 |
| 1698 | for v ulong 9 |
| 1699 | oc 32 |
| 1700 | ou famcnt i add v 1 |
| 1701 | end |
| 1702 | oc 10 |
| 1703 | end |
| 1704 | end |
| 1705 | k = vcnt 9 |
| 1706 | ot mscore |
| 1707 | ou sub get st 0 k |
| 1708 | ot mspass |
| 1709 | ou vcnt 1 |
| 1710 | ot mscut |
| 1711 | ou vcnt 2 |
| 1712 | ot msseen |
| 1713 | ou k |
| 1714 | oc 10 |
| 1715 | oflush |
| 1716 | end |
| 1717 | |
| 1718 | note score TASKS EXPECT OMC WORK [CORPUS] |
| 1719 | fn cmdscore to void |
| 1720 | na = ulong argcnt |
| 1721 | if and ne na 6 ne na 7 |
| 1722 | die eargs 2 |
| 1723 | end |
| 1724 | put st 27 4 |
| 1725 | put st 26 5 |
| 1726 | ltasks 2 |
| 1727 | xb = aload 3 |
| 1728 | xe = get st 6 |
| 1729 | if eq na 7 |
| 1730 | ntasks |
| 1731 | b = aload 6 |
| 1732 | f = nscan b get st 6 |
| 1733 | end |
| 1734 | mark = get st 6 |
| 1735 | for i ulong get st 0 bound 9223372036854775807 |
| 1736 | score1 i xb xe mark |
| 1737 | end |
| 1738 | summary |
| 1739 | end |
| 1740 | |
| 1741 | fn iscmd t view uchar * to bool |
| 1742 | pclr |
| 1743 | parg 1 |
| 1744 | n = get st 3 |
| 1745 | if ne n len t |
| 1746 | ret false |
| 1747 | end |
| 1748 | for i ulong n |
| 1749 | if ne get pth i get t i |
| 1750 | ret false |
| 1751 | end |
| 1752 | end |
| 1753 | ret true |
| 1754 | end |
| 1755 | |
| 1756 | fn main to int |
| 1757 | if lt argcnt 2 |
| 1758 | die eargs 2 |
| 1759 | end |
| 1760 | if iscmd ctable |
| 1761 | cmdtable |
| 1762 | ret 0 |
| 1763 | end |
| 1764 | if iscmd ccheck |
| 1765 | cmdcheck |
| 1766 | ret 0 |
| 1767 | end |
| 1768 | if iscmd cprompts |
| 1769 | cmdprompts |
| 1770 | ret 0 |
| 1771 | end |
| 1772 | if iscmd csample |
| 1773 | cmdsample |
| 1774 | ret 0 |
| 1775 | end |
| 1776 | if iscmd cscore |
| 1777 | cmdscore |
| 1778 | ret 0 |
| 1779 | end |
| 1780 | if iscmd cseen |
| 1781 | cmdseen |
| 1782 | ret 0 |
| 1783 | end |
| 1784 | die eargs 2 |
| 1785 | ret 2 |
| 1786 | end |