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 / bridge / babel / src / 00-core.om

250 lines · 3324 bytes Raw Blame History
1note babel 00-core: arena builder, persistent pool, decimal and escaping. Program mode, OM-2.
2note Ob is a scratch arena used as a stack (mark/reset); Pl is an append-only pool for strings that
3note outlive one step (paths, names, reasons, vectors, oracle outputs).
4global Ob uchar 8388608
5global Ol ulong 1
6global Pl uchar 8388608
7global Pn ulong 1
8global Fb uchar 524288
9global Fn ulong 1
10global Dn uchar 65536
11global Sb uchar 256
12global Ag uchar 8192
13global Cap ulong 1
14global Hash uchar 32
15
16fn mark to ulong
17ret get Ol 0
18end
19
20fn reset m ulong to void
21put Ol 0 m
22end
23
24fn bc c uchar to void
25o = get Ol 0
26if ge o 8388000
27put Cap 0 1
28ret
29end
30put Ob o c
31put Ol 0 add o 1
32end
33
34fn bs s view uchar * to void
35for i ulong len s
36bc get s i
37end
38end
39
40fn bob o ulong n ulong to void
41for i ulong n
42bc get Ob add o i
43end
44end
45
46fn bpl o ulong n ulong to void
47for i ulong n
48bc get Pl add o i
49end
50end
51
52fn bfb o ulong n ulong to void
53for i ulong n
54bc get Fb add o i
55end
56end
57
58fn bu v ulong to void
59d = new uchar 24 0
60n = ulong 0
61x = v
62while true bound 30
63put d n uchar add 48 rem x 10
64n = add n 1
65x = div x 10
66if eq x 0
67break
68end
69end
70while gt n 0 bound 30
71n = sub n 1
72bc get d n
73end
74end
75
76fn bl v long to void
77if lt v 0
78bc 45
79bu ulong neg v
80ret
81end
82bu ulong v
83end
84
85fn bsp n ulong to void
86for i ulong n
87bc 32
88end
89end
90
91fn bhex v ulong to void
92if lt v 10
93bc uchar add v 48
94ret
95end
96bc uchar add v 87
97end
98
99note copy Ob[o, o+n) into the pool; returns the pool offset
100fn psave o ulong n ulong to ulong
101p = get Pn 0
102if gt add p n 8388000
103put Cap 0 1
104ret p
105end
106for i ulong n
107put Pl add p i get Ob add o i
108end
109put Pn 0 add p n
110ret p
111end
112
113fn ptext s view uchar * to ulong
114p = get Pn 0
115for i ulong len s
116put Pl add p i get s i
117end
118put Pn 0 add p len s
119ret p
120end
121
122fn pleq a ulong an ulong b ulong bn ulong to bool
123if ne an bn
124ret false
125end
126for i ulong an
127if ne get Pl add a i get Pl add b i
128ret false
129end
130end
131ret true
132end
133
134fn plteq o ulong n ulong s view uchar * to bool
135if ne n len s
136ret false
137end
138for i ulong n
139if ne get Pl add o i get s i
140ret false
141end
142end
143ret true
144end
145
146note does Pl[o, o+n) start with text s
147fn plpre o ulong n ulong s view uchar * to bool
148if lt n len s
149ret false
150end
151for i ulong len s
152if ne get Pl add o i get s i
153ret false
154end
155end
156ret true
157end
158
159fn obteq o ulong n ulong s view uchar * to bool
160if ne n len s
161ret false
162end
163for i ulong n
164if ne get Ob add o i get s i
165ret false
166end
167end
168ret true
169end
170
171note does Pl[o, o+n) end with text s
172fn plsuf o ulong n ulong s view uchar * to bool
173if lt n len s
174ret false
175end
176b = add o sub n len s
177for i ulong len s
178if ne get Pl add b i get s i
179ret false
180end
181end
182ret true
183end
184
185note JSON string body of Pl[o, o+n) (no quotes)
186fn bjs o ulong n ulong to void
187for i ulong n
188c = get Pl add o i
189if eq c 34
190bc 92
191bc 34
192continue
193end
194if eq c 92
195bc 92
196bc 92
197continue
198end
199if eq c 10
200bc 92
201bc 110
202continue
203end
204if lt c 32
205bc 92
206bc 117
207bc 48
208bc 48
209bhex ulong shr c 4
210bhex ulong and c 15
211continue
212end
213bc c
214end
215end
216
217fn bjq o ulong n ulong to void
218bc 34
219bjs o n
220bc 34
221end
222
223note Markdown table cell of Pl[o, o+n): pipes escaped, newlines flattened
224fn bmd o ulong n ulong to void
225for i ulong n
226c = get Pl add o i
227if eq c 124
228bc 92
229bc 124
230continue
231end
232if eq c 10
233bc 32
234continue
235end
236if eq c 96
237bc 39
238continue
239end
240bc c
241end
242end
243
244fn bhash to void
245for i ulong 32
246c = get Hash i
247bhex ulong shr c 4
248bhex ulong and c 15
249end
250end