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 / tools / pi-drive-27b / omguard_trace.om

571 lines · 9632 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tools/pi-drive-27b/omguard_trace.om: Pure OM-1 self-test driver for omguard.om.
3note Build on AArch64 Linux:
4note cat tools/pi-drive-27b/omguard.om tools/pi-drive-27b/omguard_trace.om | ./seed/out/omc > omguard_trace
5note Run:
6note ./omguard_trace
7
8text tpass "OMGUARD TEST PASS 8/8\n"
9text tfail "OMGUARD TEST FAIL\n"
10
11text s1_0 "note 0xdeadbeef inside note comment is allowed"
12text s1_1 "fn sq x ulong y ulong to ulong"
13text s1_2 "acc = ulong 0"
14text s1_3 "i = ulong 0"
15text s1_4 "while lt i x bound 64"
16text s1_5 "if gt y 0"
17text s1_6 "acc = add acc y"
18text s1_7 "end"
19text s1_8 "i = add i 1"
20text s1_9 "end"
21text s1_10 "ret acc"
22text s1_11 "end"
23
24text s2_0 "fn badhex to ulong"
25text s2_1 "x = ulong 0x10"
26text s2_2 "y = ulong 0XFF"
27
28text s3_0 "fn too7 a ulong b ulong c ulong d ulong e ulong f ulong g ulong to ulong"
29
30text s4_0 "fn many to ulong"
31text s4_1 "v0 = ulong 0"
32text s4_2 "v1 = ulong 1"
33text s4_3 "v2 = ulong 2"
34text s4_4 "v3 = ulong 3"
35text s4_5 "v4 = ulong 4"
36text s4_6 "v5 = ulong 5"
37text s4_7 "v6 = ulong 6"
38text s4_8 "v7 = ulong 7"
39text s4_9 "v8 = ulong 8"
40text s4_10 "v9 = ulong 9"
41text s4_11 "v10 = ulong 10"
42text s4_12 "v11 = ulong 11"
43text s4_13 "v12 = ulong 12"
44text s4_14 "v13 = ulong 13"
45text s4_15 "v14 = ulong 14"
46text s4_16 "v15 = ulong 15"
47text s4_17 "v16 = ulong 16"
48
49text s5_0 "fn nobnd x ulong to ulong"
50text s5_1 "while gt x 0"
51
52text s6_0 "end"
53text s6_1 "fn outer to ulong"
54text s6_2 "fn inner to ulong"
55
56text pchunk0 "system: pure omega om-1 codegen"
57text pchunk1 "user: write fn sq x ulong to ulong"
58text pchunk2 "assistant: fn sq x ulong to ulong"
59text pchunk3 "user: write fn fib n ulong to ulong"
60
61note Test 1: valid OM-1 function with note 0x comment, while bound, if/end, balanced depth.
62fn test1 to long
63oginit
64i = ulong 0
65while lt i len s1_0 bound 512
66put ogline i get s1_0 i
67i = add i 1
68end
69if ne ogcheckline len s1_0 0
70ret -1
71end
72i = ulong 0
73while lt i len s1_1 bound 512
74put ogline i get s1_1 i
75i = add i 1
76end
77if ne ogcheckline len s1_1 0
78ret -2
79end
80i = ulong 0
81while lt i len s1_2 bound 512
82put ogline i get s1_2 i
83i = add i 1
84end
85if ne ogcheckline len s1_2 0
86ret -3
87end
88i = ulong 0
89while lt i len s1_3 bound 512
90put ogline i get s1_3 i
91i = add i 1
92end
93if ne ogcheckline len s1_3 0
94ret -4
95end
96i = ulong 0
97while lt i len s1_4 bound 512
98put ogline i get s1_4 i
99i = add i 1
100end
101if ne ogcheckline len s1_4 0
102ret -5
103end
104i = ulong 0
105while lt i len s1_5 bound 512
106put ogline i get s1_5 i
107i = add i 1
108end
109if ne ogcheckline len s1_5 0
110ret -6
111end
112i = ulong 0
113while lt i len s1_6 bound 512
114put ogline i get s1_6 i
115i = add i 1
116end
117if ne ogcheckline len s1_6 0
118ret -7
119end
120i = ulong 0
121while lt i len s1_7 bound 512
122put ogline i get s1_7 i
123i = add i 1
124end
125if ne ogcheckline len s1_7 0
126ret -8
127end
128i = ulong 0
129while lt i len s1_8 bound 512
130put ogline i get s1_8 i
131i = add i 1
132end
133if ne ogcheckline len s1_8 0
134ret -9
135end
136i = ulong 0
137while lt i len s1_9 bound 512
138put ogline i get s1_9 i
139i = add i 1
140end
141if ne ogcheckline len s1_9 0
142ret -10
143end
144i = ulong 0
145while lt i len s1_10 bound 512
146put ogline i get s1_10 i
147i = add i 1
148end
149if ne ogcheckline len s1_10 0
150ret -11
151end
152i = ulong 0
153while lt i len s1_11 bound 512
154put ogline i get s1_11 i
155i = add i 1
156end
157if ne ogcheckline len s1_11 0
158ret -12
159end
160if ne ogdepth 0
161ret -13
162end
163if ne oginfn 0
164ret -14
165end
166ret 0
167end
168
169note Test 2: hex literal refusal (-1) for both 0x and 0X.
170fn test2 to long
171oginit
172i = ulong 0
173while lt i len s2_0 bound 512
174put ogline i get s2_0 i
175i = add i 1
176end
177if ne ogcheckline len s2_0 0
178ret -1
179end
180i = ulong 0
181while lt i len s2_1 bound 512
182put ogline i get s2_1 i
183i = add i 1
184end
185if ne ogcheckline len s2_1 -1
186ret -2
187end
188i = ulong 0
189while lt i len s2_2 bound 512
190put ogline i get s2_2 i
191i = add i 1
192end
193if ne ogcheckline len s2_2 -1
194ret -3
195end
196ret 0
197end
198
199note Test 3: >6 params refusal (-2).
200fn test3 to long
201oginit
202i = ulong 0
203while lt i len s3_0 bound 512
204put ogline i get s3_0 i
205i = add i 1
206end
207if ne ogcheckline len s3_0 -2
208ret -1
209end
210ret 0
211end
212
213note Test 4: >16 distinct locals refusal (-3), with reassignment allowed.
214fn test4a to long
215oginit
216i = ulong 0
217while lt i len s4_0 bound 512
218put ogline i get s4_0 i
219i = add i 1
220end
221if ne ogcheckline len s4_0 0
222ret -1
223end
224i = ulong 0
225while lt i len s4_1 bound 512
226put ogline i get s4_1 i
227i = add i 1
228end
229if ne ogcheckline len s4_1 0
230ret -2
231end
232note Reassign v0: must not consume a new register slot.
233if ne ogcheckline len s4_1 0
234ret -2
235end
236i = ulong 0
237while lt i len s4_2 bound 512
238put ogline i get s4_2 i
239i = add i 1
240end
241if ne ogcheckline len s4_2 0
242ret -3
243end
244i = ulong 0
245while lt i len s4_3 bound 512
246put ogline i get s4_3 i
247i = add i 1
248end
249if ne ogcheckline len s4_3 0
250ret -4
251end
252i = ulong 0
253while lt i len s4_4 bound 512
254put ogline i get s4_4 i
255i = add i 1
256end
257if ne ogcheckline len s4_4 0
258ret -5
259end
260i = ulong 0
261while lt i len s4_5 bound 512
262put ogline i get s4_5 i
263i = add i 1
264end
265if ne ogcheckline len s4_5 0
266ret -6
267end
268i = ulong 0
269while lt i len s4_6 bound 512
270put ogline i get s4_6 i
271i = add i 1
272end
273if ne ogcheckline len s4_6 0
274ret -7
275end
276i = ulong 0
277while lt i len s4_7 bound 512
278put ogline i get s4_7 i
279i = add i 1
280end
281if ne ogcheckline len s4_7 0
282ret -8
283end
284i = ulong 0
285while lt i len s4_8 bound 512
286put ogline i get s4_8 i
287i = add i 1
288end
289if ne ogcheckline len s4_8 0
290ret -9
291end
292ret 0
293end
294
295fn test4 to long
296r = test4a
297if ne r 0
298ret r
299end
300i = ulong 0
301while lt i len s4_9 bound 512
302put ogline i get s4_9 i
303i = add i 1
304end
305if ne ogcheckline len s4_9 0
306ret -10
307end
308i = ulong 0
309while lt i len s4_10 bound 512
310put ogline i get s4_10 i
311i = add i 1
312end
313if ne ogcheckline len s4_10 0
314ret -11
315end
316i = ulong 0
317while lt i len s4_11 bound 512
318put ogline i get s4_11 i
319i = add i 1
320end
321if ne ogcheckline len s4_11 0
322ret -12
323end
324i = ulong 0
325while lt i len s4_12 bound 512
326put ogline i get s4_12 i
327i = add i 1
328end
329if ne ogcheckline len s4_12 0
330ret -13
331end
332i = ulong 0
333while lt i len s4_13 bound 512
334put ogline i get s4_13 i
335i = add i 1
336end
337if ne ogcheckline len s4_13 0
338ret -14
339end
340i = ulong 0
341while lt i len s4_14 bound 512
342put ogline i get s4_14 i
343i = add i 1
344end
345if ne ogcheckline len s4_14 0
346ret -15
347end
348i = ulong 0
349while lt i len s4_15 bound 512
350put ogline i get s4_15 i
351i = add i 1
352end
353if ne ogcheckline len s4_15 0
354ret -16
355end
356i = ulong 0
357while lt i len s4_16 bound 512
358put ogline i get s4_16 i
359i = add i 1
360end
361if ne ogcheckline len s4_16 0
362ret -17
363end
364if ne ognlocs 16
365ret -18
366end
367i = ulong 0
368while lt i len s4_17 bound 512
369put ogline i get s4_17 i
370i = add i 1
371end
372if ne ogcheckline len s4_17 -3
373ret -19
374end
375ret 0
376end
377
378note Test 5: while missing bound refusal (-4).
379fn test5 to long
380oginit
381i = ulong 0
382while lt i len s5_0 bound 512
383put ogline i get s5_0 i
384i = add i 1
385end
386if ne ogcheckline len s5_0 0
387ret -1
388end
389i = ulong 0
390while lt i len s5_1 bound 512
391put ogline i get s5_1 i
392i = add i 1
393end
394if ne ogcheckline len s5_1 -4
395ret -2
396end
397ret 0
398end
399
400note Test 6: unbalanced end refusal (-5) and nested fn refusal (-6).
401fn test6 to long
402oginit
403i = ulong 0
404while lt i len s6_0 bound 512
405put ogline i get s6_0 i
406i = add i 1
407end
408if ne ogcheckline len s6_0 -5
409ret -1
410end
411i = ulong 0
412while lt i len s6_1 bound 512
413put ogline i get s6_1 i
414i = add i 1
415end
416if ne ogcheckline len s6_1 0
417ret -2
418end
419i = ulong 0
420while lt i len s6_2 bound 512
421put ogline i get s6_2 i
422i = add i 1
423end
424if ne ogcheckline len s6_2 -6
425ret -3
426end
427ret 0
428end
429
430note Test 7: prefix-pool FNV-1a chunk hashing, exact & partial longest-prefix match.
431fn test7 to long
432ogpinit
433i = ulong 0
434while lt i len pchunk0 bound 512
435put ogp_buf i get pchunk0 i
436i = add i 1
437end
438h0 = ogphash 0 len pchunk0
439i = ulong 0
440while lt i len pchunk1 bound 512
441put ogp_buf i get pchunk1 i
442i = add i 1
443end
444h1 = ogphash 0 len pchunk1
445i = ulong 0
446while lt i len pchunk2 bound 512
447put ogp_buf i get pchunk2 i
448i = add i 1
449end
450h2 = ogphash 0 len pchunk2
451i = ulong 0
452while lt i len pchunk3 bound 512
453put ogp_buf i get pchunk3 i
454i = add i 1
455end
456h3 = ogphash 0 len pchunk3
457if eq h0 h1
458ret -1
459end
460note Slot 3: [h0, h1] with state_pa 4096000
461put ogp_q 0 h0
462put ogp_q 1 h1
463if ne ogpput 3 2 4096000 0
464ret -2
465end
466note Slot 7: [h0, h1, h2] with state_pa 8192000
467put ogp_q 0 h0
468put ogp_q 1 h1
469put ogp_q 2 h2
470if ne ogpput 7 3 8192000 0
471ret -3
472end
473note Exact 3-chunk match must pick slot 7 (len 3, pa 8192000).
474put ogp_q 0 h0
475put ogp_q 1 h1
476put ogp_q 2 h2
477if ne ogpmatch 3 7
478ret -4
479end
480if ne ogpmatch_len 3
481ret -5
482end
483if ne ogpmatch_pa 8192000
484ret -6
485end
486note Partial 2-chunk query [h0, h3]: matches h0 (len 1) on most recent slot 7.
487put ogp_q 0 h0
488put ogp_q 1 h3
489ms = ogpmatch 2
490if lt ms 0
491ret -7
492end
493if ne ogpmatch_len 1
494ret -8
495end
496note Unmatched query [h3]: must return -1.
497put ogp_q 0 h3
498if ne ogpmatch 1 -1
499ret -9
500end
501ret 0
502end
503
504note Test 8: prefix-pool full 64-slot fill and LRU eviction.
505fn test8 to long
506ogpinit
507s = ulong 0
508while lt s OGSLOTS bound 64
509h = ogphash_tok add 1000 s OGFNVOFF
510put ogp_q 0 h
511pa = mul add s 1 65536
512if ne ogpput s 1 pa 0
513ret -1
514end
515s = add s 1
516end
517note Touch slot 0 via ogpmatch so slot 1 becomes the oldest LRU entry.
518h0 = ogphash_tok 1000 OGFNVOFF
519put ogp_q 0 h0
520if ne ogpmatch 1 0
521ret -2
522end
523note Evict must choose slot 1 (oldest untouched) and clear it.
524v = ogpevict
525if ne v 1
526ret -3
527end
528if ne get ogp_act 1 0
529ret -4
530end
531note Next evict must choose slot 2.
532v2 = ogpevict
533if ne v2 2
534ret -5
535end
536ret 0
537end
538
539fn main to int
540ok = ulong 0
541if eq test1 0
542ok = add ok 1
543end
544if eq test2 0
545ok = add ok 1
546end
547if eq test3 0
548ok = add ok 1
549end
550if eq test4 0
551ok = add ok 1
552end
553if eq test5 0
554ok = add ok 1
555end
556if eq test6 0
557ok = add ok 1
558end
559if eq test7 0
560ok = add ok 1
561end
562if eq test8 0
563ok = add ok 1
564end
565if eq ok 8
566k = write 1 tpass 0 len tpass
567ret 0
568end
569k = write 2 tfail 0 len tfail
570ret 1
571end