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 / bridge / shlib / test.om

84 lines · 2490 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note bridge/shlib/test.om: the unit of the bridge/shlib gate's test library (test.tsv): a constant, an int
4note addition and division (arguments from C with undefined upper halves; division traps on 0), a pointer write
5note and read, a uint shift, two bodies that need stack (one through a private call), narrow arguments, and a
6note trap inside a private callee.
7export fn omega_shlib_seven to int
8ret 7
9end
10export fn omega_shlib_add a int b int to int
11ret add a b
12end
13export fn omega_shlib_div a int b int to int
14ret div a b
15end
16note pointer parameters: a sized edit or view is one C pointer
17export fn omega_shlib_put c edit uint 2 v uint to int
18put c 1 v
19ret 0
20end
21export fn omega_shlib_get c view uint 2 to uint
22ret get c 1
23end
24note a uint argument (omc needs it zero-extended) and a body with an 8 KiB local array (the wrapper probes
25note its stack pages first)
26export fn omega_shlib_hi a uint to uint
27ret shr a 16
28end
29export fn omega_shlib_sum n uint to uint
30a = new uint 2048 0
31for i ulong 2048
32put a i uint i
33end
34s = uint 0
35for i ulong ulong n bound 2048
36s = add s get a i
37end
38ret s
39end
40note a private function behind an export: the object carries a call record, and the export's stack need is
41note settled through it
42fn deep n uint to uint
43a = new uint 4096 0
44put a 4095 n
45ret add get a 4095 1
46end
47export fn omega_shlib_deep n uint to uint
48ret deep n
49end
50note narrow arguments: omc takes a uchar, ushort, byte or short already extended to 64 bits
51export fn omega_shlib_ub a uchar to uint
52ret uint a
53end
54export fn omega_shlib_uh a ushort to uint
55ret uint a
56end
57export fn omega_shlib_sb a byte to int
58ret int a
59end
60export fn omega_shlib_sh a short to int
61ret int a
62end
63note a trap inside a private callee: the context in x7 reaches it through omc's own call
64fn pdiv a int b int to int
65ret div a b
66end
67export fn omega_shlib_pdiv a int b int to int
68ret pdiv a b
69end
70note a need one call cost past a page: edge's frame is 4080 bytes and the export's call adds its cost, so the
71note probe covers ceil((4080 + cost + 16) / 4096) = 2 pages, 1 if the cost were dropped
72fn edge n uint to uint
73a = new uint 1020 0
74put a 1019 n
75ret add get a 1019 1
76end
77export fn omega_shlib_edge n uint to uint
78ret edge n
79end
80note a float export, left out of test.tsv: the gate's float control adds it to a copy of the table, which the
81note generator must refuse (omc passes floats in x registers, C in v registers)
82export fn omega_shlib_fl a f64 to f64
83ret a
84end