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 / core / cortex / tests / json / t_io.om

132 lines · 2138 bytes Raw Blame History
1note tests/json/t_io.om - test-only buffered stdin records (u32 LE length + bytes) and stdout records.
2note Not part of the product build. Globals prefixed t.
3global tib uchar 16777216
4global tibl ulong 1
5global tibp ulong 1
6global tibe uchar 1
7global tob uchar 16777216
8global tobl ulong 1
9note make at least n bytes available at tibp (compacting and reading); false at end of input
10fn t_need n ulong to bool
11if le n sub get tibl 0 get tibp 0
12ret true
13end
14p = get tibp 0
15l = get tibl 0
16k = sub l p
17t_mv p k
18put tibp 0 0
19put tibl 0 k
20for it ulong 100000
21if le n get tibl 0
22ret true
23end
24if eq get tibe 0 1
25ret false
26end
27l = get tibl 0
28r = read 0 tib l sub 16777216 l
29if le r 0
30put tibe 0 1
31else
32put tibl 0 add l ulong r
33end
34end
35ret false
36end
37fn t_u32 to ulong
38p = get tibp 0
39v = ulong get tib p
40v = or v shl ulong get tib add p 1 8
41v = or v shl ulong get tib add p 2 16
42v = or v shl ulong get tib add p 3 24
43put tibp 0 add p 4
44ret v
45end
46note next record into jin/jinl; false at end
47fn t_rec to bool
48if not t_need 4
49ret false
50end
51n = t_u32
52if not t_need n
53trap 9
54end
55p = get tibp 0
56t_cpin p n
57put tibp 0 add p n
58put jinl 0 n
59ret true
60end
61fn t_flush to void
62n = get tobl 0
63o = ulong 0
64for it ulong 100000
65if ge o n
66put tobl 0 0
67ret
68end
69w = write 1 tob o sub n o
70if le w 0
71trap 8
72end
73o = add o ulong w
74end
75end
76fn t_ob c uchar to void
77n = get tobl 0
78if ge n 16777216
79t_flush
80n = 0
81end
82put tob n c
83put tobl 0 add n 1
84end
85note emit job[0 .. jobl) as one output record
86fn t_emitjob to void
87n = get jobl 0
88if gt add n 4 sub 16777216 get tobl 0
89t_flush
90end
91t_ob uchar and n 255
92t_ob uchar and shr n 8 255
93t_ob uchar and shr n 16 255
94t_ob uchar and shr n 24 255
95i = ulong 0
96for b ulong 4000
97for c ulong 4000
98if ge i n
99ret
100end
101t_ob get job i
102i = add i 1
103end
104end
105end
106note tib[p .. p+k) -> tib[0 ..] (overlap safe: forward copy to a lower index)
107fn t_mv p ulong k ulong to void
108i = ulong 0
109for b ulong 4000
110for c ulong 4000
111if ge i k
112ret
113end
114x = get tib add p i
115put tib i x
116i = add i 1
117end
118end
119end
120fn t_cpin p ulong n ulong to void
121i = ulong 0
122for b ulong 4000
123for c ulong 4000
124if ge i n
125ret
126end
127x = get tib add p i
128put jin i x
129i = add i 1
130end
131end
132end