interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / train / aien-train / tests / adtrain / replay / subst.om

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