interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / omega-reference / page.om

887 lines · 15638 bytes Raw Blame History
1note page: writes /omega/reference/ to stdout from vendor.pin, vendor.sha256 and vendor/
2note Run from om/omega-reference with the pinned omc (check.sh). Inputs are read, never fetched.
3note Markdown subset of the guide: headings, paragraphs, lists, tables, fences, code, bold, links.
4note Every example file is printed byte for byte; html_to_text in seo.rs keeps it so in llms-full.
5om2
6text t_amp "&"
7text t_lt "<"
8text t_gt ">"
9text t_quot """
10note t_hash: the # of a reference such as #775, written as an entity so no # is followed by digits
11text t_hash "#"
12text t_pin "vendor.pin"
13text t_pinkey "omega-harness "
14text t_man "vendor.sha256"
15text t_vend "vendor/"
16text t_skill "skills/writing-omega/SKILL.md"
17text t_gate "examples/gate"
18text t_dotsh ".sh"
19text t_om ".om"
20text t_exp ".expect"
21text t_sin ".stdin"
22text t_arg ".args"
23text t_env ".env"
24text t_out ".stdout"
25text t_fm "---\n"
26text t_dash3 "---"
27text t_fence "```"
28text t_h1 "# "
29text t_h2 "## "
30text t_h3 "### "
31text t_li "- "
32text t_two " "
33text t_bar "|"
34text t_sep "|-"
35text t_up2 "../../"
36text t_up1 "../"
37text t_gh "https://interplane.io/drakestapleton/omega-harness/blob/"
38text t_skl "/skills/"
39note The guide names omega-mv on GitHub; the page links the forge and says the download is not open yet.
40text t_ghmv "https://github.com/aien-dev/omega-mv"
41text t_fgmv "https://interplane.io/drakestapleton/omega-mv"
42text t_ghcl "git clone https://github.com/aien-dev/omega-mv && cd omega-mv"
43text t_rdcl "# omega-mv is moving to Interplane, my own forge; downloads are not open yet."
44text t_pre "<pre>\n"
45text t_epre "</pre>"
46text t_p "<p>"
47text t_ep "</p>"
48text t_ul "<ul>"
49text t_eul "</li></ul>"
50text t_lio "<li>"
51text t_eli "</li>"
52text t_tab "<table>"
53text t_etab "</table>"
54text t_tr "<tr>"
55text t_etr "</tr>"
56text t_th "<th>"
57text t_eth "</th>"
58text t_td "<td>"
59text t_etd "</td>"
60text t_code "<code>"
61text t_ecode "</code>"
62text t_bo "<strong>"
63text t_ebo "</strong>"
64text t_ahref "<a href=\""
65text t_aend "\">"
66text t_ea "</a>"
67text t_hid "<h3 id=\"s"
68text t_art1 "<article class=\"ref-ex\" id=\"ex-"
69text t_art2 "\"><h3>"
70text t_art3 "</h3>"
71text t_eart "</article>"
72text t_lab1 "<p class=\"ref-file\">File: <code>"
73text t_lab2 "</code>"
74text t_empty " (empty file)</p>"
75text t_hexl " (hex bytes)</p><pre>\n"
76text t_nonl " (no final newline)</p><pre>\n"
77text t_endp "</p><pre>\n"
78text t_top1 "<div class=\"om-page ref-page\"><header class=\"om-hero\"><div class=\"container\"><p class=\"om-kicker\">Omega</p><h1 class=\"om-title\">Omega language reference</h1><p class=\"om-lead\">Everything an agent needs to write Omega that the pinned compiler accepts and that does what it should: program shape, types, declarations, statements, words, OM-2, the host words, every compiler error and trap exit code, common mistakes, and "
79text t_top2 " worked examples that each passed the examples gate.</p><p class=\"om-sub\">An Omega program writes this page: <code>om/omega-reference/page.om</code> in the aienos.com repository reads the guide <code>skills/writing-omega/SKILL.md</code> and the examples of omega-harness commit <a href=\""
80text t_top3 "https://interplane.io/drakestapleton/omega-harness/tree/"
81text t_top4 "\"><code>"
82text t_top5 "</code></a> and prints every file byte for byte. The compiler pin is omega-mv <code>e5b32567a7aff3ce594e3254a622a846a6cd190b</code>, omc sha256 <code>2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f</code>. The same text is in <a href=\"/llms-full.txt\">llms-full.txt</a>.</p><nav class=\"om-toc\" aria-label=\"On this page\"><a href=\"#guide\">Guide</a> <a href=\"#s11\">Compiler errors</a> <a href=\"#s5\">Traps</a> <a href=\"#s12\">Common mistakes</a> <a href=\"#examples\">Worked examples</a> <a href=\"#gate\">Checking the examples</a></nav></div></header><div class=\"container\"><section class=\"om-section ref-guide\" id=\"guide\">"
83text t_mid1 "</section><section class=\"om-section ref-examples\" id=\"examples\"><h2 class=\"om-h2\">Worked examples</h2><p>"
84text t_mid2 " programs from <code>examples/</code> and <code>skills/omega-encoding/examples/</code>, each listed with its files. <code>NAME.om</code> is the program. <code>NAME.expect</code> is what the gate checks: <code>compile N</code> is the compiler's exit status, <code>stderr LINE</code> its whole stderr when N is not 0, <code>exit N</code> the program's exit status, <code>input dir</code> and <code>output full</code> the two refusals that need a special compiler input or output. <code>NAME.stdout</code> is the exact standard output, and an absent one means empty. <code>NAME.stdin</code>, <code>NAME.args</code> (one argument per line) and <code>NAME.env</code> (one KEY=VALUE per line) are what the program is given.</p><p>Each file is labelled <code>File: PATH</code> and followed by its bytes in one block. To copy a file out of llms-full.txt, take the lines between its two fences and end each with a newline. A label ending in (no final newline) means the file does not end in a newline, so drop the last one. A label ending in (hex bytes) means the block lists the bytes as two hex digits each, sixteen to a line. A label ending in (empty file) means the file has no bytes and no block follows.</p>"
85text t_end1 "</section><section class=\"om-section ref-gate\" id=\"gate\"><h2 class=\"om-h2\">Checking the examples</h2><p>Write every file on this page into one directory tree with the paths in the labels, then run <code>bash examples/gate.sh /path/to/omc</code>. The gate refuses any compiler but the pinned one. It compiles each program, runs it with an empty environment plus its <code>.env</code> in an empty scratch directory under a 20 second timeout, compares the exit status and the stdout bytes, requires an empty stderr, prints one PASS or FAIL line per program and ends with <code>GATE PASS examples=N</code> when all of them match. The aienos.com build checks that the files in llms-full.txt are these files, and <code>om/omega-reference/llms-check.sh</code> extracts them from llms-full.txt and runs this gate on them.</p>"
86text t_end2 "</section></div></div>"
87global ob uchar 65536
88global fb uchar 262144
89global mb uchar 65536
90global pb uchar 512
91global cm uchar 64
92global st ulong 8
93note st: 0 output fill, 1 file length, 2 manifest length, 3 commit length,
94note 4 path length, 5 bold open, 6 stem length
95
96fn oflush to void
97n = get st 0
98p = ulong 0
99while lt p n bound 65536
100k = write 1 ob p sub n p
101if le k 0
102exit 90
103end
104p = add p ulong k
105end
106put st 0 0
107end
108
109fn putb b uchar to void
110n = get st 0
111if eq n len ob
112oflush
113n = ulong 0
114end
115put ob n b
116put st 0 add n 1
117end
118
119fn outs s view uchar * to void
120for i ulong len s
121putb get s i
122end
123end
124
125fn esc b uchar to void
126if eq b 38
127outs t_amp
128ret
129end
130if eq b 60
131outs t_lt
132ret
133end
134if eq b 62
135outs t_gt
136ret
137end
138if eq b 34
139outs t_quot
140ret
141end
142putb b
143end
144
145note fbhash: fb[p] is # and fb[p+1], before b, is a digit
146fn fbhash p ulong b ulong to bool
147if ne get fb p 35
148ret false
149end
150q = add p 1
151if ge q b
152ret false
153end
154c = get fb q
155if lt c 48
156ret false
157end
158if gt c 57
159ret false
160end
161ret true
162end
163
164note mbhash: the same test in mb
165fn mbhash p ulong b ulong to bool
166if ne get mb p 35
167ret false
168end
169q = add p 1
170if ge q b
171ret false
172end
173c = get mb q
174if lt c 48
175ret false
176end
177if gt c 57
178ret false
179end
180ret true
181end
182
183fn escfb a ulong b ulong to void
184p = a
185while lt p b bound 262144
186if fbhash p b
187outs t_hash
188else
189esc get fb p
190end
191p = add p 1
192end
193end
194
195fn escmb a ulong b ulong to void
196p = a
197while lt p b bound 65536
198if mbhash p b
199outs t_hash
200else
201esc get mb p
202end
203p = add p 1
204end
205end
206
207fn escs s view uchar * to void
208for i ulong len s
209esc get s i
210end
211end
212
213fn outcm to void
214n = get st 3
215for i ulong n
216putb get cm i
217end
218end
219
220fn outdec v ulong to void
221d = new uchar 20 0
222n = ulong 0
223x = v
224while true bound 21
225put d n add uchar rem x 10 48
226n = add n 1
227x = div x 10
228if eq x 0
229break
230end
231end
232while gt n 0 bound 21
233n = sub n 1
234putb get d n
235end
236end
237
238note slurp: read the file named by pb[0 .. st 4) into fb; its length, or -2 when it does not exist
239fn slurp to long
240fd = fopen pb 0 get st 4 0 0
241if lt fd 0
242if eq fd -2
243ret -2
244end
245exit 91
246end
247f = int fd
248t = ulong 0
249while true bound 262145
250if eq t len fb
251exit 92
252end
253k = read f fb t sub len fb t
254if lt k 0
255exit 93
256end
257if eq k 0
258break
259end
260t = add t ulong k
261end
262c = fclose f
263if ne c 0
264exit 93
265end
266put st 1 t
267ret long t
268end
269
270fn pbadd s view uchar * to void
271n = get st 4
272for i ulong len s
273put pb add n i get s i
274end
275put st 4 add n len s
276end
277
278fn pbmb a ulong b ulong to void
279n = get st 4
280p = a
281while lt p b bound 512
282put pb n get mb p
283n = add n 1
284p = add p 1
285end
286put st 4 n
287end
288
289note sw: does fb[p .. q) start with s
290fn sw p ulong q ulong s view uchar * to bool
291n = len s
292if gt n sub q p
293ret false
294end
295for i ulong n
296if ne get fb add p i get s i
297ret false
298end
299end
300ret true
301end
302
303fn eol p ulong e ulong to ulong
304q = p
305while lt q e bound 262144
306if eq get fb q 10
307ret q
308end
309q = add q 1
310end
311ret e
312end
313
314fn meol p ulong e ulong to ulong
315q = p
316while lt q e bound 65536
317if eq get mb q 10
318ret q
319end
320q = add q 1
321end
322ret e
323end
324
325note loadpin: the omega-harness commit from the first line of vendor.pin, into cm
326fn loadpin to void
327put st 4 0
328pbadd t_pin
329n = slurp
330if lt n 0
331exit 94
332end
333e = eol 0 ulong n
334if eq sw 0 e t_pinkey false
335exit 94
336end
337s = len t_pinkey
338if ne sub e s 40
339exit 94
340end
341for i ulong 40
342put cm i get fb add s i
343end
344put st 3 40
345end
346
347fn loadman to void
348put st 4 0
349pbadd t_man
350n = slurp
351if lt n 0
352exit 95
353end
354m = ulong n
355if gt m len mb
356exit 96
357end
358for i ulong m
359put mb i get fb i
360end
361put st 2 m
362end
363
364note isprog: is the manifest line [p .. q) a program, "HASH PATH.om"
365fn isprog p ulong q ulong to bool
366if lt sub q p 70
367ret false
368end
369if ne get mb add p 64 32
370exit 96
371end
372if ne get mb sub q 3 46
373ret false
374end
375if ne get mb sub q 2 111
376ret false
377end
378if ne get mb sub q 1 109
379ret false
380end
381ret true
382end
383
384fn nprogs to ulong
385m = get st 2
386c = ulong 0
387p = ulong 0
388while lt p m bound 4096
389q = meol p m
390if isprog p q
391c = add c 1
392end
393p = add q 1
394end
395ret c
396end
397
398fn bold to void
399if eq get st 5 0
400outs t_bo
401put st 5 1
402else
403outs t_ebo
404put st 5 0
405end
406end
407
408fn icode p ulong b ulong to ulong
409q = add p 1
410while lt q b bound 65536
411if eq get fb q 96
412outs t_code
413escfb add p 1 q
414outs t_ecode
415ret add q 1
416end
417q = add q 1
418end
419esc 96
420ret add p 1
421end
422
423fn iurl a ulong b ulong to void
424if sw a b t_ghmv
425outs t_fgmv
426escfb add a len t_ghmv b
427ret
428end
429if sw a b t_up2
430outs t_gh
431outcm
432putb 47
433escfb add a 6 b
434ret
435end
436if sw a b t_up1
437outs t_gh
438outcm
439outs t_skl
440escfb add a 3 b
441ret
442end
443escfb a b
444end
445
446note ilink: [text](url) at p; a lone [ is printed as it is
447fn ilink p ulong b ulong to ulong
448m = add p 1
449while lt add m 1 b bound 65536
450if and eq get fb m 93 eq get fb add m 1 40
451e = add m 2
452while lt e b bound 65536
453if eq get fb e 41
454outs t_ahref
455iurl add m 2 e
456outs t_aend
457inl add p 1 m
458outs t_ea
459ret add e 1
460end
461e = add e 1
462end
463esc 91
464ret add p 1
465end
466m = add m 1
467end
468esc 91
469ret add p 1
470end
471
472fn isbold p ulong b ulong to bool
473if lt add p 1 b
474if eq get fb add p 1 42
475ret true
476end
477end
478ret false
479end
480
481fn inl a ulong b ulong to void
482p = a
483while lt p b bound 65536
484y = get fb p
485if eq y 96
486p = icode p b
487else
488if and eq y 42 isbold p b
489bold
490p = add p 2
491else
492if eq y 91
493p = ilink p b
494else
495if fbhash p b
496outs t_hash
497else
498esc y
499end
500p = add p 1
501end
502end
503end
504end
505end
506
507note head: a guide heading; # is h2, ## is h3 with id sN from its number, ### is h4
508fn head p ulong q ulong lvl ulong to void
509s = add p add lvl 1
510if eq lvl 2
511outs t_hid
512x = s
513while lt x q bound 8
514y = get fb x
515if or lt y 48 gt y 57
516break
517end
518putb y
519x = add x 1
520end
521outs t_aend
522else
523putb 60
524putb 104
525putb add uchar lvl 49
526putb 62
527end
528inl s q
529putb 60
530putb 47
531putb 104
532putb add uchar lvl 49
533putb 62
534end
535
536fn trims a ulong b ulong to ulong
537p = a
538while lt p b bound 4096
539if ne get fb p 32
540ret p
541end
542p = add p 1
543end
544ret b
545end
546
547fn trime a ulong b ulong to ulong
548q = b
549while gt q a bound 4096
550if ne get fb sub q 1 32
551ret q
552end
553q = sub q 1
554end
555ret a
556end
557
558fn cell a ulong b ulong hdr ulong to void
559s = trims a b
560e = trime s b
561if eq hdr 1
562outs t_th
563inl s e
564outs t_eth
565else
566outs t_td
567inl s e
568outs t_etd
569end
570end
571
572note row: one table row; a | inside a code span does not split cells
573fn row p ulong q ulong hdr ulong to void
574a = add p 1
575b = trime a q
576if gt b a
577if eq get fb sub b 1 124
578b = sub b 1
579end
580end
581outs t_tr
582s = a
583c = ulong 0
584x = a
585while lt x b bound 4096
586y = get fb x
587if eq y 96
588c = xor c 1
589end
590if and eq y 124 eq c 0
591cell s x hdr
592s = add x 1
593end
594x = add x 1
595end
596cell s b hdr
597outs t_etr
598end
599
600fn mdclose mode ulong to void
601if eq mode 1
602outs t_ep
603end
604if eq mode 2
605outs t_eul
606end
607if eq mode 3
608outs t_etab
609end
610if eq mode 4
611outs t_epre
612end
613end
614
615note mdline: one guide line in state mode (0 none, 1 paragraph, 2 list, 3 table, 4 fence)
616fn mdline p ulong q ulong mode ulong to ulong
617if eq mode 4
618if sw p q t_fence
619outs t_epre
620ret 0
621end
622if and eq sub q p len t_ghcl sw p q t_ghcl
623escs t_rdcl
624else
625escfb p q
626end
627putb 10
628ret 4
629end
630if sw p q t_fence
631mdclose mode
632outs t_pre
633ret 4
634end
635if eq p q
636mdclose mode
637ret 0
638end
639if sw p q t_h3
640mdclose mode
641head p q 3
642ret 0
643end
644if sw p q t_h2
645mdclose mode
646head p q 2
647ret 0
648end
649if sw p q t_h1
650mdclose mode
651head p q 1
652ret 0
653end
654if sw p q t_li
655if eq mode 2
656outs t_eli
657else
658mdclose mode
659outs t_ul
660end
661outs t_lio
662inl add p 2 q
663ret 2
664end
665if and eq mode 2 sw p q t_two
666putb 10
667inl add p 2 q
668ret 2
669end
670if sw p q t_bar
671if sw p q t_sep
672ret 3
673end
674if eq mode 3
675row p q 0
676ret 3
677end
678mdclose mode
679outs t_tab
680row p q 1
681ret 3
682end
683if eq mode 1
684putb 10
685else
686mdclose mode
687outs t_p
688end
689inl p q
690ret 1
691end
692
693fn skipfm e ulong to ulong
694if sw 0 e t_fm
695p = ulong 4
696while lt p e bound 100000
697q = eol p e
698if eq sub q p 3
699if sw p q t_dash3
700ret add q 1
701end
702end
703p = add q 1
704end
705end
706ret 0
707end
708
709fn guide to void
710put st 4 0
711pbadd t_vend
712pbadd t_skill
713n = slurp
714if lt n 0
715exit 97
716end
717e = ulong n
718p = skipfm e
719mode = ulong 0
720while lt p e bound 100000
721q = eol p e
722mode = mdline p q mode
723p = add q 1
724end
725mdclose mode
726if ne get st 5 0
727exit 97
728end
729end
730
731fn hexd v uchar to uchar
732if lt v 10
733ret add v 48
734end
735ret add v 87
736end
737
738fn hexout n ulong to void
739for i ulong n
740b = get fb i
741putb hexd shr b 4
742putb hexd and b 15
743j = add i 1
744if eq rem j 16 0
745putb 10
746else
747if lt j n
748putb 32
749end
750end
751end
752if ne rem n 16 0
753putb 10
754end
755end
756
757note kind: 0 text ending in a newline, 1 text without one, 2 bytes to show in hex
758fn kind n ulong to ulong
759vis = ulong 0
760for i ulong n
761b = get fb i
762if gt b 126
763ret 2
764end
765if lt b 32
766if and ne b 9 ne b 10
767ret 2
768end
769end
770if gt b 32
771vis = ulong 1
772end
773end
774if eq vis 0
775ret 2
776end
777if eq get fb sub n 1 10
778ret 0
779end
780ret 1
781end
782
783note efile: pb holds vendor/STEM; print STEM plus x when that file exists
784fn efile x view uchar * to void
785put st 4 get st 6
786pbadd x
787r = slurp
788if lt r 0
789ret
790end
791n = ulong r
792outs t_lab1
793e = get st 4
794for i ulong sub e 7
795esc get pb add i 7
796end
797outs t_lab2
798if eq n 0
799outs t_empty
800ret
801end
802k = kind n
803if eq k 2
804outs t_hexl
805hexout n
806outs t_epre
807ret
808end
809if eq k 1
810outs t_nonl
811else
812outs t_endp
813end
814escfb 0 n
815outs t_epre
816end
817
818fn example a ulong q ulong to void
819s = sub q 3
820nb = a
821x = a
822while lt x s bound 512
823if eq get mb x 47
824nb = add x 1
825end
826x = add x 1
827end
828outs t_art1
829escmb nb s
830outs t_art2
831escmb nb s
832outs t_art3
833put st 4 0
834pbadd t_vend
835pbmb a s
836put st 6 get st 4
837efile t_om
838efile t_exp
839efile t_sin
840efile t_arg
841efile t_env
842efile t_out
843outs t_eart
844end
845
846fn examples to void
847m = get st 2
848p = ulong 0
849while lt p m bound 4096
850q = meol p m
851if isprog p q
852example add p 66 q
853end
854p = add q 1
855end
856end
857
858fn main to int
859loadpin
860loadman
861c = nprogs
862if eq c 0
863exit 96
864end
865outs t_top1
866outdec c
867outs t_top2
868outs t_top3
869outcm
870outs t_top4
871outcm
872outs t_top5
873guide
874outs t_mid1
875outdec c
876outs t_mid2
877examples
878outs t_end1
879put st 4 0
880pbadd t_vend
881pbadd t_gate
882put st 6 get st 4
883efile t_dotsh
884outs t_end2
885oflush
886ret 0
887end