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 / vendor / examples / wire_le.om

68 lines · 1581 bytes Raw Blame History
1note wire_le: there is no byte-layout type; encode and decode integers with shifts and masks
2note ---- output helpers: a function works on a global by naming it (a global is never an argument)
3global ob uchar 32
4note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90
5note bound: every pass writes at least one byte and n <= 32, so at most 32 passes
6fn outb off ulong n ulong to void
7e = add off n
8p = off
9while lt p e bound 32
10k = write 1 ob p sub e p
11if le k 0
12exit 90
13end
14p = add p ulong k
15end
16end
17note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes
18fn putu v ulong to void
19i = ulong 31
20put ob 31 10
21n = v
22while true bound 20
23i = sub i 1
24put ob i uchar add rem n 10 48
25n = div n 10
26if eq n 0
27break
28end
29end
30outb i sub 32 i
31end
32note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1
33fn putl v long to void
34if lt v 0
35put ob 0 45
36outb 0 1
37putu add ulong neg add v 1 1
38ret
39end
40putu ulong v
41end
42fn main to int
43b = new uchar 4 0
44h = uint 305419896
45put b 0 uchar and h 255
46put b 1 uchar and shr h 8 255
47put b 2 uchar and shr h 16 255
48put b 3 uchar and shr h 24 255
49for i ulong 4
50putu ulong get b i
51end
52v = or uint get b 0 shl uint get b 1 8
53v = or v shl uint get b 2 16
54v = or v shl uint get b 3 24
55putu ulong v
56note a signed 32-bit decode without integer bitcast (see omega-encoding section 5)
57s = long v
58put b 3 255
59u = or uint get b 0 shl uint get b 1 8
60u = or u shl uint get b 2 16
61u = or u shl uint get b 3 24
62s = long u
63if ge u 2147483648
64s = sub s 4294967296
65end
66putl s
67ret 0
68end