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 / ng / tests / nocaps / gate.om

1576 lines · 39407 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/tests/nocaps/gate.om: the no-caps gate of ng (NgNoCaps, 2026-11-11; Drake: "no hard caps on our own
3note software ... put a TEST that will alarm"). Handwritten seeded Omega, program mode, Linux AArch64. The child and
4note file helpers follow seed/ng/front/gate-front-ir.om; seed/ng/sha256.om supplies sh_dat, sh_all and sh_dig.
5note Build: cat seed/ng/sha256.om seed/ng/tests/nocaps/gate.om | seed/out/omc > nocaps-gate
6note Run from the repository root: nocaps-gate OMC OMC_SHA256 SCRATCH [NG]
7note OMC the oracle compiler; its sha256 must be OMC_SHA256 (64 lowercase hex) or nothing runs (INVALID)
8note SCRATCH a new directory (created 0700; an existing one is INVALID)
9note NG an ng binary to judge in place of the one this gate builds from seed/ng/ng.units (the negative
10note control: ng from before the no-caps arena must FAIL here); with NG no mutant is built
11note 1. Units far past every fixed table ng's front, its ΩIR builder, reader and writer, and its a64 back end had
12note until the no-caps arena (src/ir.om ar_*): each is generated into SCRATCH (u.om, and the same bytes after
13note the mode lines `@ng front-check` and `@ng front-ir`) from the case table g_cs below, never stored.
14note 2. Per case NAME WANT OMC KIND: OMC compiles the unit and must exit OMC (0, or a code-generator limit of omc's
15note own, D6: 12); when 0 its binary must exit WANT. ng `@ng front-check` must exit 0, or exactly omc's code
16note with omc's stderr bytes when KIND is d (an om2 diag unit: the stderr records are compared in full). KIND
17note r: ng `@ng front-ir` exits 0, `@ng a64` of its ΩIR exits 0, and that ELF, run, exits WANT. KIND c and d stop
18note after the check. A line per case: ok NAME, the exits, ng's milliseconds per stage and the bytes of the unit.
19note 3. Mutants (with no NG): each re-imposes one of the old fixed tables or loop bounds, or breaks the arena's growth, in the
20note composed units of seed/ng/ng.units (pattern FROM present exactly once, replaced by TO); each must make a case
21note fail (KILLED; its own case is tried first). A control: case 1 judged with WANT + 1 must fail.
22note 4. The usage alarm (OmcNoCaps's gate-usage, for ng): ng `@ng front-check` of the largest real units in this
23note repository, each after a `usage` line (seed/node/journal-gate.om and ng's own units joined), writes its ng-use
24note record (unit 0 was seed/omc/omc.om until omc declared a run-time pool: ng refuses that as scope, exit 64);
25note the arena top must stay at or below 10% of the arena and every group at or below 5%, and one check at or
26note below 2 s; past a threshold the gate FAILs with ALARM, the number and the threshold. Its control: ng with
27note the arena shrunk to 1048576 words must trip the alarm (with no NG).
28note Deadline: every child is killed after 600 s (NOT_RUN, never PASS).
29note Output: lines per case, mutant, control and unit, then
30note NOCAPSGATE PASS|FAIL|NOT_RUN cases=N fail=F mutants=M killed=K controls=C tripped=T notrun=U
31note Exit 0 PASS, 1 FAIL, 2 INVALID, 3 a tool did not build, 4 NOT_RUN. Globals g_*, functions gn_*.
32text g_w "seed/ng/ ng.units ng ngm src.om u.om fc.in fi.in ir ai elf bin e0 e1 e2 e3 nul o0 o1 berr us.in seed/node/journal-gate.om uo "
33text g_m "FAIL |ok |: omc exit |: omc binary exit |: ng front-check exit |: ng front-ir exit |: ng a64 exit |: program exit |, want |: front-check stderr differs from omc's|NOCAPSGATE PASS|NOCAPSGATE FAIL|NOCAPSGATE INVALID: | cases=| fail=| mutants=| killed=|usage: nocaps-gate OMC OMC_SHA256 SCRATCH [NG]|oracle sha256 differs from OMC_SHA256|scratch exists or cannot be made|build failed: |mutant |: survived every case|: killed by |: pattern not present exactly once|control |: not tripped|: tripped by | ms: check |, ir |, a64 |, elf | (unused)| (unused)| omc=| ng=|NOT_RUN |: a child passed the 600 s deadline| notrun=|: cannot write scratch| bytes=|usage |ALARM |: no ng-use record|: arena top | words, | controls=| tripped=|: front-check took | ms (threshold 2000 ms)|% of the arena (threshold 10%)|NOCAPSGATE NOT_RUN|: group |% of the arena (threshold 5%)| top=| largest=| ms|control usage: arena of 1048576 words|"
34text g_pfc "@ng front-check\n"
35text g_pfr "@ng front-ir\n"
36text g_pa64 "@ng a64\n"
37text g_use "usage\n"
38note the pieces of the generated units (g_t, separated by |, numbered from 0)
39text g_t "|global n| ulong 1\n|fn main to int\nput n0 0 3\nput n99999 0 4\nret int add get n0 0 get n99999 0\nend\n|text t| \"ab\"\n|fn main to int\nx = len t0\ny = len t99999\nret int add x y\nend\n|global long_global_name_| uint 1\n|fn main to int\nput long_global_name_0 0 uint 5\nput long_global_name_99999 0 uint 7\nret int add get long_global_name_0 0 get long_global_name_99999 0\nend\n|fn q| to ulong\nret |\nend\n|fn main to int\na = q0\nb = q59999\nret int rem add a b 256\nend\n|fn inc x ulong to ulong\nret add x 1\nend\nfn main to int\nx = ulong 0\n|x = inc x\n|ret int rem x 256\nend\n|note pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\n|fn main to int\nx = int 41\nx = add x 1\nret x\nend\n|fn main to int\nx = ulong 1\n|if eq x 1\n|ret 9\n|end\n|ret 0\nend\n|fn main to int\nx = ulong 0\n|while true\nx = add x 1\nbreak\nend\n|y = ulong 0\nwhile lt y 1\ny = add y 1\nx = add x 1\ncontinue\nend\n|fn main to int\nx = |add |ulong 0| ulong 1|\nret int rem x 256\nend\n|fn inc x ulong to ulong\nret add x 1\nend\nfn main to int\nx = |inc |ulong 0\nret int rem x 256\nend\n|fn main to int\n|a| = new ulong 1 |\n|x = get a9999 0\nret int rem x 256\nend\n|om2\n|fn ia| x int to int inline\nret add x 1\nend\n|om2 diag\nfn main to int\nx = long 0\n|x = add x long 1\n|ret int rem x long 256\nend\n|| \"|aaaaaaaaaaaaaaaa|\"\n|fn main to int\nx = len t0\ny = len t16\nret int rem add x y 256\nend\n|abc| x int to int\n|x = ia| x\n|ret x\nend\n|fn main to int\nx = int 0\n|x = fg|ret rem x 256\nend\n|fn inc x ulong to ulong\nret add x 1\nend\n| x ulong to ulong\ny = x\n|y = inc y\n|ret y\nend\n|x = q|neg |long 1\nret int rem x long 256\nend\n|not ||add ulong 1 |fn fg|fn f6 a ulong b ulong c ulong d ulong e ulong g ulong to ulong\nret add a 1\nend\nfn main to int\nx = |f6 | ulong 1 ulong 1 ulong 1 ulong 1 ulong 1|fn f x long to long\n|x = add x 1\n|ret x\nend\nfn main to int\nret int rem f long 1 256\nend\n|ret x\nend\nfn main to int\nret int rem f long 9223372036854506807 256\nend\n|om2\nfn ia x int to int inline\n|if eq x 1\nret 9\nend\n|ret x\nend\nfn main to int\nx = ia int 41\nret x\nend\n|\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|fn main to int\nret int rem len t 256\nend\n|"
40note the cases: NAME WANT OMC KIND SPEC..., SPEC tokens Lk (piece k), Rk:N (piece k, N times), Nk:m:p:N (for i in
41note 0 .. N-1: piece k, i, then piece m and i again when m is not 0, then piece p), I:A:B (the inline-edges unit),
42note C:F:K (F functions of K calls each, main calling them all), T:K (K texts of 1 MiB, the last 3 bytes longer).
43note KIND r: check, front-ir, a64, the ELF; i: check and front-ir (ng's a64 stage refuses these for a reason named
44note below, never a table of the front or the ΩIR); c and d: the check only (d an om2 diag unit, stderr compared).
45note Each is past an old fixed table: names100k (front names 8192, front-ir 8192, ΩIR reader 65536 globals, a64
46note 65537 addresses), texts100k, long100k (long names 4096), fns60k (functions 4096), calls1m (calls 524288; its
47note ΩIR is 21 MB, past the 16 MiB payload and output buffers; one function of 2,000,009 wires is past what a64's
48note per-wire tables, 10 words a wire, take in the arena: i), calls1100k (1,100,000 calls in all: a64's 1048576
49note call sites), calls524289 (the formerly ngcap row: a64's 262144 wires a function), in64m (input 8 MiB),
50note nest5000 (blocks 512, front-ir stack 1024; a64's liveness, blocks x wires / 64 words, is 7,035,471 words a
51note bitset, past the arena: i), nest3000 (a64 liveness 2.5 M words, past its 2097152), nest1100 (a function of
52note over 1000 blocks: a64 read block 1000 and up as a trap label), breaks3000 / conts3000 (1024 each; a64
53note liveness: i), value5000 (value nesting 1024; omc 12), callnest5000, call6nest12000 (front-ir call arguments
54note 65536: 72000 here), snap2m (front-ir name snapshots 1048576), arrays10k (front-ir local arrays 8192; omc 12, a64's frame:
55note `unsupported`, i), inline22k (inline edges 16384; omc c52e986e and 1e628c80 trapped 3 past 64 inline edges, fixed
56note in omc 2495bc25, omega-mv 83507124: omc compiles it and its binary exits 228), diag1m (om2 diag site records 8 MiB), texts17m (ΩIR global
57note data 16 MiB, a64 code image 16 MiB), and the deepest value shapes at 32767 levels (d*32767: the stack-derived
58note bound of 32768; daddr's right-nested adds need a frame past a64's 4095 bytes: i).
59note Old loop bounds of the front and a64 (trap 4 or a64's `unsupported` before the no-caps review): inlrets1m (an
60note inline frame's rets walked by fe_inl_pat, 1,000,000 passes: 1,000,001 reachable rets in one inline body called
61note once, one inline edge; its front-ir is refused, class 23, by the ΩIR format's 65536 blocks a function, IR.md
62note s12: c), text16m (fe_ltxb, a front-ir pass a text byte, 16777216: one literal of 16,777,219 bytes), lalc16m
63note (fe_lalc's read-ahead, a pass a blank line and two a statement line, 16777216: 16,777,232 blank lines in main's
64note outermost block), fix270k (a64's 262144 branch fixups a function: one overflow branch each), fixtrap270k (the
65note same function overflowing: a trap branch patched past the old table, exit 101).
66text g_cs "names100k 7 0 r N1:0:2:100000 L3\ntexts100k 4 0 r N4:0:5:100000 L6\nlong100k 12 0 r N7:0:8:100000 L9\nfns60k 95 0 r N10:11:12:60000 L13\ncalls1m 64 0 i L14 R15:1000000 L16\ncalls1100k 224 0 r C:1100:1000\ncalls524289 1 0 r L14 R15:524289 L16\nin64m 42 0 r R17:671088 L18\nnest5000 9 0 i L19 R20:5000 L21 R22:5000 L23\nnest3000 9 0 r L19 R20:3000 L21 R22:3000 L23\nnest1100 9 0 r L19 R20:1100 L21 R22:1100 L23\nbreaks3000 184 0 i L24 R25:3000 L16\nconts3000 184 0 i L24 R26:3000 L16\nvalue5000 136 12 r L27 R28:5000 L29 R30:5000 L31\ncallnest5000 136 0 r L32 R33:5000 L34\ncall6nest12000 224 0 r L70 R71:12000 L29 R72:12000 L31\nsnap2m 9 0 r N1:0:2:1000 L19 R20:2000 L21 R22:2000 L23\narrays10k 15 12 i L35 N36:37:38:10000 L39\ninline22k 228 0 c L40 I:150:150\ndiag1m 0 0 d L43 R44:1000000 L45\ntexts17m 3 0 r T:17\ndneg32767 255 12 r L27 R64:32767 L65\ndadd32767 255 12 r L27 R28:32767 L29 R30:32767 L31\ndcall32767 255 24 r L32 R33:32767 L34\ndnot32767 255 12 r L27 R66:32767 L34\ndaddr32767 255 12 i L27 R68:32767 L34\ninlrets1m 41 0 c L77 R78:1000001 L79\ntext16m 3 0 r L4 L47 R48:1048576 L51 L49 L81\nlalc16m 1 0 r L19 R80:1048577 L16\nfix270k 177 0 r L73 R74:270000 L75\nfixtrap270k 101 0 r L73 R74:270000 L76\n"
67global g_wo uint 64
68global g_wl uint 64
69global g_mo uint 128
70global g_ml uint 128
71global g_to uint 128
72global g_tl uint 128
73global g_omc uchar 4096
74global g_scr uchar 4096
75global g_pa uchar 8192
76global g_av uchar 16384
77global g_b1 uchar 16777216
78global g_b2 uchar 16777216
79global g_gb uchar 1048576
80global g_gf int 3
81global g_o uchar 4096
82global g_stb uchar 4
83global g_hx uchar 128
84global g_ng uchar 4096
85global g_mf uchar 256
86global g_mt uchar 512
87global g_n ulong 48
88note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 b1 length, 6 b2 length,
89note 7 generator buffer fill, 8 case cursor in g_cs, 9 out length, 10 cases, 11 failed cases, 12 quiet, 13 current
90note case failed (1) or NOT_RUN (2), 14 name start, 15 name end, 16 a child passed the deadline, 17 mutants, 18 killed,
91note 19 controls, 20 tripped, 21 NOT_RUN cases, 22 NG given, 23 WANT adjustment (control), 24 spec cursor, 25 spec
92note end, 26 unit bytes, 27 mutant FROM length, 28 mutant TO length, 29 ng binary word (2 or 3), 30 alarms,
93note 31 last front-check ms, 32 ng-use top, 33 ng-use arena, 34 largest group words, 35 its label start, 36 its end
94
95note ---- words and output -------------------------------------------------------------------------------
96fn gn_split t ulong to void
97w = ulong 0
98s = ulong 0
99if eq t 0
100for i ulong len g_w bound 4096
101if eq get g_w i 32
102put g_wo w uint s
103put g_wl w uint sub i s
104w = add w 1
105s = add i 1
106end
107end
108end
109if eq t 1
110for i ulong len g_m bound 8192
111if eq get g_m i 124
112put g_mo w uint s
113put g_ml w uint sub i s
114w = add w 1
115s = add i 1
116end
117end
118end
119if eq t 2
120for i ulong len g_t bound 65536
121if eq get g_t i 124
122put g_to w uint s
123put g_tl w uint sub i s
124w = add w 1
125s = add i 1
126end
127end
128end
129end
130fn gn_init to void
131gn_split 0
132gn_split 1
133gn_split 2
134put g_n 29 2
135end
136fn gn_c b ulong to void
137n = get g_n 9
138if lt n len g_o
139put g_o n uchar b
140put g_n 9 add n 1
141end
142end
143fn gn_nl to void
144gn_c 10
145r = write 1 g_o 0 get g_n 9
146put g_n 9 0
147end
148fn gn_say i ulong to void
149s = ulong get g_mo i
150for j ulong ulong get g_ml i bound 256
151gn_c ulong get g_m add s j
152end
153end
154fn gn_num v ulong to void
155if ge v 10
156gn_num div v 10
157end
158gn_c add 48 rem v 10
159end
160fn gn_name to void
161for p ulong sub get g_n 15 get g_n 14 bound 256
162gn_c ulong get g_cs add get g_n 14 p
163end
164end
165note a failure of the current case (FAIL NAME<message i>), unless quiet
166fn gn_fail i ulong to void
167put g_n 13 1
168if eq get g_n 12 0
169gn_say 0
170gn_name
171gn_say i
172end
173end
174fn gn_failv i ulong v ulong w ulong to void
175gn_fail i
176if eq get g_n 12 0
177gn_num v
178gn_say 8
179gn_num w
180gn_nl
181end
182end
183
184note ---- paths and files ----------------------------------------------------------------------------------
185fn gn_pclr to void
186put g_n 0 0
187end
188fn gn_pc c ulong to void
189n = get g_n 0
190if lt n len g_pa
191put g_pa n uchar c
192put g_n 0 add n 1
193end
194end
195fn gn_pw i ulong to void
196s = ulong get g_wo i
197for j ulong ulong get g_wl i bound 64
198gn_pc ulong get g_w add s j
199end
200end
201note scratch file word i
202fn gn_ps i ulong to void
203gn_pclr
204for j ulong get g_n 2 bound 4096
205gn_pc ulong get g_scr j
206end
207gn_pw i
208end
209fn gn_open fl ulong to int
210r = fopen g_pa 0 get g_n 0 int fl 420
211if lt r 0
212ret -1
213end
214ret int r
215end
216fn gn_rdonly to int
217ret gn_open 524288
218end
219fn gn_wronly to int
220ret gn_open 524865
221end
222fn gn_exe to int
223r = unlink g_pa 0 get g_n 0
224x = fopen g_pa 0 get g_n 0 524865 493
225if lt x 0
226ret -1
227end
228ret int x
229end
230fn gn_fclo fd int to void
231if ge fd 0
232r = fclose fd
233end
234end
235note write b1[0, n) to fd; false on a short write
236fn gn_wr fd int n ulong to bool
237o = ulong 0
238while lt o n bound 16777217
239x = write fd g_b1 o sub n o
240if le x 0
241ret false
242end
243o = add o ulong x
244end
245ret true
246end
247note read the file at g_pa into b1 at offset o; its length, or 2^63 when unreadable or too big
248fn gn_slurp o ulong to ulong
249fd = gn_rdonly
250if lt fd 0
251ret shl ulong 1 63
252end
253n = o
254ok = true
255while true bound 16777218
256x = read fd g_b1 n sub len g_b1 n
257if lt x 0
258ok = false
259break
260end
261if eq x 0
262break
263end
264n = add n ulong x
265if ge n len g_b1
266ok = false
267break
268end
269end
270gn_fclo fd
271if not ok
272ret shl ulong 1 63
273end
274ret sub n o
275end
276note read up to m bytes of fd into b1 (k 1) or b2 (k 2); the count (0 at the end)
277fn gn_rdn fd int k ulong m ulong to ulong
278n = ulong 0
279while lt n m bound 1048577
280x = long 0
281if eq k 1
282x = read fd g_b1 n sub m n
283else
284x = read fd g_b2 n sub m n
285end
286if le x 0
287ret n
288end
289n = add n ulong x
290end
291ret n
292end
293fn gn_eqn n ulong to bool
294for j ulong n bound 1048576
295if ne get g_b1 j get g_b2 j
296ret false
297end
298end
299ret true
300end
301note the scratch files w1 and w2 hold the same bytes
302fn gn_fcmp w1 ulong w2 ulong to bool
303gn_ps w1
304f1 = gn_rdonly
305gn_ps w2
306f2 = gn_rdonly
307ok = and ge f1 0 ge f2 0
308dn = false
309while and ok not dn bound 65536
310a = gn_rdn f1 1 1048576
311b = gn_rdn f2 2 1048576
312if ne a b
313ok = false
314else
315if eq a 0
316dn = true
317end
318ok = gn_eqn a
319end
320end
321gn_fclo f1
322gn_fclo f2
323ret ok
324end
325note scratch file d = the mode line text m (0 a64, 1 front-check) then the bytes of scratch file s
326fn gn_pref m ulong s ulong d ulong to bool
327n = ulong 0
328if eq m 0
329n = len g_pa64
330for j ulong n bound 64
331put g_b1 j get g_pa64 j
332end
333else
334n = len g_use
335for j ulong n bound 64
336put g_b1 j get g_use j
337end
338end
339gn_ps d
340fo = gn_wronly
341if lt fo 0
342ret false
343end
344ok = gn_wr fo n
345if eq m 2
346ok = and ok gn_wr fo 0
347end
348gn_ps s
349fi = gn_rdonly
350dn = false
351while and ok not dn bound 65536
352if lt fi 0
353ok = false
354else
355k = gn_rdn fi 1 1048576
356if eq k 0
357dn = true
358else
359ok = gn_wr fo k
360end
361end
362end
363gn_fclo fi
364gn_fclo fo
365ret ok
366end
367
368note ---- children ------------------------------------------------------------------------------------
369fn gn_aclr to void
370put g_n 3 2
371put g_n 4 0
372end
373fn gn_apa to void
374p = get g_n 3
375n = get g_n 0
376for j ulong n bound 8192
377put g_av add add p 2 j get g_pa j
378end
379put g_av p uchar and n 255
380put g_av add p 1 uchar shr n 8
381put g_n 3 add p add n 2
382c = add get g_n 4 1
383put g_n 4 c
384put g_av 0 uchar and c 255
385put g_av 1 uchar shr c 8
386end
387fn gn_redir s int d int to void
388if ne dupfd s d 0 long d
389exit 127
390end
391end
392note run the argument list with stdin, stdout, stderr fds (closed here); the exit code, 256 + the signal, 1000
393note when the child passed the 600 s deadline (killed; g_n 16 = 1)
394fn gn_spawn fi int fo int fe int to ulong
395if or lt fi 0 or lt fo 0 lt fe 0
396gn_fclo fi
397gn_fclo fo
398gn_fclo fe
399ret 512
400end
401pid = fork
402if lt pid 0
403exit 2
404end
405if eq pid 0
406gn_redir fi 0
407gn_redir fo 1
408gn_redir fe 2
409r = execprog g_av 0 get g_n 3
410exit 127
411end
412gn_fclo fi
413gn_fclo fo
414gn_fclo fe
415t0 = monons
416while true bound 1000000000
417r = waitpid int pid g_stb 0 len g_stb 1
418if eq r pid
419x = ulong get g_stb 0
420if ne x 0
421ret add 256 x
422end
423ret ulong get g_stb 1
424end
425if lt r 0
426exit 2
427end
428if gt sub monons t0 600000000000
429r = killpid int pid 9
430r = waitpid int pid g_stb 0 len g_stb 0
431put g_n 16 1
432ret 1000
433end
434q = sleepns 200000
435end
436exit 2
437end
438note run scratch program p with stdin scratch i, stdout scratch o (an executable when ex), stderr scratch e
439fn gn_run p ulong i ulong o ulong ex bool e ulong to ulong
440gn_ps i
441fi = gn_rdonly
442gn_aclr
443gn_ps p
444gn_apa
445gn_ps o
446fo = int -1
447if ex
448fo = gn_exe
449else
450fo = gn_wronly
451end
452gn_ps e
453fe = gn_wronly
454ret gn_spawn fi fo fe
455end
456note OMC with stdin scratch i, stdout scratch o (an executable), stderr scratch e
457fn gn_omc i ulong o ulong e ulong to ulong
458gn_ps i
459fi = gn_rdonly
460gn_aclr
461gn_pclr
462for j ulong get g_n 1 bound 4096
463gn_pc ulong get g_omc j
464end
465gn_apa
466gn_ps o
467fo = gn_exe
468gn_ps e
469fe = gn_wronly
470ret gn_spawn fi fo fe
471end
472note milliseconds since t0
473fn gn_ms t0 long to ulong
474ret ulong div sub monons t0 1000000
475end
476
477note ---- the generator ------------------------------------------------------------------------------
478note g_gb is flushed to the g_gf files (u.om, fc.in, fi.in) when full and at the end
479fn gn_gflush to bool
480n = get g_n 7
481ok = true
482for f ulong 3
483fd = get g_gf f
484o = ulong 0
485while and ok lt o n bound 1048577
486x = write fd g_gb o sub n o
487if le x 0
488ok = false
489else
490o = add o ulong x
491end
492end
493end
494put g_n 26 add get g_n 26 n
495put g_n 7 0
496ret ok
497end
498fn gn_gc c ulong to void
499n = get g_n 7
500if ge n len g_gb
501z = gn_gflush
502n = ulong 0
503end
504put g_gb n uchar c
505put g_n 7 add n 1
506end
507fn gn_gt k ulong to void
508s = ulong get g_to k
509for j ulong ulong get g_tl k bound 4096
510gn_gc ulong get g_t add s j
511end
512end
513fn gn_gn v ulong to void
514if ge v 10
515gn_gn div v 10
516end
517gn_gc add 48 rem v 10
518end
519note the next decimal number of the spec at g_n 24 (stops at ':', ' ' or the end of the line)
520fn gn_snum to ulong
521v = ulong 0
522p = get g_n 24
523while lt p get g_n 25 bound 32
524c = ulong get g_cs p
525if or lt c 48 gt c 57
526put g_n 24 add p 1
527ret v
528end
529v = add mul v 10 sub c 48
530p = add p 1
531end
532put g_n 24 p
533ret v
534end
535note the inline-edges unit (I:A:B): A inline functions ia0.., B functions f0.. each calling every inline function on
536note x, main calling every f on x: B * A edges from a function to an inline function, each recorded once
537fn gn_ginl a ulong b ulong to void
538for k ulong a bound 100000
539gn_gt 41
540gn_gn k
541gn_gt 42
542end
543for j ulong b bound 100000
544gn_gt 69
545gn_gn j
546gn_gt 52
547for k ulong a bound 100000
548gn_gt 53
549gn_gn k
550gn_gt 54
551end
552gn_gt 55
553end
554gn_gt 56
555for j ulong b bound 100000
556gn_gt 57
557gn_gn j
558gn_gt 54
559end
560gn_gt 58
561end
562note the spread-calls unit (C:F:K): F functions q0.. of K calls each, main calling every q on x
563fn gn_gcall f ulong k ulong to void
564gn_gt 59
565for j ulong f bound 100000
566gn_gt 10
567gn_gn j
568gn_gt 60
569for i ulong k bound 100000
570gn_gt 61
571end
572gn_gt 62
573end
574gn_gt 24
575for j ulong f bound 100000
576gn_gt 63
577gn_gn j
578gn_gt 54
579end
580gn_gt 16
581end
582note the texts unit (T:K): K texts t0.. of 1048576 bytes (the last 3 more), then main reading t0 and the last
583fn gn_gtxt k ulong to void
584for i ulong k bound 4096
585gn_gt 4
586gn_gn i
587gn_gt 47
588for j ulong 65536
589gn_gt 48
590end
591if eq add i 1 k
592gn_gt 51
593end
594gn_gt 49
595end
596gn_gt 50
597end
598note generate the case's unit (spec tokens from g_n 24 to g_n 25) into u.om, fc.in and fi.in; false when a
599note file cannot be written
600fn gn_gen to bool
601put g_n 26 0
602put g_n 7 0
603gn_ps 5
604put g_gf 0 gn_wronly
605gn_ps 6
606put g_gf 1 gn_wronly
607gn_ps 7
608put g_gf 2 gn_wronly
609ok = and ge get g_gf 0 0 and ge get g_gf 1 0 ge get g_gf 2 0
610if ok
611for j ulong len g_pfc bound 64
612put g_gb j get g_pfc j
613end
614o = ulong 0
615x = write get g_gf 1 g_gb 0 len g_pfc
616for j ulong len g_pfr bound 64
617put g_gb j get g_pfr j
618end
619x = write get g_gf 2 g_gb 0 len g_pfr
620while lt get g_n 24 get g_n 25 bound 64
621p = get g_n 24
622c = ulong get g_cs p
623put g_n 24 add p 1
624if eq c 76
625gn_gt gn_snum
626end
627if eq c 82
628k = gn_snum
629n = gn_snum
630for i ulong n bound 16777216
631gn_gt k
632end
633end
634if eq c 78
635k = gn_snum
636m = gn_snum
637q = gn_snum
638n = gn_snum
639for i ulong n bound 16777216
640gn_gt k
641gn_gn i
642if ne m 0
643gn_gt m
644gn_gn i
645end
646gn_gt q
647end
648end
649if eq c 73
650put g_n 24 add get g_n 24 1
651a = gn_snum
652b = gn_snum
653gn_ginl a b
654end
655if eq c 67
656put g_n 24 add get g_n 24 1
657a = gn_snum
658b = gn_snum
659gn_gcall a b
660end
661if eq c 84
662put g_n 24 add get g_n 24 1
663gn_gtxt gn_snum
664end
665end
666ok = gn_gflush
667end
668gn_fclo get g_gf 0
669gn_fclo get g_gf 1
670gn_fclo get g_gf 2
671ret ok
672end
673
674note ---- one case -----------------------------------------------------------------------------------------
675note fields of the case line at g_n 8: name, WANT, OMC, KIND; the spec's span into g_n 24 and 25; the KIND letter
676note (0 at the end of the table, 1 for a malformed line)
677fn gn_line to ulong
678p = get g_n 8
679e = len g_cs
680if ge p e
681ret 0
682end
683q = p
684while and lt q e ne get g_cs q 10 bound 4096
685q = add q 1
686end
687put g_n 8 add q 1
688s = p
689while and lt p q ne get g_cs p 32 bound 256
690p = add p 1
691end
692put g_n 14 s
693put g_n 15 p
694put g_n 24 add p 1
695put g_n 25 q
696ret 2
697end
698note the current case: the unit generated, then judged by OMC and its binary (gn_omcp), ng's check (gn_chk) and,
699note for KIND r, ng's front-ir, a64 and the ELF (gn_ngrun); a line per case. g_n 37..44: check, ir, a64 and elf
700note milliseconds, omc's exit, its binary's, ng's check exit, the ELF's
701fn gn_case kind ulong want ulong oc ulong to void
702put g_n 13 0
703put g_n 16 0
704if eq get g_n 12 0
705put g_n 10 add get g_n 10 1
706end
707for i ulong 8
708put g_n add 37 i 0
709end
710if not gn_gen
711gn_fail 39
712gn_nl
713ret
714end
715if not gn_omcp kind want oc
716ret
717end
718if not gn_chk kind
719ret
720end
721if or eq kind 114 eq kind 105
722if not gn_ngrun want eq kind 114
723ret
724end
725end
726if eq get g_n 12 0
727gn_say 1
728gn_name
729gn_say 34
730gn_num get g_n 41
731gn_c 47
732gn_num get g_n 42
733gn_say 35
734gn_num get g_n 43
735gn_c 47
736gn_num get g_n 44
737gn_say 40
738gn_num get g_n 26
739gn_say 28
740gn_num get g_n 37
741gn_say 29
742gn_num get g_n 38
743gn_say 30
744gn_num get g_n 39
745gn_say 31
746gn_num get g_n 40
747gn_nl
748end
749end
750note OMC on u.om must exit oc; when 0 (and KIND is not d) its binary must exit WANT (+ g_n 23)
751fn gn_omcp kind ulong want ulong oc ulong to bool
752x = gn_omc 5 11 12
753put g_n 41 x
754if gn_dl
755ret false
756end
757if ne x oc
758gn_failv 2 x oc
759ret false
760end
761if or ne oc 0 eq kind 100
762ret true
763end
764a = gn_run 11 16 17 false 19
765put g_n 42 a
766if gn_dl
767ret false
768end
769w = add want get g_n 23
770if ne a w
771gn_failv 3 a w
772ret false
773end
774ret true
775end
776note ng @ng front-check: exit 0, or for KIND d omc's exit and omc's stderr bytes
777fn gn_chk kind ulong to bool
778t0 = monons
779y = gn_run get g_n 29 6 17 false 13
780put g_n 37 gn_ms t0
781put g_n 43 y
782if gn_dl
783ret false
784end
785if ne kind 100
786if ne y 0
787gn_failv 4 y 0
788ret false
789end
790ret true
791end
792x = get g_n 41
793if ne y x
794gn_failv 4 y x
795ret false
796end
797if not gn_fcmp 12 13
798gn_fail 9
799if eq get g_n 12 0
800gn_nl
801end
802ret false
803end
804ret true
805end
806note ng @ng front-ir, then (full) @ng a64 of its ΩIR, then the ELF: exits 0, 0 and WANT (+ g_n 23)
807fn gn_ngrun want ulong full bool to bool
808t0 = monons
809z = gn_run get g_n 29 7 8 false 14
810put g_n 38 gn_ms t0
811if gn_dl
812ret false
813end
814if ne z 0
815gn_failv 5 z 0
816ret false
817end
818if not full
819ret true
820end
821if not gn_pref 0 8 9
822gn_fail 39
823gn_nl
824ret false
825end
826t0 = monons
827z = gn_run get g_n 29 9 10 true 15
828put g_n 39 gn_ms t0
829if gn_dl
830ret false
831end
832if ne z 0
833gn_failv 6 z 0
834ret false
835end
836t0 = monons
837b = gn_run 10 16 17 false 19
838put g_n 40 gn_ms t0
839put g_n 44 b
840if gn_dl
841ret false
842end
843w = add want get g_n 23
844if ne b w
845gn_failv 7 b w
846ret false
847end
848ret true
849end
850note a child of the current case passed the deadline: NOT_RUN (g_n 13 = 2)
851fn gn_dl to bool
852if eq get g_n 16 0
853ret false
854end
855put g_n 13 2
856if eq get g_n 12 0
857gn_say 36
858gn_name
859gn_say 37
860gn_nl
861end
862ret true
863end
864note the next field of the case line (a number) at g_n 24
865fn gn_fnum to ulong
866ret gn_snum
867end
868note every case (when only is not 0, the case with that number first and, when stop, only until one fails);
869note true when some case failed
870fn gn_all only ulong stop bool to bool
871hit = false
872put g_n 8 0
873k = ulong 0
874while true bound 4096
875r = gn_line
876if eq r 0
877break
878end
879k = add k 1
880want = gn_fnum
881oc = gn_fnum
882kind = ulong get g_cs get g_n 24
883put g_n 24 add get g_n 24 2
884if or eq only 0 eq only k
885gn_case kind want oc
886if eq get g_n 13 1
887hit = true
888if eq get g_n 12 0
889put g_n 11 add get g_n 11 1
890end
891if stop
892ret true
893end
894end
895if eq get g_n 13 2
896if eq get g_n 12 0
897put g_n 21 add get g_n 21 1
898end
899end
900end
901end
902ret hit
903end
904
905note ---- building ng ----------------------------------------------------------------------------------
906note append the file at g_pa to b1 at its length (g_n 5); false when unreadable
907fn gn_cat to bool
908n = gn_slurp get g_n 5
909if ge n shl ulong 1 63
910ret false
911end
912put g_n 5 add get g_n 5 n
913ret true
914end
915note the units of seed/ng/ng.units (lines SHA256 PATH, in order) into b1
916fn gn_units to bool
917put g_n 5 0
918gn_pclr
919gn_pw 0
920gn_pw 1
921fd = gn_rdonly
922if lt fd 0
923ret false
924end
925k = gn_rdn fd 2 1048576
926gn_fclo fd
927s = ulong 0
928for i ulong k bound 1048576
929if eq get g_b2 i 10
930if gt i add s 65
931gn_pclr
932for j ulong sub i add s 65 bound 4096
933gn_pc ulong get g_b2 add add s 65 j
934end
935if not gn_cat
936ret false
937end
938end
939s = add i 1
940end
941end
942ret true
943end
944note write b1[0, g_n 5) to scratch src.om (the usage step reads it as ng's own units, with or without NG)
945fn gn_wsrc to bool
946gn_ps 4
947fd = gn_wronly
948if lt fd 0
949ret false
950end
951ok = gn_wr fd get g_n 5
952gn_fclo fd
953ret ok
954end
955note compile b1[0, g_n 5) with OMC into scratch word o
956fn gn_bld o ulong to bool
957if not gn_wsrc
958ret false
959end
960x = gn_omc 4 o 19
961ret eq x 0
962end
963note copy the file named by argument 4 to scratch ng (an executable)
964fn gn_cpng to bool
965r = argread 4 g_pa 0 4095
966if lt r 1
967ret false
968end
969put g_n 0 ulong r
970put g_n 5 0
971if not gn_cat
972ret false
973end
974gn_ps 2
975fd = gn_exe
976if lt fd 0
977ret false
978end
979ok = gn_wr fd get g_n 5
980gn_fclo fd
981ret ok
982end
983
984note ---- mutants and controls --------------------------------------------------------------------------
985note the mutants: FROM|TO pairs of g_mx (each FROM present exactly once in the composed units), with the number of
986note the case that should kill it
987text g_mx "\nfe_need 4 n\nput ar_m add get ar_rb 4 n w\n|\nif ge n 8192\nfe_fail 14\nend\nfe_need 4 n\nput ar_m add get ar_rb 4 n w\n|\nfe_need 6 k\n|\nif ge k 4096\nfe_fail 14\nend\nfe_need 6 k\n|\nfe_need 8 f\n|\nif ge f 4096\nfe_fail 14\nend\nfe_need 8 f\n|\nfe_need 10 n\n|\nif ge n 524288\nfe_fail 14\nend\nfe_need 10 n\n|\nfe_need 11 n\n|\nif ge n 512\nfe_fail 14\nend\nfe_need 11 n\n|\nfe_need 12 n\n|\nif ge n 1024\nfe_fail 14\nend\nfe_need 12 n\n|\nfe_need 13 n\n|\nif ge n 1024\nfe_fail 14\nend\nfe_need 13 n\n|\nfe_need 14 n\n|\nif ge n 16384\nfe_fail 14\nend\nfe_need 14 n\n|\nif gt get f_depth 0 32768\n|\nif gt get f_depth 0 1024\n|\nfe_need 3 n\n|\nif ge n 8388608\nfe_fail 14\nend\nfe_need 3 n\n|\nret fe_check get ar_inl 0\n|\nif ge get ar_inl 0 8388608\nfe_fail 14\nend\nret fe_check get ar_inl 0\n|\nfe_need 18 n\n|\nif ge n 8192\nfe_lno\nend\nfe_need 18 n\n|\nfe_need 20 d\n|\nif ge d 1024\nfe_lno\nend\nfe_need 20 d\n|\nfe_need 21 add p n0\n|\nif gt add p n0 1048576\nfe_lno\nend\nfe_need 21 add p n0\n|\nfe_need 22 a\n|\nif ge a 8192\nfe_lno\nend\nfe_need 22 a\n|\nfe_need 23 add bs np\n|\nif gt add bs np 65536\nfe_lno\nend\nfe_need 23 add bs np\n|\nif ne ar_need 1 add p k 0\nar_die\nend\n|\nif gt add p k 16777216\nar_die\nend\nif ne ar_need 1 add p k 0\nar_die\nend\n|\nif eq ng_rd 2\nng_bad 23 get ar_inl 0\nend\n|\nif eq ng_rd 2\nng_bad 23 get ar_inl 0\nend\nif gt get ar_inl 0 16777216\nng_bad 23 16777216\nend\n|\nif ne ar_need 2 x 0\nar_die\nend\n|\nif ge x 16777216\nar_die\nend\nif ne ar_need 2 x 0\nar_die\nend\n|\nif ne ar_need 24 add get i_n 2 1 0\n|\nif ge get i_n 2 65536\nir_bad 23 get i_rd 0\nret\nend\nif ne ar_need 24 add get i_n 2 1 0\n|\nif ne ar_need 25 n 0\n|\nif gt n 65536\na6_unsup n\nend\nif ne ar_need 25 n 0\n|\nif ne ar_need 26 add nv 1 0\n|\nif gt nv 262144\na6_unsup nv\nend\nif ne ar_need 26 add nv 1 0\n|\nif ne ar_need 27 mul get a_fs 1 lw 0\n|\nif gt mul get a_fs 1 lw 2097152\na6_unsup lw\nend\nif ne ar_need 27 mul get a_fs 1 lw 0\n|\na6_pmove\nc = get a_ncl 0\nif ne ar_need 28 c 0\n|\na6_pmove\nc = get a_ncl 0\nif ge c 1048576\na6_unsup c\nend\nif ne ar_need 28 c 0\n|\nif gt add o 4 134217728\n|\nif gt add o 4 16777216\n|\nconst a_tlab ulong 4294967296\n|\nconst a_tlab ulong 1000\n|\nar_copy t b o\n|\nar_copy t b 0\n|\nfn fe_inl_pat p0 ulong to void\nput f_nilp 0 p0\n|\nfn fe_inl_pat p0 ulong to void\nn = get f_nilp 0\nj = p0\nwhile lt j n\nj = add j 1\nend\nput f_nilp 0 p0\n|\nwhile lt p e bound 134217729\n|\nwhile lt p e bound 16777216\n|\ndp = ulong 0\ngo = true\nwhile go bound 134217729\n|\ndp = ulong 0\ngo = true\nwhile go bound 16777216\n|\nn = get a_fs 12\nif ne ar_need 30 n 0\n|\nn = get a_fs 12\nif ge n 262144\na6_unsup n\nend\nif ne ar_need 30 n 0\n|\nwhile lt i get a_fs 12 bound 33554433\n|\nwhile lt i get a_fs 12 bound 262144\n|"
988note g_mkt: the case number (1-based) that should kill each mutant, in order
989text g_mkt "1 3 4 5 9 12 13 19 14 20 8 1 9 17 18 16 5 21 21 1 1 7 10 6 21 11 1 27 28 29 30 30 "
990global g_mk ulong 64
991note gn_mkinit: g_mkt into g_mk
992fn gn_mkinit to void
993v = ulong 0
994k = ulong 0
995for j ulong len g_mkt bound 1024
996c = ulong get g_mkt j
997if eq c 32
998put g_mk k v
999k = add k 1
1000v = ulong 0
1001else
1002v = add mul v 10 sub c 48
1003end
1004end
1005end
1006note mutant i (0-based): FROM into g_mf, TO into g_mt; false when there is no mutant i
1007fn gn_msel i ulong to bool
1008w = ulong 0
1009s = ulong 0
1010fs = ulong 0
1011fl = ulong 0
1012for j ulong len g_mx bound 1048576
1013if eq get g_mx j 124
1014if eq w mul i 2
1015fs = s
1016fl = sub j s
1017end
1018if eq w add mul i 2 1
1019if gt fl len g_mf
1020ret false
1021end
1022for q ulong fl bound 256
1023put g_mf q get g_mx add fs q
1024end
1025put g_n 27 fl
1026tl = sub j s
1027if gt tl len g_mt
1028ret false
1029end
1030for q ulong tl bound 512
1031put g_mt q get g_mx add s q
1032end
1033put g_n 28 tl
1034ret true
1035end
1036w = add w 1
1037s = add j 1
1038end
1039end
1040ret false
1041end
1042note the places of FROM in b1[0, g_n 5)
1043fn gn_mcount to ulong
1044k = get g_n 27
1045n = get g_n 5
1046c = ulong 0
1047if lt n k
1048ret 0
1049end
1050p = ulong 0
1051while le add p k n bound 16777217
1052if gn_mat p k
1053c = add c 1
1054p = add p k
1055else
1056p = add p 1
1057end
1058end
1059ret c
1060end
1061fn gn_mat p ulong k ulong to bool
1062if ne get g_b1 p get g_mf 0
1063ret false
1064end
1065for j ulong k bound 256
1066if ne get g_b1 add p j get g_mf j
1067ret false
1068end
1069end
1070ret true
1071end
1072note the place of the first FROM in b1[0, g_n 5), or g_n 5 when there is none
1073fn gn_mpos to ulong
1074k = get g_n 27
1075n = get g_n 5
1076if lt n k
1077ret n
1078end
1079e = sub n k
1080p = ulong 0
1081while le p e bound 16777217
1082if gn_mat p k
1083ret p
1084end
1085p = add p 1
1086end
1087ret n
1088end
1089note b1 with its one FROM replaced by TO (b2 holds the copy)
1090fn gn_msub to void
1091p = gn_mpos
1092n = get g_n 5
1093for j ulong n bound 16777216
1094put g_b2 j get g_b1 j
1095end
1096t = get g_n 28
1097for j ulong t bound 512
1098put g_b1 add p j get g_mt j
1099end
1100r = add p get g_n 27
1101d = add p t
1102m = sub n r
1103for j ulong m bound 16777216
1104x = get g_b2 add r j
1105put g_b1 add d j x
1106end
1107put g_n 5 add d m
1108end
1109note mutant i: built to scratch ngm and judged quietly on its own case first, then every case until one fails
1110fn gn_mut i ulong to void
1111put g_n 17 add get g_n 17 1
1112gn_say 21
1113gn_num i
1114if not gn_units
1115gn_say 20
1116gn_nl
1117put g_n 11 add get g_n 11 1
1118ret
1119end
1120if ne gn_mcount 1
1121gn_say 24
1122gn_nl
1123put g_n 11 add get g_n 11 1
1124ret
1125end
1126gn_msub
1127if not gn_bld 3
1128gn_say 20
1129gn_nl
1130put g_n 11 add get g_n 11 1
1131ret
1132end
1133put g_n 29 3
1134put g_n 12 1
1135k = get g_mk i
1136hit = gn_all k true
1137if not hit
1138hit = gn_all 0 true
1139end
1140put g_n 12 0
1141put g_n 29 2
1142if hit
1143put g_n 18 add get g_n 18 1
1144gn_say 23
1145gn_name
1146else
1147gn_say 22
1148put g_n 11 add get g_n 11 1
1149end
1150gn_nl
1151end
1152note control: case 1 judged with WANT + 1 must fail
1153fn gn_ctl to void
1154put g_n 19 add get g_n 19 1
1155put g_n 23 1
1156put g_n 12 1
1157hit = gn_all 1 true
1158put g_n 12 0
1159put g_n 23 0
1160gn_say 25
1161gn_num 1
1162if hit
1163put g_n 20 add get g_n 20 1
1164gn_say 27
1165gn_name
1166else
1167gn_say 26
1168put g_n 11 add get g_n 11 1
1169end
1170gn_nl
1171end
1172
1173note the largest group's token of the last record (b1[g_n 35, g_n 36))
1174fn gn_ulab to void
1175s = get g_n 35
1176for j ulong sub get g_n 36 s bound 4096
1177gn_c ulong get g_b1 add s j
1178end
1179end
1180note ---- the usage alarm ---------------------------------------------------------------------------------
1181note gn_uin k: scratch us.in = "@ng front-check\nusage\n", then unit k (0 seed/node/journal-gate.om, 1 ng's own units joined,
1182note the scratch src.om the build wrote); false when it cannot be written
1183fn gn_uin k ulong to bool
1184n = len g_pfc
1185for j ulong n bound 64
1186put g_b1 j get g_pfc j
1187end
1188u = len g_use
1189for j ulong u bound 64
1190put g_b1 add n j get g_use j
1191end
1192n = add n u
1193if eq k 0
1194gn_pclr
1195gn_pw 21
1196else
1197gn_ps 4
1198end
1199m = gn_slurp n
1200if ge m shl ulong 1 63
1201ret false
1202end
1203gn_ps 20
1204fd = gn_wronly
1205if lt fd 0
1206ret false
1207end
1208ok = gn_wr fd add n m
1209gn_fclo fd
1210ret ok
1211end
1212note the decimal number in b1 after the first byte c of [s, e)
1213fn gn_tnum s ulong e ulong c ulong to ulong
1214p = s
1215while and lt p e ne ulong get g_b1 p c bound 256
1216p = add p 1
1217end
1218p = add p 1
1219v = ulong 0
1220while lt p e bound 32
1221d = ulong get g_b1 p
1222if or lt d 48 gt d 57
1223ret v
1224end
1225v = add mul v 10 sub d 48
1226p = add p 1
1227end
1228ret v
1229end
1230note the ng-use record in b1[0, n): g_n 33 the arena words, 32 the top, 34 the largest group's words, 35 / 36 that
1231note group's token; false when it is not a record
1232fn gn_upar n ulong to bool
1233put g_n 34 0
1234if lt n 8
1235ret false
1236end
1237if or ne get g_b1 0 110 or ne get g_b1 1 103 ne get g_b1 2 45
1238ret false
1239end
1240t = ulong 0
1241p = ulong 0
1242while lt p n bound 1048576
1243s = p
1244while and lt p n gt get g_b1 p 32 bound 4096
1245p = add p 1
1246end
1247if gt p s
1248if eq t 2
1249put g_n 33 gn_tnum s p 61
1250end
1251if eq t 3
1252put g_n 32 gn_tnum s p 61
1253end
1254if ge t 6
1255h = gn_tnum s p 47
1256if gt h get g_n 34
1257put g_n 34 h
1258put g_n 35 s
1259put g_n 36 p
1260end
1261end
1262t = add t 1
1263end
1264p = add p 1
1265end
1266ret ge t 6
1267end
1268note the name of usage unit k
1269fn gn_uname k ulong to void
1270if eq k 0
1271s = ulong get g_wo 21
1272for j ulong ulong get g_wl 21 bound 64
1273gn_c ulong get g_w add s j
1274end
1275else
1276s = ulong get g_wo 0
1277for j ulong ulong get g_wl 0 bound 64
1278gn_c ulong get g_w add s j
1279end
1280s = ulong get g_wo 1
1281for j ulong ulong get g_wl 1 bound 64
1282gn_c ulong get g_w add s j
1283end
1284end
1285end
1286note unit k through ng (scratch word g_n 29) with a usage line: its record judged against the thresholds; a line
1287note per unit (usage NAME top=.. largest=GROUP=N/H .. ms) and one per alarm unless quiet; the alarms, counted
1288fn gn_uchk k ulong to ulong
1289if not gn_uin k
1290if eq get g_n 12 0
1291gn_say 42
1292gn_uname k
1293gn_say 39
1294gn_nl
1295end
1296ret 1
1297end
1298t0 = monons
1299x = gn_run get g_n 29 20 22 false 15
1300ms = gn_ms t0
1301gn_ps 22
1302n = gn_slurp 0
1303if or ne x 0 or ge n shl ulong 1 63 not gn_upar n
1304if eq get g_n 12 0
1305gn_say 42
1306gn_uname k
1307gn_say 43
1308gn_nl
1309end
1310ret 1
1311end
1312a = get g_n 33
1313tp = get g_n 32
1314h = get g_n 34
1315al = ulong 0
1316if gt mul tp 100 mul a 10
1317al = add al 1
1318gn_ual k 44 tp a 50
1319end
1320if gt mul h 100 mul a 5
1321al = add al 1
1322gn_ual k 52 h a 53
1323end
1324if gt ms 2000
1325al = add al 1
1326if eq get g_n 12 0
1327gn_say 42
1328gn_uname k
1329gn_say 48
1330gn_num ms
1331gn_say 49
1332gn_nl
1333end
1334end
1335if eq get g_n 12 0
1336gn_say 41
1337gn_uname k
1338gn_say 54
1339gn_num tp
1340gn_say 55
1341gn_ulab
1342gn_c 32
1343gn_num ms
1344gn_say 56
1345gn_nl
1346end
1347ret al
1348end
1349note one alarm line: ALARM NAME<message m> v words, P<message t>
1350fn gn_ual k ulong m ulong v ulong a ulong t ulong to void
1351if ne get g_n 12 0
1352ret
1353end
1354gn_say 42
1355gn_uname k
1356gn_say m
1357gn_num v
1358gn_say 45
1359gn_num div mul v 100 a
1360gn_say t
1361gn_nl
1362end
1363note the usage alarm over both units (counted as failed cases when it alarms); control (with no NG): ng built
1364note with the arena shrunk to 1048576 words must alarm on some unit
1365fn gn_usage to void
1366for k ulong 2
1367if ne gn_uchk k 0
1368put g_n 11 add get g_n 11 1
1369end
1370end
1371end
1372text g_ux "\nglobal ar_m ulong 16777216\n|\nglobal ar_m ulong 1048576\n|"
1373fn gn_uctl to void
1374put g_n 19 add get g_n 19 1
1375gn_say 57
1376put g_n 27 0
1377put g_n 28 0
1378k = ulong 0
1379fs = ulong 0
1380for j ulong len g_ux bound 256
1381if eq get g_ux j 124
1382if eq k 0
1383put g_n 27 j
1384for q ulong j bound 256
1385put g_mf q get g_ux q
1386end
1387fs = add j 1
1388else
1389put g_n 28 sub j fs
1390for q ulong sub j fs bound 256
1391put g_mt q get g_ux add fs q
1392end
1393end
1394k = add k 1
1395end
1396end
1397ok = gn_units
1398if ok
1399ok = eq gn_mcount 1
1400end
1401if ok
1402gn_msub
1403ok = gn_bld 3
1404end
1405if not ok
1406gn_say 20
1407gn_nl
1408put g_n 11 add get g_n 11 1
1409ret
1410end
1411put g_n 29 3
1412put g_n 12 1
1413al = add gn_uchk 0 gn_uchk 1
1414put g_n 12 0
1415put g_n 29 2
1416if gt al 0
1417put g_n 20 add get g_n 20 1
1418gn_say 27
1419gn_num al
1420else
1421gn_say 26
1422put g_n 11 add get g_n 11 1
1423end
1424gn_nl
1425end
1426
1427note ---- main ---------------------------------------------------------------------------------------------
1428fn gn_inval i ulong to int
1429gn_say 12
1430gn_say i
1431gn_nl
1432ret 2
1433end
1434note OMC hashes to the hex of argument 2
1435fn gn_oracle to bool
1436gn_pclr
1437for j ulong get g_n 1 bound 4096
1438gn_pc ulong get g_omc j
1439end
1440fd = gn_rdonly
1441if lt fd 0
1442ret false
1443end
1444n = ulong 0
1445while true bound 16777218
1446x = read fd sh_dat n sub len sh_dat n
1447if le x 0
1448break
1449end
1450n = add n ulong x
1451if ge n len sh_dat
1452gn_fclo fd
1453ret false
1454end
1455end
1456gn_fclo fd
1457sh_all n
1458r = argread 2 g_hx 0 128
1459if ne r 64
1460ret false
1461end
1462for j ulong 32
1463b = get sh_dig j
1464if ne get g_hx mul j 2 sh_hexd uint shr b 4
1465ret false
1466end
1467if ne get g_hx add mul j 2 1 sh_hexd uint and b 15
1468ret false
1469end
1470end
1471ret true
1472end
1473fn main to int
1474gn_init
1475gn_mkinit
1476c = argcnt
1477if and ne c 4 ne c 5
1478ret gn_inval 17
1479end
1480r = argread 1 g_omc 0 4095
1481if lt r 1
1482ret gn_inval 17
1483end
1484put g_n 1 ulong r
1485if not gn_oracle
1486ret gn_inval 18
1487end
1488r = argread 3 g_scr 0 4094
1489if lt r 1
1490ret gn_inval 17
1491end
1492n = ulong r
1493x = makedir g_scr 0 n 448
1494if ne x 0
1495ret gn_inval 19
1496end
1497put g_scr n 47
1498put g_n 2 add n 1
1499gn_ps 16
1500fd = gn_wronly
1501gn_fclo fd
1502if eq c 5
1503put g_n 22 1
1504if not gn_cpng
1505ret gn_inval 17
1506end
1507note the usage step reads ng's own units from src.om: compose and write it, without building
1508if not gn_units
1509gn_say 20
1510gn_nl
1511ret 3
1512end
1513if not gn_wsrc
1514gn_say 20
1515gn_nl
1516ret 3
1517end
1518else
1519if not gn_units
1520gn_say 20
1521gn_nl
1522ret 3
1523end
1524if not gn_bld 2
1525gn_say 20
1526gn_ps 19
1527r = write 1 g_pa 0 get g_n 0
1528gn_nl
1529ret 3
1530end
1531end
1532z = gn_all 0 false
1533gn_usage
1534if eq get g_n 22 0
1535for i ulong 64
1536if gn_msel i
1537gn_mut i
1538end
1539end
1540gn_ctl
1541gn_uctl
1542end
1543f = get g_n 11
1544nr = get g_n 21
1545if ne f 0
1546gn_say 11
1547else
1548if ne nr 0
1549gn_say 51
1550else
1551gn_say 10
1552end
1553end
1554gn_say 13
1555gn_num get g_n 10
1556gn_say 14
1557gn_num f
1558gn_say 15
1559gn_num get g_n 17
1560gn_say 16
1561gn_num get g_n 18
1562gn_say 46
1563gn_num get g_n 19
1564gn_say 47
1565gn_num get g_n 20
1566gn_say 38
1567gn_num nr
1568gn_nl
1569if ne f 0
1570ret 1
1571end
1572if ne nr 0
1573ret 4
1574end
1575ret 0
1576end