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 / native / prefetch / gate.om

427 lines · 7242 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Prefetch host qualification. Process helpers adapted from existing gate669 at1dffceae.
3note No GPU. Exact exits plus exact verdict bytes; child deadlines30s; scratch exclusive.
4text scratch "build/prefetch-native-gate"
5text prefix "build/prefetch-native-gate/"
6text names "unused\nnative/prefetch/classify.om\nnative/prefetch/review-fixtures.om\nnative/prefetch/review-nested.om\n/dev/null\n1\n0\nL\nJ\n2\n124\n137\n139\n-1\n01\n\nnative/prefetch/gate-child.om\n"
7text input " < "
8text output " > "
9text errors " 2> "
10text nl "\n"
11text statusm "exit="
12text expect " expected="
13text signalm "INVALID child wait low-byte="
14text timeoutm "INVALID child deadline exceeded; sent SIGKILL; wait low-byte="
15text passed "AIEN-OBS prefetch_cases 53\nPREFETCH_NATIVE_GATE: PASS\n"
16text failed "PREFETCH_NATIVE_GATE: FAIL; retain all scratch files and command output\n"
17global pathbuf uchar 4096
18global plen ulong 1
19global serial ulong 1
20global argv uchar 4096
21global argc ulong 1
22global apos ulong 1
23global statbuf uchar 4
24global buf uchar 4096
25global other uchar 4096
26global digits uchar 32
27global cases ulong 1
28text caught "PREFETCH_CONTROL: CAUGHT\n"
29text missed "PREFETCH_CONTROL: UNCAUGHT\n"
30text invalid "PREFETCH_CONTROL: INVALID\n"
31fn stop to void
32r = write 2 failed 0 len failed
33exit 99
34end
35fn decimal v ulong to ulong
36x = v
37n = ulong 0
38while ge x 10
39put digits n uchar add 48 rem x 10
40x = div x 10
41n = add n 1
42end
43put digits n uchar add 48 x
44ret add n 1
45end
46fn num v ulong to void
47n = decimal v
48for i ulong n
49r = write 1 digits sub sub n i 1 1
50if ne r 1
51stop
52end
53end
54end
55fn setpath id ulong to void
56if eq id 1
57n = argread 1 pathbuf 0 len pathbuf
58if le n 0
59stop
60end
61put plen 0 ulong n
62ret
63end
64if and ge id 100 lt id 356
65put pathbuf 0 uchar sub id 100
66put plen 0 1
67ret
68end
69if ge id 1000
70for i ulong len prefix
71put pathbuf i get prefix i
72end
73n = decimal id
74for i ulong n
75put pathbuf add len prefix i get digits sub sub n i 1
76end
77put plen 0 add len prefix n
78ret
79end
80index = ulong 1
81p = ulong 0
82for i ulong len names
83b = get names i
84if eq b 10
85if eq index id
86put plen 0 p
87ret
88end
89index = add index 1
90else
91if eq index id
92put pathbuf p b
93p = add p 1
94end
95end
96end
97stop
98end
99fn showpath id ulong to void
100setpath id
101r = write 1 pathbuf 0 get plen 0
102if ne r long get plen 0
103stop
104end
105end
106fn openfile id ulong flags int to int
107setpath id
108r = fopen pathbuf 0 get plen 0 flags 384
109if lt r 0
110stop
111end
112ret int r
113end
114fn fresh to ulong
115n = add get serial 0 1
116if ge n 400000
117stop
118end
119put serial 0 n
120ret add 1000 n
121end
122fn arg id ulong to void
123setpath id
124p = get apos 0
125n = get plen 0
126if gt add add p n 2 len argv
127stop
128end
129put argv p uchar and n 255
130put argv add p 1 uchar shr n 8
131p = add p 2
132for i ulong n
133put argv add p i get pathbuf i
134end
135put apos 0 add p n
136put argc 0 add get argc 0 1
137end
138fn command exe ulong to void
139put argc 0 0
140put apos 0 2
141arg exe
142showpath exe
143end
144fn argument id ulong to void
145put digits 0 32
146r = write 1 digits 0 1
147showpath id
148arg id
149end
150fn close fd int to void
151if ne fclose fd 0
152stop
153end
154end
155fn redirect source int dest int to void
156if ne source dest
157if ne dupfd source dest 0 long dest
158stop
159end
160end
161end
162fn reap pid int to ulong
163start = monons
164if lt start 0
165stop
166end
167while true
168r = waitpid pid statbuf 0 len statbuf 1
169if eq r long pid
170if ne get statbuf 0 0
171r = write 1 signalm 0 len signalm
172num ulong get statbuf 0
173r = write 1 nl 0 1
174stop
175end
176ret ulong get statbuf 1
177end
178if lt r 0
179stop
180end
181now = monons
182if or lt now start gt sub now start 30000000000
183r = killpid pid 9
184r = waitpid pid statbuf 0 len statbuf 0
185r = write 1 timeoutm 0 len timeoutm
186num ulong get statbuf 0
187r = write 1 nl 0 1
188stop
189end
190if ne sleepns 1000000 0
191stop
192end
193end
194exit 99
195end
196fn run source ulong wanted ulong to ulong
197outid = fresh
198errid = add outid 500000
199r = write 1 input 0 len input
200showpath source
201r = write 1 output 0 len output
202showpath outid
203r = write 1 errors 0 len errors
204showpath errid
205r = write 1 nl 0 1
206rd = openfile source 524288
207wr = openfile outid 524481
208er = openfile errid 524481
209put argv 0 uchar get argc 0
210put argv 1 uchar shr get argc 0 8
211pid = fork
212if lt pid 0
213stop
214end
215if eq pid 0
216redirect rd 0
217redirect wr 1
218redirect er 2
219r = execprog argv 0 get apos 0
220exit 98
221end
222close rd
223close wr
224close er
225actual = reap int pid
226r = write 1 statusm 0 len statusm
227num actual
228r = write 1 expect 0 len expect
229num wanted
230r = write 1 nl 0 1
231if ne actual wanted
232stop
233end
234ret outid
235end
236fn enable id ulong to void
237fd = openfile id 524288
238r = read fd buf 0 4
239if ne r 4
240stop
241end
242if or ne get buf 0 127 ne get buf 1 69
243stop
244end
245if or ne get buf 2 76 ne get buf 3 70
246stop
247end
248if ne fchmod fd 448 0
249stop
250end
251close fd
252end
253fn empty id ulong to void
254fd = openfile id 524288
255r = read fd buf 0 1
256close fd
257if ne r 0
258stop
259end
260end
261fn compile cc ulong src ulong wanted ulong to ulong
262command cc
263outid = run src wanted
264if eq wanted 0
265enable outid
266else
267empty outid
268end
269ret outid
270end
271fn verdict id ulong want ulong to void
272fd = openfile id 524288
273n = read fd buf 0 len buf
274if lt n 0
275stop
276end
277extra = read fd other 0 1
278close fd
279if ne extra 0
280stop
281end
282size = len invalid
283if eq want 0
284size = len caught
285end
286if eq want 1
287size = len missed
288end
289if ne ulong n size
290stop
291end
292for i ulong size
293b = uchar 0
294if eq want 65
295b = get invalid i
296end
297if eq want 0
298b = get caught i
299end
300if eq want 1
301b = get missed i
302end
303if ne get buf i b
304stop
305end
306end
307put cases 0 add get cases 0 1
308end
309fn make gen ulong mode ulong kind ulong to ulong
310command gen
311argument add mode 100
312argument kind
313ret run 5 0
314end
315fn check exe ulong code ulong log ulong json ulong want ulong to void
316command exe
317argument code
318argument log
319argument json
320result = run 5 want
321verdict result want
322end
323fn basics exe ulong gen ulong to void
324for i ulong 21
325mode = add i 48
326if ge i 10
327mode = add sub i 10 65
328end
329log = make gen mode 8
330json = make gen mode 9
331want = ulong 65
332code = ulong 6
333if lt i 3
334want = 0
335end
336if eq i 3
337want = 1
338code = 7
339end
340check exe code log json want
341end
342end
343fn statuses exe ulong gen ulong to void
344log = make gen 48 8
345json = make gen 48 9
346check exe 7 log json 65
347for i ulong 7
348code = add i 10
349check exe code log json 65
350end
351log = make gen 51 8
352json = make gen 51 9
353check exe 6 log json 65
354end
355fn slots exe ulong gen ulong to void
356json = make gen 48 9
357otherj = make gen 49 9
358for i ulong 13
359log = make gen add i 76 8
360want = ulong 65
361if or eq i 4 eq i 5
362want = 0
363end
364selected = json
365if eq i 5
366selected = otherj
367end
368check exe 6 log selected want
369end
370end
371fn nested exe ulong gen ulong mut ulong to void
372log = make gen 48 8
373json = make gen 48 9
374for i ulong 10
375command mut
376argument add i 148
377changed = run json 0
378check exe 6 log changed 65
379end
380end
381fn control to void
382if ne argread 2 buf 0 1 1
383stop
384end
385m = get buf 0
386if or lt m 48 gt m 50
387stop
388end
389put buf 0 sub m 48
390id = fresh
391fd = openfile id 524481
392if ne write fd buf 0 1 1
393stop
394end
395close fd
396child = compile 1 17 0
397command child
398result = run id 0
399stop
400end
401fn main to int
402if or lt argcnt 2 gt argcnt 3
403ret 90
404end
405if ne makedir scratch 0 len scratch 448 0
406ret 91
407end
408if eq argcnt 3
409control
410ret 99
411end
412exe = compile 1 2 0
413gen = compile 1 3 0
414mut = compile 1 4 0
415basics exe gen
416statuses exe gen
417slots exe gen
418nested exe gen mut
419if ne get cases 0 53
420stop
421end
422r = write 1 passed 0 len passed
423if ne r long len passed
424ret 99
425end
426ret 0
427end