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 / diaggen.om

465 lines · 7138 bytes Raw Blame History
1note Diagnostic source generator. Compose after the core of seed/trace/sha256.om; compile in OM-2.
2note Usage: diaggen OMC_SOURCE ERROR_REG SHA_SOURCE RUNTIME_SOURCE [sites]
3note Or: diaggen OMC_SOURCE OMC_BINARY, a derived append-only size-history row.
4note stdout is canonical compiler source, or the documented site catalog when argc is 6.
5global buf uchar *
6global bn ulong 1
7global src uchar *
8global sn ulong 1
9global obuf uchar *
10global on ulong 1
11global path uchar 4096
12text beginmark "note D2-GENERATED-BEGIN"
13text endmark "note D2-GENERATED-END"
14text pinhead "text d2pin \""
15text sitehead "note d2site "
16text reghead "omc|"
17text fnhead "fn "
18text shastop "fn sha256 "
19text names "h w k nr blk kset mask ror ch maj bs0 bs1 ss0 ss1 kinit hinit compress"
20text dsp "ds_"
21text premeans "text d2means \""
22text presites "text d2sites \""
23text tail "\"\n"
24text header "\nnote D2-GENERATED-BEGIN\n"
25text footer "\nnote D2-GENERATED-END\n"
26
27fn load arg ulong to void
28p = argread arg path 0 len path
29if or le p 0 ge p long len path
30exit 61
31end
32fd = fopen path 0 ulong p 0 0
33if lt fd 0
34exit 62
35end
36n = ulong 0
37while true bound 9223372036854775807
38if gt n sub ulong 9223372036854775807 4096
39exit 63
40end
41if lt len buf add n 4096
42z = enlarge buf add n 4096
43if ne z 0
44exit 63
45end
46end
47nr = read int fd buf n 4096
48if lt nr 0
49exit 64
50end
51if eq nr 0
52break
53end
54n = add n ulong nr
55end
56z = fclose int fd
57put bn 0 n
58end
59
60fn ob c uchar to void
61n = get on 0
62if eq n len obuf
63cap = ulong 9223372036854775807
64if le n div sub cap 4096 2
65cap = add mul n 2 4096
66end
67if eq n cap
68exit 63
69end
70z = enlarge obuf cap
71if ne z 0
72exit 63
73end
74end
75put obuf n c
76put on 0 add n 1
77end
78
79fn ot t view uchar * to void
80for i ulong len t bound 9223372036854775807
81ob get t i
82end
83end
84
85fn esc c uchar to void
86if eq c 10
87ob 92
88ob 110
89else
90if or eq c 92 eq c 34
91ob 92
92end
93ob c
94end
95end
96
97fn match p ulong t view uchar * to bool
98if gt add p len t get bn 0
99ret false
100end
101for i ulong len t bound 9223372036854775807
102if ne get buf add p i get t i
103ret false
104end
105end
106ret true
107end
108
109fn nl p ulong to ulong
110i = p
111while lt i get bn 0 bound 9223372036854775807
112if eq get buf i 10
113ret i
114end
115i = add i 1
116end
117ret i
118end
119
120fn rename a ulong b ulong to bool
121p = ulong 0
122while lt p len names bound 9223372036854775807
123q = p
124while lt q len names bound 9223372036854775807
125if eq get names q 32
126break
127end
128q = add q 1
129end
130if eq sub b a sub q p
131same = true
132for i ulong sub b a bound 9223372036854775807
133if ne get buf add a i get names add p i
134same = false
135end
136end
137if same
138ret true
139end
140end
141p = add q 1
142end
143ret false
144end
145
146fn hashout pos ulong to void
147hinit
148i = ulong 0
149while ge sub get on 0 i 64 bound 9223372036854775807
150for j ulong 64 bound 9223372036854775807
151put blk j get obuf add i j
152end
153compress
154i = add i 64
155end
156n = sub get on 0 i
157for j ulong 64 bound 9223372036854775807
158put blk j 0
159end
160for j ulong n bound 9223372036854775807
161put blk j get obuf add i j
162end
163put blk n 128
164if ge n 56
165compress
166for j ulong 64 bound 9223372036854775807
167put blk j 0
168end
169end
170bits = mul get on 0 8
171for j ulong 8 bound 9223372036854775807
172put blk add 56 j uchar and shr bits mul sub 7 j 8 255
173end
174compress
175hexout pos
176end
177
178fn hexout pos ulong to void
179for j ulong 32 bound 9223372036854775807
180v = and shr get h div j 4 mul sub 3 rem j 4 8 255
181hi = shr v 4
182lo = and v 15
183if lt hi 10
184put obuf add pos mul j 2 uchar add hi 48
185else
186put obuf add pos mul j 2 uchar add hi 87
187end
188if lt lo 10
189put obuf add add pos mul j 2 1 uchar add lo 48
190else
191put obuf add add pos mul j 2 1 uchar add lo 87
192end
193end
194end
195
196fn flush to void
197i = ulong 0
198while lt i get on 0 bound 9223372036854775807
199nr = write 1 obuf i sub get on 0 i
200if le nr 0
201exit 65
202end
203i = add i ulong nr
204end
205end
206
207global marks ulong 2
208fn scan to void
209i = ulong 0
210nb = ulong 0
211ends = ulong 0
212while lt i get bn 0 bound 9223372036854775807
213j = nl i
214if match i beginmark
215put marks 0 i
216nb = add nb 1
217end
218if match i endmark
219put marks 1 add j 1
220ends = add ends 1
221end
222i = add j 1
223end
224if or or ne nb 1 ne ends 1 le get marks 1 get marks 0
225exit 66
226end
227end
228fn sites escaped bool to void
229i = ulong 0
230while lt i get bn 0 bound 9223372036854775807
231j = nl i
232if match i sitehead
233p = add i len sitehead
234while lt p j bound 9223372036854775807
235if escaped
236esc get buf p
237else
238ob get buf p
239end
240p = add p 1
241end
242if escaped
243esc 10
244else
245ob 10
246end
247end
248i = add j 1
249end
250end
251fn means to void
252i = ulong 0
253while lt i get bn 0 bound 9223372036854775807
254j = nl i
255if match i reghead
256p = add i len reghead
257bars = ulong 0
258while lt p j bound 9223372036854775807
259c = get buf p
260if eq c 124
261bars = add bars 1
262if eq bars 1
263esc 124
264end
265else
266if or eq bars 0 eq bars 3
267esc c
268end
269end
270p = add p 1
271end
272esc 10
273end
274i = add j 1
275end
276end
277fn runtimehead to void
278i = ulong 0
279while lt i get bn 0 bound 9223372036854775807
280if match i fnhead
281ret
282end
283ob get buf i
284i = add i 1
285end
286end
287fn runtimebody to void
288i = ulong 0
289while lt i get bn 0 bound 9223372036854775807
290if match i fnhead
291break
292end
293i = add i 1
294end
295while lt i get bn 0 bound 9223372036854775807
296ob get buf i
297i = add i 1
298end
299end
300fn shacore to void
301i = ulong 0
302while lt i get bn 0 bound 9223372036854775807
303if match i shastop
304ret
305end
306c = get buf i
307if or or eq c 32 eq c 10 eq c 13
308ob c
309i = add i 1
310else
311j = i
312while lt j get bn 0 bound 9223372036854775807
313c = get buf j
314if or or eq c 32 eq c 10 eq c 13
315break
316end
317j = add j 1
318end
319if rename i j
320ot dsp
321end
322while lt i j bound 9223372036854775807
323ob get buf i
324i = add i 1
325end
326end
327end
328end
329text sizetag "seeded-"
330text sizedesc "\tGenerated from seeded source and executable\t"
331
332fn decimal n ulong to void
333if ge n 10
334decimal div n 10
335end
336ob uchar add 48 rem n 10
337end
338
339fn sizerecord to void
340load 1
341lines = ulong 0
342functions = ulong 0
343for i ulong get bn 0 bound 9223372036854775807
344start = eq i 0
345if gt i 0
346start = eq get buf sub i 1 10
347end
348if start
349if match i fnhead
350functions = add functions 1
351end
352end
353if eq get buf i 10
354lines = add lines 1
355end
356end
357load 2
358n = get bn 0
359if lt n 176
360exit 67
361end
362if ne rem sub n 176 4 0
363exit 67
364end
365if ne get buf 0 127
366exit 67
367end
368if ne get buf 1 69
369exit 67
370end
371if ne get buf 2 76
372exit 67
373end
374if ne get buf 3 70
375exit 67
376end
377for i ulong n bound 9223372036854775807
378ob get buf i
379end
380hashout 0
381z = enlarge src 64
382if ne z 0
383exit 63
384end
385for i ulong 64
386put src i get obuf i
387end
388put on 0 0
389ot sizetag
390for i ulong 12
391ob get src i
392end
393ot sizedesc
394decimal lines
395ob 9
396decimal functions
397ob 9
398decimal div sub n 176 4
399ob 9
400for i ulong 64
401ob get src i
402end
403ob 10
404flush
405end
406
407fn main to int
408if eq argcnt 3
409sizerecord
410ret 0
411end
412if or lt argcnt 5 gt argcnt 6
413ret 60
414end
415load 1
416scan
417if eq argcnt 6
418sites false
419flush
420ret 0
421end
422z = enlarge src get bn 0
423if ne z 0
424ret 63
425end
426put sn 0 get bn 0
427for i ulong get bn 0 bound 9223372036854775807
428put src i get buf i
429end
430for i ulong get marks 0 bound 9223372036854775807
431ob get src i
432end
433ot beginmark
434ob 10
435ot pinhead
436pinpos = get on 0
437for i ulong 64 bound 9223372036854775807
438ob 48
439end
440ot tail
441load 2
442ot premeans
443means
444ot tail
445load 1
446ot presites
447sites true
448ot tail
449load 4
450runtimehead
451load 3
452shacore
453load 4
454runtimebody
455ot footer
456finish = get marks 1
457if lt finish get sn 0
458for i ulong sub get sn 0 finish bound 9223372036854775807
459ob get src add finish i
460end
461end
462hashout pinpos
463flush
464ret 0
465end