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 / ng / a64 / tests / macho / lib / libloop.om

78 lines · 1406 bytes Raw Blame History
1target macos
2note libloop: values that live across library calls. 200 calls of getpid in a loop with eight running sums; each
3note sum must come out as computed without the calls, and every call must give the same number. Status 1.
4text s_getpid "getpid"
5
6fn p64 b edit uchar 128 o ulong v ulong to void
7for i ulong 8
8put b add o i uchar and shr v mul i 8 255
9end
10end
11
12fn g64 b view uchar 128 o ulong to ulong
13v = ulong 0
14for i ulong 8
15v = or v shl ulong get b add o i mul i 8
16end
17ret v
18end
19
20note the address of the library function named by the n bytes of nm (nm is zero after them)
21fn sym rg edit uchar 128 nm edit uchar 64 to ulong
22p64 rg 0 18446744073709551614
23p64 rg 8 ulong libptr nm 0 64
24ret ulong libcall ulong libfn 1 rg 0 128
25end
26
27fn main to int
28rg = new uchar 128 0
29nm = new uchar 64 0
30for i ulong len s_getpid
31put nm i get s_getpid i
32end
33put nm len s_getpid 0
34f = sym rg nm
35pid = libcall f rg 0 128
36if le pid 0
37ret 2
38end
39a = ulong 1
40b = ulong 2
41c = ulong 3
42d = ulong 4
43e = ulong 5
44g = ulong 6
45h = ulong 7
46bad = ulong 0
47x = f64 1.5
48for i ulong 200
49a = add a i
50b = add b mul i 2
51c = add c mul i 3
52d = xor d add i 11
53e = add e a
54g = add g b
55h = xor h c
56x = add x f64 0.25
57q = libcall f rg 0 128
58if ne q pid
59bad = add bad 1
60end
61if ne g64 rg 0 ulong pid
62bad = add bad 1
63end
64end
65if ne bad 0
66ret 3
67end
68if or ne a 19901 ne b 39802
69ret 4
70end
71if ne c 59703
72ret 5
73end
74if ne x f64 51.5
75ret 6
76end
77ret 1
78end