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 / si / harness / examples / structs.om

59 lines · 1362 bytes Raw Blame History
1note structs: 8-byte cells in order, no padding; a struct is never a wire layout
2note a struct line comes before the first fn
3struct Pair a uint b long end
4note ---- output helpers: a function works on a global by naming it (a global is never an argument)
5global ob uchar 32
6note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90
7note bound: every pass writes at least one byte and n <= 32, so at most 32 passes
8fn outb off ulong n ulong to void
9e = add off n
10p = off
11while lt p e bound 32
12k = write 1 ob p sub e p
13if le k 0
14exit 90
15end
16p = add p ulong k
17end
18end
19note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes
20fn putu v ulong to void
21i = ulong 31
22put ob 31 10
23n = v
24while true bound 20
25i = sub i 1
26put ob i uchar add rem n 10 48
27n = div n 10
28if eq n 0
29break
30end
31end
32outb i sub 32 i
33end
34note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1
35fn putl v long to void
36if lt v 0
37put ob 0 45
38outb 0 1
39putu add ulong neg add v 1 1
40ret
41end
42putu ulong v
43end
44note swapsum: an edit parameter may be written; a view parameter may not (error 20)
45fn swapsum p edit Pair to long
46t = long get p a
47put p a uint 7
48ret add t get p b
49end
50fn main to int
51p = new Pair 5 -12
52v = swapsum p
53putl v
54putu ulong get p a
55putu sizeof Pair
56putu offsetof Pair b
57putu sizeof uint
58ret 0
59end