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 / train / omega-llm / tools / combined / combined.om

657 lines · 9982 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Linked with the existing benchmark path, process, and execpure grading primitives.
3text formal "om_formalize"
4text sk "om_sketch"
5text sy "om_synth"
6text neural "ollm"
7text spec "input.spec"
8text source "function.om"
9text promptfile "prompt"
10text logname "status"
11text raw "answer"
12text formcmd "formalize"
13text solvecmd "solve"
14text specsample "spsamp"
15text r6 "r6.ck"
16text r3 "r3.ck"
17text r11 "r11.ck"
18text fast "base.ck"
19text traceck "trace.ck"
20text merges "merges.bin"
21text s1 "S1_arith.sp"
22text s2 "S2_fold.sp"
23text s3 "S3_rewrite.sp"
24text s4 "S4_repair.sp"
25text missform "FORMALIZE_ABSTAIN\n"
26text misssk "SKETCH_FAIL\n"
27text misssy "SYNTH_FAIL nodes="
28text noStrand ""
29text size64 "64"
30text heat "700"
31text badinput "combined: malformed prompt or numeric examples\n"
32text failure "combined: component or file failed\n"
33text absent "combined: no candidate passed the supplied examples\n"
34text from "route "
35text linefeed "\n"
36text arity "arity "
37text knobs "\ndepth 2\nconsts 0 1 2 3\n"
38text cs "case"
39text fs "fold"
40text rs "rew"
41text setarr "put arr "
42text calcwords "add sub mul div rem and or xor shl shr eq ne lt le gt ge not true false if else end while for bound break continue ret put get new int uint ulong long uchar bool ="
43text paramTo "to"
44text paramView "view"
45text paramEdit "edit"
46text equalSign "="
47text bindFor "for "
48text bindEnd " ulong 0\nend\n"
49global names ulong *
50global cfg ulong 8
51note cfg: prompt size, signature start/end, shape, example count.
52global cases ulong 1088
53
54fn kfile t view uchar * to void
55pclr
56parg 1
57pch 47
58ptx t
59end
60
61fn kitarg t view uchar * to void
62kfile t
63kpath
64end
65
66fn workarg t view uchar * to void
67wpath t
68kpath
69end
70
71fn present t view uchar * to bool
72kfile t
73f = fopen pth 0 get st 3 0 0
74if lt f 0
75ret false
76end
77x = fclose int f
78ret true
79end
80
81fn cbRun dest view uchar * to long
82wpath dest
83fo = popen true 384
84pclr
85ptx tnull
86fi = popen false 0
87p = spawn fi fo false
88x = fclose fi
89y = fclose fo
90ret waitp p 60000
91end
92
93note Load a bounded regular file through one descriptor. Each input stays in its own mem range.
94fn cbLoad limit ulong to ulong
95fd = popen false 0
96sz = fseek fd 0 2
97if or lt sz 0 gt ulong sz limit
98die badinput 65
99end
100if ne fseek fd 0 0 0
101die failure 70
102end
103b = get st 6
104e = add b ulong sz
105grow = enlarge mem add e 1
106if lt grow 0
107die failure 70
108end
109p = b
110while lt p e bound 65536
111k = read fd mem p sub e p
112if le k 0
113die failure 70
114end
115p = add p ulong k
116end
117if ne read fd mem e 1 0
118die failure 70
119end
120cl = fclose fd
121put st 6 e
122ret b
123end
124
125fn wload t view uchar * to ulong
126wpath t
127ret cbLoad 65535
128end
129
130fn resolved rc long miss view uchar * to bool
131if eq rc 0
132ret true
133end
134b = wload logname
135if and eq rc 1 sw b get st 6 miss
136ret false
137end
138die failure 70
139ret false
140end
141
142fn readprompt to void
143pclr
144parg 4
145b = cbLoad 4095
146e = get st 6
147if or lt e 18 gt e 4095
148die badinput 65
149end
150p = lend 0 e
151s = add p 1
152q = lend s e
153if or not sw 0 p gnote not sw s q gsolve
154die badinput 65
155end
156if or le p len gnote gt e add q 1
157die badinput 65
158end
159for i ulong e bound 4095
160v = get mem i
161if and lt v 32 ne v 10
162die badinput 65
163end
164end
165put cfg 0 q
166put cfg 1 s
167put cfg 2 q
168put cfg 3 shapeof add s len gsolve q
169put st 2 0
170gmem 0 q
171gc 10
172wpath promptfile
173fsave 384
174end
175
176fn canonical a ulong w ulong to ulong
177v = dec a w
178di = udec v
179note Canonical decimal round trip also rejects unsigned overflow and leading zeroes.
180if ne sub w a sub 24 di
181die badinput 65
182end
183for z ulong sub w a bound 20
184if ne get mem add a z get dg add di z
185die badinput 65
186end
187end
188ret v
189end
190
191fn readrow p ulong q ulong width ulong to void
192a = skipsp p q
193r = get cfg 4
194if or ge r 64 ne nwords a q width
195die badinput 65
196end
197for j ulong width bound 17
198w = wordend a q
199v = canonical a w
200if and and ge get cfg 3 4 eq j 0 gt v 8
201die badinput 65
202end
203put cases add mul r 17 j v
204a = skipsp w q
205end
206put cfg 4 add r 1
207end
208
209fn readcases to void
210pclr
211parg 5
212p = cbLoad 24576
213e = get st 6
214sh = get cfg 3
215width = add sh 1
216if eq sh 4
217width = 10
218end
219if eq sh 5
220width = 17
221end
222while lt p e bound 65
223q = lend p e
224readrow p q width
225p = add q 1
226end
227if eq get cfg 4 0
228die badinput 65
229end
230end
231
232fn numberarg x ulong to void
233gc 32
234gu x
235end
236
237fn exampleSpec to void
238sh = get cfg 3
239put st 2 0
240gtx arity
241gu sh
242gtx knobs
243for i ulong get cfg 4 bound 64
244if eq i 8
245break
246end
247b = mul i 17
248n = add sh 1
249if le sh 3
250gtx cs
251else
252if eq sh 5
253gtx rs
254n = 17
255else
256gtx fs
257n = add get cases b 1
258end
259end
260for j ulong n bound 17
261numberarg get cases add b j
262end
263if eq sh 4
264numberarg get cases add b 9
265end
266gc 10
267end
268wpath spec
269fsave 384
270end
271
272note Allowed instruction words. The seeded compiler checks their grammar, types and scope.
273fn instruction p ulong q ulong to bool
274w = ulong 0
275while lt w len calcwords bound 512
276z = w
277while lt z len calcwords bound 512
278if eq get calcwords z 32
279break
280end
281z = add z 1
282end
283if meq p q part calcwords w sub z w
284ret true
285end
286w = add z 1
287end
288ret false
289end
290
291fn digitsOnly p ulong q ulong to bool
292for i ulong sub q p
293c = get mem add p i
294if or lt c 48 gt c 57
295ret false
296end
297end
298ret gt q p
299end
300
301fn knownName p ulong q ulong to bool
302for i ulong get cfg 5
303start = get names mul i 2
304size = get names add mul i 2 1
305if mm p sub q p start size
306ret true
307end
308end
309ret false
310end
311
312fn bindName p ulong q ulong to bool
313if or eq p q gt sub q p 63
314ret false
315end
316c = get mem p
317if or eq c 45 and ge c 48 le c 57
318ret false
319end
320for i ulong sub q p
321c = get mem add p i
322if or le c 32 or eq c 34 or eq c 40 eq c 41
323ret false
324end
325end
326if instruction p q
327ret false
328end
329if not knownName p q
330i = mul get cfg 5 2
331capacity = enlarge names add i 2
332if lt capacity 0
333die failure 70
334end
335put names i p
336put names add i 1 sub q p
337put cfg 5 add get cfg 5 1
338end
339ret true
340end
341
342note readprompt already checked the signature. Consume each scalar or sized-array parameter.
343fn bindParams to void
344p = add get cfg 1 len gsolve
345q = get cfg 2
346while lt p q
347w = wordend p q
348if meq p w paramTo
349break
350end
351if not bindName p w
352die failure 70
353end
354p = skipsp w q
355w = wordend p q
356if or meq p w paramView meq p w paramEdit
357p = skipsp w q
358p = skipsp wordend p q q
359w = wordend p q
360end
361p = skipsp w q
362end
363end
364
365fn mathbody b ulong e ulong to bool
366put cfg 5 0
367bindParams
368p = b
369while lt p e bound 65536
370q = lend p e
371a = skipsp p q
372w = wordend a q
373nextWord = skipsp w q
374nextEnd = wordend nextWord q
375if meq nextWord nextEnd equalSign
376if not bindName a w
377ret false
378end
379end
380if meq a w twfor
381if not bindName nextWord nextEnd
382ret false
383end
384end
385while lt a q bound 65536
386w = wordend a q
387if not or digitsOnly a w or instruction a w knownName a w
388ret false
389end
390a = skipsp w q
391end
392p = add q 1
393end
394ret true
395end
396
397note Check every proposed identifier in an unambiguous declaration position.
398note This asks the same compiler that executes the checker which names are reserved.
399fn validateNames to void
400for i ulong get cfg 5
401gtx bindFor
402gmem get names mul i 2 get names add mul i 2 1
403gtx bindEnd
404end
405end
406
407fn checkbody b ulong e ulong to bool
408z = bodyend b e
409if eq z 0
410ret false
411end
412if or more sub z 1 e not mathbody b e
413ret false
414end
415put st 2 0
416gmem get cfg 1 sub get cfg 2 get cfg 1
417gc 10
418gmem b sub e b
419gc 10
420gtx gmain0
421validateNames
422sh = get cfg 3
423if ge sh 4
424gtx garr0
425end
426for i ulong get cfg 4 bound 64
427o = mul i 17
428if le sh 3
429gtx gifne
430for j ulong sh bound 3
431gtx gsul
432gu get cases add o j
433end
434gtx gsul
435gu get cases add o sh
436gtx gfail
437else
438for j ulong 8
439gtx setarr
440gu j
441numberarg get cases add add o 1 j
442gc 10
443end
444if eq sh 4
445gtx gifne
446gtx garrul
447gu get cases o
448gtx gsul
449gu get cases add o 9
450gtx gfail
451else
452gtx gcall
453gtx garrul
454gu get cases o
455gc 10
456for j ulong 8
457gtx gifget
458gu j
459gtx gsul
460gu get cases add add o 9 j
461gtx gfail
462end
463end
464end
465end
466gtx gret77
467rc = compile
468if eq rc 127
469die failure 70
470end
471if ne rc 0
472ret false
473end
474ret eq runp false 77
475end
476
477fn emitbody b ulong e ulong route view uchar * to bool
478if ge b e
479ret false
480end
481if gt get cfg 4 0
482if not checkbody b e
483ret false
484end
485end
486w = write 2 from 0 len from
487w = write 2 route 0 len route
488w = write 2 linefeed 0 1
489p = b
490while lt p e bound 65536
491n = write 1 mem p sub e p
492if le n 0
493die failure 70
494end
495p = add p ulong n
496end
497ret true
498end
499
500fn symbol exe view uchar * miss view uchar * to bool
501kclr
502kitarg exe
503ktx solvecmd
504workarg spec
505workarg source
506if not resolved cbRun logname miss
507ret false
508end
509b = wload source
510e = get st 6
511q = lend b e
512if not mm b sub q b get cfg 1 sub get cfg 2 get cfg 1
513ret false
514end
515body = add q 1
516if ge body e
517die failure 70
518end
519z = bodyend body e
520if eq z 0
521die failure 70
522end
523if more sub z 1 e
524die failure 70
525end
526ret emitbody body e exe
527end
528
529fn solveSpec to bool
530if symbol sk misssk
531ret true
532end
533if le get cfg 3 4
534ret symbol sy misssy
535end
536ret false
537end
538
539fn draw ck view uchar * strand view uchar * seed ulong to bool
540kclr
541kitarg neural
542if eq len strand 0
543ktx csample
544kitarg ck
545ktx a42
546ktx a128
547ktx a0
548else
549ktx specsample
550kitarg ck
551kitarg strand
552ktx size64
553ktx heat
554end
555put st 2 0
556gmem 0 get cfg 0
557if ne len strand 0
558gc 10
559end
560kprog
561if ne len strand 0
562put st 2 0
563gu seed
564kprog
565end
566kitarg merges
567if ne cbRun raw 0
568die failure 70
569end
570b = wload raw
571if eq len strand 0
572ret emitbody b get st 6 ck
573end
574ret emitbody b get st 6 strand
575end
576
577fn strandDraw s view uchar * first ulong to bool
578if not present s
579ret false
580end
581for j ulong 4
582if draw r3 s add first j
583ret true
584end
585end
586ret false
587end
588
589fn main to int
590if and ne argcnt 5 ne argcnt 6
591die badinput 2
592end
593put st 26 2
594put st 27 3
595readprompt
596if eq argcnt 6
597readcases
598end
599kclr
600kitarg formal
601ktx formcmd
602workarg promptfile
603workarg spec
604if resolved cbRun logname missform
605if solveSpec
606ret 0
607end
608end
609if eq argcnt 6
610exampleSpec
611if solveSpec
612ret 0
613end
614end
615if draw r6 noStrand 0
616ret 0
617end
618if eq argcnt 5
619die absent 1
620end
621if present r3
622if draw r3 noStrand 0
623ret 0
624end
625end
626if present fast
627if draw fast noStrand 0
628ret 0
629end
630end
631if present traceck
632if draw traceck noStrand 0
633ret 0
634end
635end
636if present r11
637if draw r11 noStrand 0
638ret 0
639end
640end
641if present r3
642if strandDraw s1 1000
643ret 0
644end
645if strandDraw s2 1100
646ret 0
647end
648if strandDraw s3 1200
649ret 0
650end
651if strandDraw s4 1300
652ret 0
653end
654end
655die absent 1
656ret 1
657end