aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tests / adtrain / replay / subst.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note subst: exact-once source substitution for the DRA-14 replay mutants. |
| 3 | note stdin: PATTERN, one 0 byte, REPLACEMENT, one 0 byte, SOURCE. |
| 4 | note stdout: SOURCE with the single occurrence of PATTERN replaced. |
| 5 | note Exits: 0 done, 74 I/O, 75 malformed input, 76 PATTERN does not occur |
| 6 | note exactly once in SOURCE (an invalid mutant setup, never a kill). |
| 7 | note Written independently of omega-mv tests/autodiff664/mutate.om and |
| 8 | note aien-train tests/adtrain/mutate.om; it knows no pattern of its own. |
| 9 | global SI uchar 262144 |
| 10 | global SZ ulong 4 |
| 11 | |
| 12 | note Read all of stdin into SI; SZ 0 = byte count. |
| 13 | fn slurp to void |
| 14 | p = ulong 0 |
| 15 | reading = true |
| 16 | while reading bound 262145 |
| 17 | if eq p 262144 |
| 18 | exit 75 |
| 19 | end |
| 20 | n = read 0 SI p sub 262144 p |
| 21 | if eq n 0 |
| 22 | reading = false |
| 23 | else |
| 24 | if lt n 0 |
| 25 | exit 74 |
| 26 | end |
| 27 | p = add p ulong n |
| 28 | end |
| 29 | end |
| 30 | put SZ 0 p |
| 31 | end |
| 32 | |
| 33 | note Index of the first 0 byte at or after from; exit 75 when there is none. |
| 34 | fn zfind from ulong to ulong |
| 35 | i = from |
| 36 | while lt i get SZ 0 bound 262145 |
| 37 | if eq get SI i 0 |
| 38 | ret i |
| 39 | end |
| 40 | i = add i 1 |
| 41 | end |
| 42 | exit 75 |
| 43 | end |
| 44 | |
| 45 | note true when the pattern SI[ps..ps+pl) occurs at SI[pos..). |
| 46 | fn match pos ulong ps ulong pl ulong to bool |
| 47 | k = ulong 0 |
| 48 | while lt k pl bound 262145 |
| 49 | if ne get SI add pos k get SI add ps k |
| 50 | ret false |
| 51 | end |
| 52 | k = add k 1 |
| 53 | end |
| 54 | ret true |
| 55 | end |
| 56 | |
| 57 | fn emit from ulong n ulong to void |
| 58 | o = ulong 0 |
| 59 | while lt o n bound 262145 |
| 60 | w = write 1 SI add from o sub n o |
| 61 | if le w 0 |
| 62 | exit 74 |
| 63 | end |
| 64 | o = add o ulong w |
| 65 | end |
| 66 | end |
| 67 | |
| 68 | fn main to int |
| 69 | slurp |
| 70 | z1 = zfind 0 |
| 71 | z2 = zfind add z1 1 |
| 72 | pl = z1 |
| 73 | if eq pl 0 |
| 74 | ret 75 |
| 75 | end |
| 76 | s0 = add z2 1 |
| 77 | n = get SZ 0 |
| 78 | if lt sub n s0 pl |
| 79 | ret 76 |
| 80 | end |
| 81 | found = ulong 0 |
| 82 | at = ulong 0 |
| 83 | last = sub n pl |
| 84 | pos = s0 |
| 85 | while le pos last bound 262145 |
| 86 | if match pos 0 pl |
| 87 | found = add found 1 |
| 88 | at = pos |
| 89 | end |
| 90 | pos = add pos 1 |
| 91 | end |
| 92 | if ne found 1 |
| 93 | ret 76 |
| 94 | end |
| 95 | emit s0 sub at s0 |
| 96 | emit add z1 1 sub z2 add z1 1 |
| 97 | tail = add at pl |
| 98 | emit tail sub n tail |
| 99 | ret 0 |
| 100 | end |