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 / evidence / ECOSYSTEM663 / compile-second.om

366 lines · 5497 bytes Raw Blame History
1note M20 metadata-v1. Integer metadata only; no allocator or numeric execution.
2note ED: schema,dtype,rank,elements,offset,slot,generation,reserved,shape8,stride8.
3note ES: live,retired,slot,generation,dtype,elements,reserved,reserved.
4note ES is the caller-owned allocator snapshot. It is not untrusted wire input.
5global ED ulong 24
6global ES ulong 8
7
8fn emshape to int
9rank = get ED 2
10if gt rank 8
11ret -2
12end
13n = ulong 1
14for d ulong rank
15size = get ED add 8 d
16if eq size 0
17ret -3
18end
19if gt size div 1073741824 n
20ret -8
21end
22n = mul n size
23end
24if ne get ED 3 n
25ret -3
26end
27ret 0
28end
29
30fn emlive slot ulong gen ulong to int
31if or ne get ES 0 1 ne get ES 1 0
32ret -5
33end
34if or eq gen 0 ne slot get ES 2
35ret -5
36end
37if ne gen get ES 3
38ret -5
39end
40ret 0
41end
42
43fn embounds to int
44size = get ES 5
45offset = get ED 4
46if or eq size 0 gt size 1073741824
47ret -8
48end
49if ge offset size
50ret -6
51end
52note Compare against remaining extent before multiplication, never overflow.
53room = sub sub size 1 offset
54for d ulong get ED 2
55count = sub get ED add 8 d 1
56stride = get ED add 16 d
57if ne stride 0
58if gt count div room stride
59ret -6
60end
61room = sub room mul count stride
62end
63end
64ret 0
65end
66
67fn emcheck to int
68if or ne get ED 0 1 ne get ED 7 0
69ret -1
70end
71if or ne get ES 6 0 ne get ES 7 0
72ret -1
73end
74dtype = get ED 1
75if or lt dtype 1 gt dtype 3
76ret -4
77end
78status = emshape
79if ne status 0
80ret status
81end
82status = emlive get ED 5 get ED 6
83if ne status 0
84ret status
85end
86if ne dtype get ES 4
87ret -4
88end
89ret embounds
90end
91
92fn emrelease slot ulong gen ulong to int
93status = emlive slot gen
94if ne status 0
95ret status
96end
97note A maximal generation is retired, never wrapped into a valid old handle.
98if eq gen 18446744073709551615
99put ES 1 1
100else
101put ES 3 add gen 1
102end
103put ES 0 0
104ret 0
105end
106note Native checks plus independent element-by-element view bounds oracle.
107global EC ulong 1
108global Digits uchar 20
109text Pass "M20_METADATA_V1_PASS checks="
110text Fail "M20_METADATA_V1_FAIL check="
111text NL "\n"
112
113fn number n ulong to void
114if eq n 0
115put Digits 0 48
116w = write 1 Digits 0 1
117if ne w 1
118exit 90
119end
120ret
121end
122pos = ulong 20
123while gt n 0 bound 20
124pos = sub pos 1
125put Digits pos uchar add 48 rem n 10
126n = div n 10
127end
128w = write 1 Digits pos sub 20 pos
129if ne w long sub 20 pos
130exit 90
131end
132end
133
134fn check got int want int to void
135put EC 0 add get EC 0 1
136if ne got want
137w = write 1 Fail 0 len Fail
138number get EC 0
139w = write 1 NL 0 1
140if ne w 1
141exit 90
142end
143exit 1
144end
145end
146
147fn fixture to void
148for i ulong 24
149put ED i 0
150end
151for i ulong 8
152put ES i 0
153end
154put ED 0 1
155put ED 1 1
156put ED 2 2
157put ED 3 6
158put ED 5 4
159put ED 6 17
160put ED 8 2
161put ED 9 3
162put ED 16 3
163put ED 17 1
164put ES 0 1
165put ES 2 4
166put ES 3 17
167put ES 4 1
168put ES 5 6
169end
170
171fn direct to void
172fixture
173check emcheck 0
174put ED 0 2
175check emcheck -1
176fixture
177put ED 7 1
178check emcheck -1
179fixture
180put ES 6 1
181check emcheck -1
182fixture
183put ES 7 1
184check emcheck -1
185fixture
186put ED 1 0
187check emcheck -4
188put ED 1 4
189check emcheck -4
190fixture
191put ES 4 2
192check emcheck -4
193put ED 1 2
194check emcheck 0
195put ED 1 3
196put ES 4 3
197check emcheck 0
198fixture
199put ED 2 9
200check emcheck -2
201fixture
202put ED 8 0
203check emcheck -3
204fixture
205put ED 3 7
206check emcheck -3
207fixture
208put ED 8 1073741824
209check emcheck -8
210fixture
211put ED 8 18446744073709551615
212check emcheck -8
213fixture
214put ES 5 0
215check emcheck -8
216put ES 5 1073741825
217check emcheck -8
218fixture
219put ED 4 6
220check emcheck -6
221fixture
222put ED 4 18446744073709551615
223check emcheck -6
224fixture
225put ED 16 18446744073709551615
226check emcheck -6
227fixture
228put ED 8 1
229put ED 3 3
230put ED 16 18446744073709551615
231check emcheck 0
232fixture
233put ED 16 0
234check emcheck 0
235fixture
236put ED 16 1
237put ED 17 2
238check emcheck 0
239put ES 5 5
240check emcheck -6
241fixture
242put ED 2 0
243put ED 3 1
244put ED 4 5
245check emcheck 0
246put ED 4 6
247check emcheck -6
248fixture
249put ED 2 8
250put ED 3 1
251for i ulong 8
252put ED add 8 i 1
253put ED add 16 i 18446744073709551615
254end
255check emcheck 0
256fixture
257put ED 2 1
258put ED 8 1073741824
259put ED 3 1073741824
260put ED 16 0
261put ES 5 1
262check emcheck 0
263put ED 16 1
264put ES 5 1073741824
265check emcheck 0
266put ED 4 1
267check emcheck -6
268end
269
270fn lifetime to void
271fixture
272check emlive 4 17 0
273check emlive 5 17 -5
274check emlive 4 0 -5
275check emlive 4 16 -5
276check emrelease 4 16 -5
277check emlive 4 17 0
278check emrelease 4 17 0
279check int get ES 0 0
280check int get ES 3 18
281check emcheck -5
282check emrelease 4 17 -5
283put ES 0 1
284check emcheck -5
285put ED 6 18
286check emcheck 0
287check emlive 4 17 -5
288fixture
289put ES 1 1
290check emcheck -5
291fixture
292put ES 0 2
293check emcheck -5
294fixture
295put ES 1 2
296check emcheck -5
297fixture
298put ES 3 18446744073709551615
299put ED 6 18446744073709551615
300check emcheck 0
301check emrelease 4 18446744073709551615 0
302check int get ES 0 0
303check int get ES 1 1
304check emlive 4 18446744073709551615 -5
305put ES 0 1
306check emcheck -5
307if ne get ES 3 18446744073709551615
308check 1 0
309end
310fixture
311check emcheck 0
312end
313
314note Independent oracle visits every element; it never uses maximal extent.
315fn oracle a ulong b ulong s ulong t ulong off ulong cap ulong to int
316for i ulong a
317for j ulong b
318index = add off add mul i s mul j t
319if ge index cap
320ret -6
321end
322end
323end
324ret 0
325end
326
327fn enumerate to void
328fixture
329for ai ulong 3
330a = add ai 1
331put ED 8 a
332for bi ulong 3
333b = add bi 1
334put ED 9 b
335put ED 3 mul a b
336for s ulong 5
337put ED 16 s
338for t ulong 5
339put ED 17 t
340for off ulong 4
341put ED 4 off
342for ci ulong 16
343cap = add ci 1
344put ES 5 cap
345want = oracle a b s t off cap
346check emcheck want
347end
348end
349end
350end
351end
352end
353end
354
355fn main to int
356direct
357lifetime
358enumerate
359w = write 1 Pass 0 len Pass
360number get EC 0
361w = write 1 NL 0 1
362if ne w 1
363ret 90
364end
365ret 0
366end