interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / pageunit / gen.om

332 lines · 5919 bytes Raw Blame History
1note gen.om: deterministic inputs and the two helpers of the pageunit gate (tests/pageunit/run.sh),
2note so the runner itself only invokes programs and compares bytes and exit codes. Argument 1 selects:
3note m 900000 bytes: 7500 copies of the 120-byte line GLINE (quotes, backslashes, a tab, UTF-8)
4note w 999999 bytes: 7999 lines of 124 quotes, then 124 quotes with no newline (every byte escaped)
5note b 1000000 bytes of a, no newline: one line longer than a record, split by enc
6note g 300000 bytes of q, no newline
7note k, j, l 8000, 8001 and 10000 lines of x (8000 was the most the old enc accepted)
8note x, y 50000 and 200000 lines "line N" (the old pinned omc refused units past 8192 texts); the
9note unit of y is over the alarm threshold, so it is also the alarm's end-to-end control
10note c, d ok, byte 1 or byte 127, newline: enc must exit 4
11note u stdin to stdout, streamed, with the first lowercase letter after the first quote changed to
12note upper case: one byte inside the first text record of an enc unit (the mutant control)
13note a alarm: stdin is the omc-use record of a unit compiled in usage mode (`usage` as its first
14note line). Prints "arena=A top=T full=F alarm-at=ALARMAT" and exits 8 when F is 1 or T (the
15note 8-byte words the unit put in the compiler's arena) is ALARMAT or more; exit 0 below it. The
16note threshold is a stated number, not a share of A: 80 percent of the 16777216-word arena that
17note compilers before omega-mv's run-time pools had (that arena was fixed; the later one grows, so a
18note share of it says nothing)
19note exit 0 ok, 2 usage, read error or no record, 6 write error, 7 mode u found no letter to change,
20note 8 alarm. Every input is read in 65536-byte blocks and output leaves through one 1048576-byte
21note buffer; no size limit of its own.
22global gb uchar 1048576
23global gn ulong 1
24global gi uchar 65536
25global av ulong 8
26text GLINE "He said \"ok\"\tthen C:\\tmp\\x; café naïve 中文 Ελλάδα € 🙂 the quick brown fox jumps over the lazy dog, agai\n"
27text KARENA "arena="
28text KTOP "top="
29text KFULL "full="
30text AARENA "arena="
31text ATOP " top="
32text AFULL " full="
33text AUSED " alarm-at="
34const ALARMAT ulong 13421773
35fn gflush to void
36n = get gn 0
37o = ulong 0
38while lt o n bound 1048577
39k = write 1 gb o sub n o
40if le k 0
41exit 6
42end
43o = add o ulong k
44end
45put gn 0 0
46end
47fn gput c uchar to void
48p = get gn 0
49put gb p c
50p = add p 1
51put gn 0 p
52if eq p 1048576
53gflush
54end
55end
56fn gdec v ulong to void
57d = new uchar 20 0
58k = ulong 0
59x = v
60while gt x 0 bound 20
61put d k uchar add rem x 10 48
62x = div x 10
63k = add k 1
64end
65if eq k 0
66gput uchar 48
67end
68while gt k 0 bound 20
69k = sub k 1
70gput get d k
71end
72end
73fn gtimes c uchar k ulong to void
74i = ulong 0
75while lt i k bound 9223372036854775807
76gput c
77i = add i 1
78end
79end
80fn gtext a view uchar * to void
81n = len a
82i = ulong 0
83while lt i n bound 4097
84gput get a i
85i = add i 1
86end
87end
88fn gxlines k ulong to void
89i = ulong 0
90while lt i k bound 9223372036854775807
91gput uchar 120
92gput uchar 10
93i = add i 1
94end
95end
96fn gnlines k ulong to void
97i = ulong 0
98while lt i k bound 9223372036854775807
99gput uchar 108
100gput uchar 105
101gput uchar 110
102gput uchar 101
103gput uchar 32
104gdec i
105gput uchar 10
106i = add i 1
107end
108end
109fn gmutate to int
110note st 0 before the first quote, 1 after it, 2 done
111st = ulong 0
112go = ulong 1
113while eq go 1 bound 9223372036854775807
114r = read 0 gi 0 65536
115if lt r 0
116ret 2
117end
118if eq r 0
119go = ulong 0
120else
121n = ulong r
122i = ulong 0
123while lt i n bound 65536
124c = get gi i
125if eq st 1
126if ge c 97
127if le c 122
128c = uchar sub c 32
129st = ulong 2
130end
131end
132end
133if eq st 0
134if eq c 34
135st = ulong 1
136end
137end
138gput c
139i = add i 1
140end
141end
142end
143gflush
144if ne st 2
145ret 7
146end
147ret 0
148end
149fn kstep k view uchar * pos ulong c uchar to ulong
150note the next match position of key k after byte c, given the current one
151if eq c get k pos
152ret add pos 1
153end
154if eq c get k 0
155ret 1
156end
157ret 0
158end
159fn galarm to int
160note av: 0 arena, 1 top, 2 full, 3 digit target (0 none, 1 arena, 2 top, 3 full), 4..6 key
161note positions, 7 keys seen (bit 1 arena, 2 top)
162go = ulong 1
163while eq go 1 bound 9223372036854775807
164r = read 0 gi 0 65536
165if lt r 0
166ret 2
167end
168if eq r 0
169go = ulong 0
170else
171n = ulong r
172i = ulong 0
173while lt i n bound 65536
174c = get gi i
175t = get av 3
176if ne t 0
177if ge c 48
178if le c 57
179v = get av sub t 1
180put av sub t 1 add mul v 10 ulong sub c 48
181end
182end
183if lt c 48
184put av 3 0
185end
186if gt c 57
187put av 3 0
188end
189end
190pa = kstep KARENA get av 4 c
191pt = kstep KTOP get av 5 c
192pf = kstep KFULL get av 6 c
193if eq pa len KARENA
194put av 0 0
195put av 3 1
196put av 7 or get av 7 1
197pa = ulong 0
198end
199if eq pt len KTOP
200put av 1 0
201put av 3 2
202put av 7 or get av 7 2
203pt = ulong 0
204end
205if eq pf len KFULL
206put av 2 0
207put av 3 3
208pf = ulong 0
209end
210put av 4 pa
211put av 5 pt
212put av 6 pf
213i = add i 1
214end
215end
216end
217if ne get av 7 3
218ret 2
219end
220a = get av 0
221if eq a 0
222ret 2
223end
224t = get av 1
225f = get av 2
226gtext AARENA
227gdec a
228gtext ATOP
229gdec t
230gtext AFULL
231gdec f
232gtext AUSED
233gdec ALARMAT
234gput uchar 10
235gflush
236if eq f 1
237ret 8
238end
239if ge t ALARMAT
240ret 8
241end
242ret 0
243end
244fn main to int
245if ne argcnt 2
246ret 2
247end
248m = new uchar 8 0
249k = argread 1 m 0 8
250if lt k 1
251ret 2
252end
253c = get m 0
254if eq c 117
255ret gmutate
256end
257if eq c 97
258ret galarm
259end
260if eq c 109
261i = ulong 0
262while lt i 7500 bound 7500
263gtext GLINE
264i = add i 1
265end
266gflush
267ret 0
268end
269if eq c 119
270j = ulong 0
271while lt j 7999 bound 7999
272gtimes uchar 34 124
273gput uchar 10
274j = add j 1
275end
276gtimes uchar 34 124
277gflush
278ret 0
279end
280if eq c 98
281gtimes uchar 97 1000000
282gflush
283ret 0
284end
285if eq c 103
286gtimes uchar 113 300000
287gflush
288ret 0
289end
290if eq c 107
291gxlines 8000
292gflush
293ret 0
294end
295if eq c 106
296gxlines 8001
297gflush
298ret 0
299end
300if eq c 108
301gxlines 10000
302gflush
303ret 0
304end
305if eq c 120
306gnlines 50000
307gflush
308ret 0
309end
310if eq c 121
311gnlines 200000
312gflush
313ret 0
314end
315if eq c 99
316gput uchar 111
317gput uchar 107
318gput uchar 1
319gput uchar 10
320gflush
321ret 0
322end
323if eq c 100
324gput uchar 111
325gput uchar 107
326gput uchar 127
327gput uchar 10
328gflush
329ret 0
330end
331ret 2
332end