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 / json / tests / big.om

284 lines · 5350 bytes Raw Blame History
1note seed/json/tests/big.om: test driver for inputs above the old 983040-byte bound (json/growing). Program
2note mode, composed after json.om, jsonw.om and jsonf.om under one `om2` line by tests/gate-json.sh.
3note Usage: big MODE [A] < input
4note p [SLIM] parse with size limit SLIM (default jsmaxn); prints "OK tokens"
5note r [CAP] parse, then write every token again through js_wtok into an output array of CAP bytes
6note (default 2098192); prints the JSON text, no newline
7note n [CAP] the whole input is one number lexeme, written by js_wnumb into CAP bytes
8note s [CAP] the whole input is the raw UTF-8 bytes of one string, written by js_wsbuf into CAP bytes
9note f the whole input is one number lexeme: "F status bits text", status js_f64st, bits the f64
10note in hex, text from js_wf64
11note A refusal prints one line: js_init "INIT -code", js_parse "ERR code pos", the writer "WERR code".
12note Exit 0 after printing; 90 a read or write error, 92 usage, 93 more input than the 4194304-byte array.
13note The input is read to its end, never a prefix: a full array is followed by a one-byte probe read.
14note Stack: the input is a local of main (4194304 bytes, the omc limit of 4 MiB of local arrays per
15note function); the tape (1048576 bytes) and the output (2098192 bytes) are locals of the functions it
16note calls; their combined live arrays remain below the 8 MiB program stack.
17
18note ======== output ========
19
20note bg_w: write all of b[o .. o + n); every pass writes at least one byte or exits, so passes <= n
21fn bg_w b view uchar * o ulong n ulong to void
22q = ulong 0
23while lt q n bound 9223372036854775807
24k = write 1 b add o q sub n q
25if le k 0
26exit 90
27end
28q = add q ulong k
29end
30end
31
32fn bg_c c uchar to void
33b = new uchar 1 0
34put b 0 c
35bg_w b 0 1
36end
37
38fn bg_dec v ulong to void
39b = new uchar 20 0
40k = ulong 20
41x = v
42for i ulong 20
43k = sub k 1
44put b k uchar add rem x 10 48
45x = div x 10
46if eq x 0
47break
48end
49end
50bg_w b k sub 20 k
51end
52
53fn bg_hexd v ulong to uchar
54if lt v 10
55ret uchar add v 48
56end
57ret uchar add v 87
58end
59
60fn bg_hex16 v ulong to void
61h = new uchar 16 0
62for i ulong 16
63put h i bg_hexd and shr v mul sub 15 i 4 15
64end
65bg_w h 0 16
66end
67
68fn bg_werr c ulong to void
69bg_c 87
70bg_c 69
71bg_c 82
72bg_c 82
73bg_c 32
74bg_dec c
75bg_c 10
76end
77
78fn bg_err c ulong p ulong to void
79bg_c 69
80bg_c 82
81bg_c 82
82bg_c 32
83bg_dec c
84bg_c 32
85bg_dec p
86bg_c 10
87end
88
89note ======== input and arguments ========
90
91note bg_read: all of stdin into src. Exit 90 on a read error, 93 when one more byte follows a full array.
92note Every pass reads at least one byte or leaves, so passes <= len src.
93fn bg_read src edit uchar * to ulong
94p = ulong 0
95while lt p len src bound 9223372036854775807
96k = read 0 src p sub len src p
97if lt k 0
98exit 90
99end
100if eq k 0
101ret p
102end
103p = add p ulong k
104end
105x = new uchar 1 0
106k = read 0 x 0 1
107if lt k 0
108exit 90
109end
110if gt k 0
111exit 93
112end
113ret p
114end
115
116fn bg_arg i ulong d ulong to ulong
117b = new uchar 32 0
118if le argcnt long i
119ret d
120end
121k = argread i b 0 32
122if or le k 0 gt k 20
123exit 92
124end
125v = ulong 0
126for j ulong ulong k
127c = get b j
128if or lt c 48 gt c 57
129exit 92
130end
131if gt v 1844674407370955160
132exit 92
133end
134v = add mul v 10 ulong sub c 48
135end
136ret v
137end
138
139fn bg_mode to uchar
140b = new uchar 2 0
141if lt argcnt 2
142exit 92
143end
144k = argread 1 b 0 2
145if ne k 1
146exit 92
147end
148ret get b 0
149end
150
151note ======== modes ========
152
153fn bg_done ob edit uchar * to void
154r = js_wdone ob
155if lt r 0
156bg_werr ulong neg r
157ret
158end
159bg_w ob jswh ulong r
160end
161
162note bg_rw2: every token of the tape through js_wtok; one token per pass, so passes <= js_ntok tape
163fn bg_rw2 src view uchar * tape view uint * ob edit uchar * to void
164r = js_winit ob
165if lt r 0
166bg_werr ulong neg r
167ret
168end
169t = ulong 0
170while lt t js_ntok tape bound 9223372036854775807
171js_wtok ob src js_type tape t js_off tape t
172t = add t 1
173end
174bg_done ob
175end
176
177fn bg_rw src view uchar * tape view uint * cap ulong to void
178ob = new uchar 2098192 0
179bg_rw2 src tape part ob 0 cap
180end
181
182fn bg_parse src view uchar * m uchar sl ulong cap ulong to void
183tape = new uint 262144 0
184r = js_init tape sl 512
185if lt r 0
186bg_c 73
187bg_c 78
188bg_c 73
189bg_c 84
190bg_c 32
191bg_c 45
192bg_dec ulong neg r
193bg_c 10
194ret
195end
196r2 = js_parse src tape len src
197if lt r2 0
198bg_err js_err tape js_epos tape
199ret
200end
201if eq m 112
202bg_c 79
203bg_c 75
204bg_c 32
205bg_dec ulong r2
206bg_c 10
207ret
208end
209bg_rw src tape cap
210end
211
212fn bg_wr2 src view uchar * m uchar ob edit uchar * to void
213r = js_winit ob
214if lt r 0
215bg_werr ulong neg r
216ret
217end
218if eq m 110
219js_wnumb ob src 0 len src
220else
221js_wsbuf ob src 0 len src
222end
223bg_done ob
224end
225
226fn bg_wr src view uchar * m uchar cap ulong to void
227ob = new uchar 2098192 0
228bg_wr2 src m part ob 0 cap
229end
230
231fn bg_f src view uchar * to void
232fs = new long jsfs 0
233ob = new uchar 2048 0
234x = js_f64 src 0 fs
235bg_c 70
236bg_c 32
237bg_dec js_f64st fs
238bg_c 32
239bg_hex16 bitcast ulong x
240bg_c 32
241r = js_winit ob
242if lt r 0
243exit 92
244end
245js_wf64 ob x fs
246r2 = js_wdone ob
247if lt r2 0
248bg_werr ulong neg r2
249ret
250end
251bg_w ob jswh ulong r2
252bg_c 10
253end
254
255fn main to int
256src = new uchar 4194304 0
257m = bg_mode
258a = bg_arg 2 2098192
259sl = bg_arg 2 jsmaxn
260n = bg_read src
261if eq m 112
262bg_parse part src 0 n m sl 2098192
263ret 0
264end
265if eq m 114
266if gt a 2098192
267exit 92
268end
269bg_parse part src 0 n m jsmaxn a
270ret 0
271end
272if or eq m 110 eq m 115
273if gt a 2098192
274exit 92
275end
276bg_wr part src 0 n m a
277ret 0
278end
279if eq m 102
280bg_f part src 0 n
281ret 0
282end
283exit 92
284end