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 / om / tls / test / acvp / acvpio.om

244 lines · 3046 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note acvpio.om: record reader and output writer shared by the ACVP drivers (acvp.om, mlkemacvp.om).
3note Composition: acvpio.om, then the driver (which defines drrec a b c), then acvpmain.om (fn main).
4note No library calls here.
5
6global inp uchar 16777216
7global outb uchar 1048576
8global st ulong 16
9global one uchar 1
10text hexd "0123456789ABCDEF"
11text tbad "BAD"
12text tio "acvp: cannot read input or input over 16 MiB\n"
13
14note st: 0 input length, 1 cursor, 2 line number, 3 malformed flag, 4 line start, 5 records,
15note 6 malformed records, 7 output fill
16
17fn drslurp to int
18t = ulong 0
19while true bound 999999
20room = sub len inp t
21if eq room 0
22r = read 0 one 0 1
23if ne r 0
24ret 2
25end
26break
27end
28r = read 0 inp t room
29if lt r 0
30ret 2
31end
32if eq r 0
33break
34end
35t = add t ulong r
36end
37put st 0 t
38ret 0
39end
40
41fn oflush to void
42n = get st 7
43o = ulong 0
44while lt o n bound 999999
45r = write 1 outb o sub n o
46if le r 0
47break
48end
49o = add o ulong r
50end
51put st 7 0
52end
53
54fn obyte c ulong to void
55if ge get st 7 len outb
56oflush
57end
58put outb get st 7 uchar c
59put st 7 add get st 7 1
60end
61
62fn ohex a view uchar * to void
63obyte 32
64if eq len a 0
65obyte 45
66ret
67end
68for i ulong len a
69v = ulong get a i
70obyte ulong get hexd shr v 4
71obyte ulong get hexd and v 15
72end
73end
74
75fn odec v ulong to void
76b = new uchar 24 0
77x = v
78k = ulong 0
79while true bound 21
80put b sub 23 k uchar add 48 rem x 10
81k = add k 1
82x = div x 10
83if eq x 0
84break
85end
86end
87for i ulong k
88obyte ulong get b add sub 24 k i
89end
90end
91
92fn ofld v ulong to void
93obyte 32
94odec v
95end
96
97fn drpeek to ulong
98c = get st 1
99if ge c get st 0
100ret 256
101end
102ret ulong get inp c
103end
104
105fn dradv to void
106put st 1 add get st 1 1
107end
108
109fn drbad to void
110put st 3 1
111end
112
113fn isbad to bool
114ret eq get st 3 1
115end
116
117fn drhexv c ulong to ulong
118if ge c 48
119if le c 57
120ret sub c 48
121end
122end
123if ge c 97
124if le c 102
125ret sub c 87
126end
127end
128if ge c 65
129if le c 70
130ret sub c 55
131end
132end
133ret 16
134end
135
136fn drbyte to uchar
137hi = drhexv drpeek
138dradv
139lo = drhexv drpeek
140dradv
141if gt hi 15
142drbad
143ret 0
144end
145if gt lo 15
146drbad
147ret 0
148end
149ret uchar or shl hi 4 lo
150end
151
152fn drsp to void
153if ne drpeek 32
154drbad
155ret
156end
157dradv
158end
159
160note a decimal number (at most 19 digits) after one space
161fn drnum to ulong
162drsp
163v = ulong 0
164k = ulong 0
165while true bound 21
166c = drpeek
167if lt c 48
168break
169end
170if gt c 57
171break
172end
173v = add mul v 10 sub c 48
174k = add k 1
175dradv
176end
177if eq k 0
178drbad
179end
180if gt k 19
181drbad
182end
183ret v
184end
185
186note one space, then hex bytes into a[0..n) (or "-"); returns n
187fn drhex a edit uchar * to ulong
188drsp
189if eq drpeek 45
190dradv
191ret 0
192end
193n = ulong 0
194while true bound 999999
195if gt drhexv drpeek 15
196break
197end
198if ge n len a
199drbad
200ret n
201end
202put a n drbyte
203n = add n 1
204end
205if eq n 0
206drbad
207end
208ret n
209end
210
211fn dreor to void
212if eq drpeek 13
213dradv
214end
215c = drpeek
216if eq c 10
217dradv
218ret
219end
220if ne c 256
221drbad
222end
223end
224
225fn drskip to void
226while true bound 999999
227c = drpeek
228if eq c 256
229ret
230end
231dradv
232if eq c 10
233ret
234end
235end
236end
237
238note the record's ID: printed first, kept in st 8 for the BAD line
239fn drid to void
240id = drnum
241put st 8 id
242odec id
243end
244