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