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 / seed / omc / tests / pools / mk.py

793 lines · 19215 bytes Raw Blame History
1#!/usr/bin/env python3
2# mk.py OUTDIR -- the test-data generator of seed/omc/tests/pools (run by seed/omc/gate-pools.sh, which
3# checks that `python3 seed/omc/tests/pools/mk.py DIR` gives the committed .om and .want files byte for
4# byte). Writes every hand-written case and its expected output, computed here; fuzz.py writes the rest.
5import os, sys
6
7OUT = sys.argv[1]
8os.makedirs(OUT, exist_ok=True)
9
10PNUM = """fn pnum v ulong to void
11put ob 23 10
12i = ulong 23
13x = v
14go = true
15while go bound 21
16i = sub i 1
17put ob i uchar add rem x 10 48
18x = div x 10
19go = ne x 0
20end
21k = write 1 ob i sub 24 i
22end
23fn plong v long to void
24if lt v 0
25put ob 0 uchar 45
26k = write 1 ob 0 1
27pnum ulong neg v
28else
29pnum ulong v
30end
31end
32"""
33
34RSS = """fn hit i ulong to bool
35a = and eq get sb i 86 eq get sb add i 1 109
36b = and eq get sb add i 2 82 eq get sb add i 5 58
37ret and a b
38end
39fn rss to ulong
40fd = fopen pth 0 len pth 0 0
41if lt fd 0
42ret 0
43end
44n = read int fd sb 0 4096
45fd = fclose int fd
46if le n 0
47ret 0
48end
49lim = ulong n
50i = ulong 0
51while lt add i 6 lim bound 4096
52if hit i
53break
54end
55i = add i 1
56end
57i = add i 6
58v = ulong 0
59while lt i lim bound 4096
60ch = get sb i
61if and ge ch 48 le ch 57
62v = add mul v 10 ulong sub ch 48
63else
64if and ne ch 32 ne ch 9
65break
66end
67end
68i = add i 1
69end
70ret v
71end
72"""
73
74
75WROTE = []
76
77
78def put(name, src, want=None):
79 with open(os.path.join(OUT, name + ".om"), "w") as f:
80 f.write(src)
81 WROTE.append(name + ".om")
82 if want is not None:
83 with open(os.path.join(OUT, name + ".want"), "w") as f:
84 f.write(want)
85 WROTE.append(name + ".want")
86
87
88def W(lines, status):
89 return "".join(str(x) + "\n" for x in lines) + "status %d\n" % status
90
91
92# ---------------------------------------------------------------- gate 1: growth and contents
93g1 = """note gate-pools 1: growth and contents. P grows 0 -> 1 -> 2 -> 512 -> 513 -> 4096 (then 10 and 4096,
94note which change nothing) -> 2^20 -> 2^27 elements; Q (uchar) grows past 16777216 elements, then to 2^27.
95note Old values are kept and new elements are 0 at every step.
96global P ulong *
97global Q uchar *
98global ob uchar 24
99""" + PNUM + """fn psum a ulong b ulong to ulong
100s = ulong 0
101i = a
102while lt i b bound 200000000
103s = add s get P i
104i = add i 1
105end
106ret s
107end
108fn qsum a ulong b ulong to ulong
109s = ulong 0
110i = a
111while lt i b bound 200000000
112s = add s ulong get Q i
113i = add i 1
114end
115ret s
116end
117fn main to int
118pnum len P
119r = enlarge P ulong 1
120plong r
121pnum len P
122pnum get P 0
123put P 0 7
124r = enlarge P ulong 2
125plong r
126pnum len P
127pnum get P 0
128pnum get P 1
129put P 1 8
130r = enlarge P ulong 512
131plong r
132pnum len P
133pnum psum 2 512
134r = enlarge P ulong 513
135plong r
136pnum len P
137pnum get P 0
138pnum get P 1
139pnum get P 512
140r = enlarge P ulong 4096
141plong r
142pnum len P
143pnum psum 2 4096
144i = ulong 0
145while lt i 4096
146put P i add i 1
147i = add i 1
148end
149r = enlarge P ulong 10
150plong r
151pnum len P
152pnum psum 0 4096
153r = enlarge P ulong 4096
154plong r
155pnum len P
156r = enlarge P ulong 1048576
157plong r
158pnum len P
159pnum psum 0 4096
160pnum psum 4096 1048576
161i = ulong 4096
162while lt i 1048576 bound 2000000
163put P i i
164i = add i 1
165end
166pnum psum 0 1048576
167r = enlarge P ulong 134217728
168plong r
169pnum len P
170pnum psum 0 1048576
171s = ulong 0
172i = ulong 1048576
173while lt i 134217728 bound 200000
174s = add s get P i
175i = add i 4096
176end
177pnum s
178put P 134217727 5
179pnum get P 134217727
180pnum get P 1048575
181r = enlarge Q ulong 16777217
182plong r
183pnum len Q
184i = ulong 0
185while lt i 16777217 bound 20000000
186put Q i uchar and i 255
187i = add i 1
188end
189pnum qsum 0 16777217
190pnum ulong get Q 16777216
191r = enlarge Q ulong 134217728
192plong r
193pnum len Q
194pnum qsum 0 16777217
195pnum qsum 16777217 134217728
196ret 0
197end
198"""
199o = []
200P = []
201o.append(0)
202P = [0] * 1; o += [0, 1, 0]; P[0] = 7
203P += [0]; o += [0, 2, 7, 0]; P[1] = 8
204P += [0] * 510; o += [0, 512, sum(P[2:512])]
205P += [0]; o += [0, 513, 7, 8, 0]
206P += [0] * (4096 - 513); o += [0, 4096, sum(P[2:4096])]
207for i in range(4096):
208 P[i] = i + 1
209o += [0, 4096, sum(P[0:4096])]
210o += [0, 4096]
211o += [0, 1048576, sum(P[0:4096]), 0]
212M = 2**64
213fill = sum(range(4096, 1048576))
214tot = (sum(P[0:4096]) + fill) % M
215o += [tot]
216o += [0, 134217728, tot, 0, 5, 1048575]
217qs = sum(i & 255 for i in range(16777217))
218o += [0, 16777217, qs, 16777216 & 255]
219o += [0, 134217728, qs, 0]
220put("g1", g1, W(o, 0))
221
222gf = """note gate-pools 1: float pools. F (f64) and G (f32) grow by 4096 elements 40 times, a blocker pool B above
223note them forcing moves; each value written is read back after every grow. Prints 2*F[k] and 4*G[k] (as
224note ulong), their sums, both lengths, the last elements (0), then G at its length traps 3.
225global B uchar *
226global F f64 *
227global G f32 *
228global ob uchar 24
229""" + PNUM + """fn main to int
230r = enlarge B ulong 1
231r = enlarge F ulong 1
232r = enlarge G ulong 1
233pnum ulong get F 0
234k = ulong 0
235while lt k 40
236r = enlarge B add len B 4096
237r = enlarge F add len F 4096
238r = enlarge G add len G 4096
239put F k add f64 k 0.5f64
240put G k add f32 k 0.25f32
241pnum ulong mul get F k 2.0f64
242pnum ulong mul get G k 4.0f32
243k = add k 1
244end
245s = ulong 0
246t = ulong 0
247k = ulong 0
248while lt k 40
249s = add s ulong mul get F k 2.0f64
250t = add t ulong mul get G k 4.0f32
251k = add k 1
252end
253pnum s
254pnum t
255pnum len F
256pnum len G
257pnum ulong get F sub len F 1
258pnum ulong get G 40
259n = len G
260pnum ulong get G n
261ret 0
262end
263"""
264o = [0]
265for k in range(40):
266 o += [2 * k + 1, 4 * k + 1]
267o += [sum(2 * k + 1 for k in range(40)), sum(4 * k + 1 for k in range(40)), 1 + 40 * 4096, 1 + 40 * 4096, 0, 0]
268put("gf", gf, W(o, 103))
269
270# ---------------------------------------------------------------- gate 2: range
271g2a = """note gate-pools 2: an index equal to the length (a variable) traps 3 before any store; len + 1 is in range
272note after a grow. With the compare removed the put lands and the next lines print 9.
273global P ulong *
274global ob uchar 24
275""" + PNUM + """fn main to int
276r = enlarge P ulong 10
277put P 9 1
278pnum get P 9
279r = enlarge P ulong 11
280put P 10 5
281pnum get P 10
282i = len P
283put P i 9
284r = enlarge P ulong 12
285pnum get P 11
286ret 0
287end
288"""
289put("g2a", g2a, W([1, 5], 103))
290g2b = """note gate-pools 2: a number index past the length compiles (no error 21) and traps 3 at run time (put).
291global P ulong *
292global ob uchar 24
293""" + PNUM + """fn main to int
294r = enlarge P ulong 4
295put P 3 6
296pnum get P 3
297put P 100 1
298pnum get P 100
299ret 0
300end
301"""
302put("g2b", g2b, W([6], 103))
303g2c = """note gate-pools 2: a number index equal to the length traps 3 at run time (get), also when length 0.
304global P ulong *
305global Q ulong *
306global ob uchar 24
307""" + PNUM + """fn main to int
308r = enlarge P ulong 4
309pnum get P 3
310pnum len Q
311pnum get P 4
312ret 0
313end
314"""
315put("g2c", g2c, W([0, 0], 103))
316g2d = """note gate-pools 2: a read or write slice past the length traps 3 (uchar pool, write path).
317global U uchar *
318global ob uchar 24
319""" + PNUM + """fn main to int
320r = enlarge U ulong 3
321put U 0 79
322put U 1 75
323put U 2 10
324k = write 1 U 0 3
325n = len U
326k = write 1 U 1 n
327pnum 9
328ret 0
329end
330"""
331put("g2d", g2d, "OK\nstatus 103\n")
332
333# ---------------------------------------------------------------- gate 3: stale base
334ROUNDS = 40
335STDIN = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN"
336
337
338def g3src(inline):
339 il = " inline" if inline else ""
340 head = "om2\n" if inline else ""
341 return head + """note gate-pools 3: enlarge runs inside the value of put, the index of get, and the counts of read and
342note write; every call grows the pool it serves by 4096 elements and a blocker pool beside it, so mremap
343note moves the regions and later mappings reuse the old addresses (the gate counts both with strace).
344note stdin: the 40 bytes abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN.%s
345global P ulong *
346global Q ulong *
347global U uchar *
348global V uchar *
349global ob uchar 24
350""" % (" Every grower is an OM-2 inline body." if inline else "") + PNUM + """fn gv v ulong to ulong%s
351r = enlarge P add len P 4096
352r = enlarge Q add len Q 4096
353ret v
354end
355fn gi j ulong to ulong%s
356r = enlarge P add len P 4096
357r = enlarge Q add len Q 4096
358ret j
359end
360fn gu n ulong to ulong%s
361r = enlarge U add len U 4096
362r = enlarge V add len V 4096
363ret n
364end
365fn main to int
366r = enlarge Q ulong 1
367r = enlarge P ulong 1
368r = enlarge V ulong 1
369r = enlarge U ulong 64
370j = ulong 0
371while lt j %d
372put P j gv add mul j 3 1
373x = get P gi j
374pnum x
375k = read 0 U j gu 1
376k = write 1 U j gu 1
377pnum ulong k
378j = add j 1
379end
380k = write 1 U 0 %d
381s = ulong 0
382j = ulong 0
383while lt j %d
384s = add s get P j
385j = add j 1
386end
387pnum s
388pnum len P
389pnum len U
390ret 0
391end
392""" % (il, il, il, ROUNDS, ROUNDS, ROUNDS)
393
394
395o3 = []
396for j in range(ROUNDS):
397 o3.append(3 * j + 1)
398 o3.append(STDIN[j] + "1")
399last = STDIN + str(sum(3 * j + 1 for j in range(ROUNDS)))
400o3.append(last)
401o3.append(1 + 2 * ROUNDS * 4096)
402o3.append(64 + 2 * ROUNDS * 4096)
403put("g3", g3src(False), W(o3, 0))
404put("g3i", g3src(True), W(o3, 0))
405
406# ---------------------------------------------------------------- gate 4: pinning
407g4 = """om2
408note gate-pools 4: the first global is a pool, sized globals follow. The pool takes no pinned register: the
409note set of X18..X26 written by this unit equals that of g4base.om (the same unit without the pool).
410global P ulong *
411global g ulong 10
412global h ulong 5000
413global ob uchar 24
414""" + PNUM + """fn main to int
415r = enlarge P ulong 1000
416put P 999 5
417put g 9 6
418put h 4999 7
419r = enlarge P ulong 1000000
420put P 999999 8
421pnum get P 999
422pnum get g 9
423pnum get h 4999
424pnum get P 999999
425pnum len P
426ret 0
427end
428"""
429put("g4", g4, W([5, 6, 7, 8, 1000000], 0))
430g4base = """om2
431note gate-pools 4 baseline: g4.om without the pool (compiled only, for the pinned register set).
432global g ulong 10
433global h ulong 5000
434global ob uchar 24
435""" + PNUM + """fn main to int
436put g 9 6
437put h 4999 7
438pnum get g 9
439pnum get h 4999
440ret 0
441end
442"""
443put("g4base", g4base, W([6, 7], 0))
444
445# ---------------------------------------------------------------- gate 5: contracts
446g5a = """om2 diag
447note gate-pools 5: requires eq len P 0 is kept (rule=runtime) and holds before the grow, fails after it.
448global P ulong *
449global ob uchar 24
450""" + PNUM + """fn f k ulong to ulong
451requires eq len P 0
452ret k
453end
454fn main to int
455x = f 1
456pnum x
457r = enlarge P ulong 8
458x = f 2
459pnum x
460ret 0
461end
462"""
463put("g5a", g5a, W([1], 109))
464g5b = """om2 diag
465note gate-pools 5: invariant le i len P is kept (rule=runtime): true for i 0..8, false at 9.
466global P ulong *
467global ob uchar 24
468""" + PNUM + """fn main to int
469r = enlarge P ulong 8
470i = ulong 0
471while lt i 12
472invariant le i len P
473pnum i
474i = add i 1
475end
476ret 0
477end
478"""
479put("g5b", g5b, W(list(range(9)), 110))
480g5c = """om2
481note gate-pools 5: a constant index under unroll keeps its run-time check (length 8, copies 0..11).
482global P ulong *
483global ob uchar 24
484""" + PNUM + """fn main to int
485r = enlarge P ulong 8
486for j ulong 12 unroll
487put P j add j 1
488pnum get P j
489end
490ret 0
491end
492"""
493put("g5c", g5c, W(list(range(1, 9)), 103))
494g5d = """om2
495note gate-pools 5: a constant index in an inline body keeps its run-time check (7 in range, 9 not).
496global P ulong *
497global ob uchar 24
498""" + PNUM + """fn g7 to ulong inline
499ret get P 7
500end
501fn g9 to ulong inline
502ret get P 9
503end
504fn main to int
505r = enlarge P ulong 8
506put P 7 4
507pnum g7
508pnum g9
509ret 0
510end
511"""
512put("g5d", g5d, W([4], 103))
513g5ctl = """om2 diag
514note gate-pools 5 control: len of a sized global folds, so the same clause is erased rule=constant-true.
515global G ulong 8
516fn f k ulong to ulong
517requires eq len G 8
518ret k
519end
520fn main to int
521x = f 1
522ret int x
523end
524"""
525put("g5ctl", g5ctl, W([], 1))
526
527# ---------------------------------------------------------------- gate 8: host refusal
528g8a = """note gate-pools 8: run under prlimit --as=268435456: an 8 GiB enlarge returns -12, the pool is unchanged,
529note the program goes on and ends with its own status 7. Without the limit the first 8 GiB enlarge gives 0.
530global P ulong *
531global Q ulong *
532global ob uchar 24
533""" + PNUM + """fn main to int
534r = enlarge P ulong 1000
535plong r
536put P 5 42
537r = enlarge P ulong 1073741824
538plong r
539pnum len P
540pnum get P 5
541r = enlarge Q ulong 1073741824
542plong r
543pnum len Q
544r = enlarge P ulong 2000
545plong r
546pnum len P
547pnum get P 5
548ret 7
549end
550"""
551put("g8a", g8a, W([0, -12, 1000, 42, -12, 0, 0, 2000, 42], 7))
552g8b = """note gate-pools 8: n times the element size at or past 2^63 is -22 with nothing changed; just below it the
553note host refuses (-12).
554global P ulong *
555global U uchar *
556global ob uchar 24
557""" + PNUM + """fn main to int
558r = enlarge P ulong 1152921504606846976
559plong r
560pnum len P
561r = enlarge P ulong 18446744073709551615
562plong r
563r = enlarge P ulong 1152921504606846975
564plong r
565pnum len P
566r = enlarge U ulong 9223372036854775808
567plong r
568r = enlarge U ulong 9223372036854775807
569plong r
570pnum len U
571r = enlarge P ulong 3
572plong r
573put P 2 11
574r = enlarge P ulong 2305843009213693952
575plong r
576pnum len P
577pnum get P 2
578ret 5
579end
580"""
581put("g8b", g8b, W([-22, 0, -22, -12, 0, -22, -12, 0, 0, -22, 3, 11], 5))
582g8c = """note gate-pools 8 (recorded): touch 128 MiB of a pool, one byte per page. Under
583note systemd-run --user --scope -p MemoryMax=64M the expected result is the kernel's OOM kill (137).
584global U uchar *
585fn main to int
586r = enlarge U ulong 134217728
587if ne r 0
588ret 3
589end
590i = ulong 0
591while lt i 134217728 bound 40000
592put U i 1
593i = add i 4096
594end
595ret 0
596end
597"""
598put("g8c", g8c)
599
600# ---------------------------------------------------------------- gate 9: untouched pages
601g9 = """note gate-pools 9: a 2 GiB pool with one page touched adds about one page of VmRSS. Prints the length,
602note then VmRSS (kB) before the grow, after touching one page, and after touching 1024 more (the control).
603global P uchar *
604global sb uchar 4096
605global ob uchar 24
606text pth "/proc/self/status"
607""" + PNUM + RSS + """fn main to int
608a = rss
609a = rss
610r = enlarge P ulong 2147483648
611if ne r 0
612ret 3
613end
614put P 12345678 1
615b = rss
616i = ulong 0
617while lt i 1024
618put P add 1000000000 mul i 4096 1
619i = add i 1
620end
621c = rss
622pnum len P
623pnum a
624pnum b
625pnum c
626ret 0
627end
628"""
629put("g9", g9)
630
631# ---------------------------------------------------------------- section S: server
632NREQ = 2000
633srv = """note gate-pools S (design section 11): 2000 requests of growing and shrinking sizes (a fixed 64-bit LCG,
634note 1 byte .. 64 MiB; the first 8 ramp to the 64 MiB high-water mark) served from one pool that is enlarged
635note only past its high-water mark and reused. Prints the high-water mark, enlarge calls, new marks, VmRSS (kB)
636note after the high-water point (request 8) and at the end, and a checksum of the bytes served.
637note Control: with the byte L on stdin, requests 8..23 are served from fresh memory past the old end (a
638note server that enlarges per request); its VmRSS must rise past the high-water mark.
639global P uchar *
640global sb uchar 4096
641global mb uchar 1
642global ob uchar 24
643text pth "/proc/self/status"
644""" + PNUM + RSS + """fn serve q ulong b ulong sz ulong to ulong
645cs = ulong 0
646o = ulong 0
647while lt o sz bound 20000
648put P add b o uchar and add q o 255
649cs = add cs ulong get P add b o
650o = add o 4096
651end
652ret cs
653end
654fn main to int
655leak = false
656k = read 0 mb 0 1
657if gt k 0
658leak = eq get mb 0 76
659end
660x = ulong 12345
661hw = ulong 0
662calls = ulong 0
663marks = ulong 0
664rhw = ulong 0
665cs = ulong 0
666q = ulong 0
667while lt q %d
668x = add mul x 6364136223846793005 1442695040888963407
669sz = add rem shr x 33 67108864 1
670if lt q 8
671sz = mul add q 1 8388608
672end
673b = ulong 0
674if and leak ge q 8
675if eq q 24
676break
677end
678sz = add rem sz 4194304 1
679b = len P
680r = enlarge P add b sz
681calls = add calls 1
682if ne r 0
683ret 4
684end
685end
686if gt sz hw
687r = enlarge P sz
688calls = add calls 1
689if ne r 0
690ret 3
691end
692hw = sz
693marks = add marks 1
694end
695cs = add cs serve q b sz
696if eq q 8
697rhw = rss
698end
699q = add q 1
700end
701pnum hw
702pnum calls
703pnum marks
704pnum rhw
705pnum rss
706pnum cs
707ret 0
708end
709""" % NREQ
710put("srv", srv)
711x = 12345
712hw = calls = marks = cs = 0
713for q in range(NREQ):
714 x = (x * 6364136223846793005 + 1442695040888963407) % M
715 sz = ((x >> 33) % 67108864) + 1
716 if q < 8:
717 sz = (q + 1) * 8388608
718 if sz > hw:
719 calls += 1; hw = sz; marks += 1
720 cs += (q & 255) * ((sz + 4095) // 4096)
721with open(os.path.join(OUT, "srv.want"), "w") as f:
722 f.write("hw %d\ncalls %d\nmarks %d\ncs %d\n" % (hw, calls, marks, cs % M))
723WROTE.append("srv.want")
724
725# ---------------------------------------------------------------- gate 10: refusals
726PM = "global P ulong *\n"
727errs = {
728 # name: (source, line or '*', code)
729 "err-fnmode": (PM + "fn f to long\nr = enlarge P ulong 4\nret r\nend\n", "*", 9),
730 "err-ir": ("ir\n" + PM + "fn main to int\nret 0\nend\n", 2, 9),
731 "err-x86efi": ("target x86efi\n" + PM + "fn main to int\nr = enlarge P ulong 4\nput P 0 1\nret int get P 0\nend\n", "*", 25),
732 "err-arg": ("om2\n" + PM + "fn f a view ulong * to ulong\nret len a\nend\nfn main to int\nr = enlarge P ulong 4\nx = f P\nret 0\nend\n", 8, 19),
733 "err-part": ("om2\n" + PM + "fn f a view ulong * to ulong\nret len a\nend\nfn main to int\nr = enlarge P ulong 4\nx = f part P 0 2\nret 0\nend\n", 8, 19),
734 "err-expr": (PM + "fn main to int\nif eq enlarge P ulong 4 0\nret 1\nend\nret 0\nend\n", 3, 9),
735 "err-sum": (PM + "fn main to int\nr = add enlarge P ulong 4 0\nret 0\nend\n", 3, 9),
736 "err-stmt": (PM + "fn main to int\nenlarge P ulong 4\nret 0\nend\n", 3, 16),
737 "err-sized": ("global G ulong 4\nfn main to int\nr = enlarge G ulong 8\nret 0\nend\n", 3, 7),
738 "err-local": ("fn main to int\na = new ulong 4 0\nr = enlarge a ulong 8\nret 0\nend\n", 3, 7),
739 "err-view": ("om2\nfn f a edit ulong * to long\nr = enlarge a ulong 8\nret r\nend\nfn main to int\nret 0\nend\n", 3, 7),
740 "err-bool": ("global P bool *\nfn main to int\nret 0\nend\n", 1, 9),
741 "err-nint": (PM + "fn main to int\nr = enlarge P int 4\nret 0\nend\n", 3, 7),
742 "err-nlong": (PM + "fn main to int\nn = long 4\nr = enlarge P n\nret 0\nend\n", 4, 7),
743 "err-rint": (PM + "fn main to int\nr = int 0\nr = enlarge P ulong 4\nret 0\nend\n", 4, 7),
744 "err-devctl": ("global P uchar *\nfn main to int\nr = devctl neg int 1 uint 21531 P 0 8\nret 0\nend\n", 3, 7),
745 "err-mapwrite": ("global P uchar *\nfn main to int\nh = long 0\nr = mapwrite h 0 P 0 1\nret 0\nend\n", 4, 7),
746 "err-struct": ("om2\nstruct Pr a ulong b ulong end\n" + PM + "fn f p view Pr to ulong\nret 0\nend\nfn main to int\nx = f P\nret 0\nend\n", 8, 7),
747}
748for n, (src, ln, code) in errs.items():
749 put(n, src + "note gate-pools 10: refused with error %d\n" % code,
750 "omc: line %s: error %d\n" % (ln, code))
751
752# ---------------------------------------------------------------- gate 3: read from a pipe across grows
753gr = """note gate-pools 3: a uchar pool filled by read 0 P off n from a pipe, n given by a function that enlarges P
754note (and a blocker B above it) by 65536 elements before every read; then the bytes are written back and their
755note count printed. The gate feeds it `seq 1 200000` through a pipe; its expected output is built there.
756global B uchar *
757global P uchar *
758global ob uchar 24
759""" + PNUM + """fn gn n ulong to ulong
760r = enlarge B add len B 4096
761r = enlarge P add len P n
762ret n
763end
764fn main to int
765r = enlarge B ulong 1
766r = enlarge P ulong 1
767used = ulong 0
768go = true
769while go bound 100000
770k = read 0 P used gn 65536
771if lt k 0
772ret 2
773end
774if eq k 0
775go = false
776else
777used = add used ulong k
778end
779end
780o = ulong 0
781while lt o used bound 100000
782k = write 1 P o sub used o
783if le k 0
784ret 3
785end
786o = add o ulong k
787end
788pnum used
789ret 0
790end
791"""
792put("gr", gr)
793print("wrote", len(WROTE), "files")