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 / imp.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note bridge/shlib/imp.om: the unit of the gate's import library (imp.tsv): imports from the dependency library |
| 4 | note (dep.om) and the C library, frame exports over three states, and a lock (imp.tsv's lock row). |
| 5 | extern fn omega_dep_twice a ulong to ulong |
| 6 | extern fn omega_dep_dirty to int |
| 7 | extern fn omega_dep_sub a ulong b ulong to ulong |
| 8 | extern fn omega_dep_rd c view uint 1024 to uint |
| 9 | extern fn strlen s view uchar 4096 to ulong |
| 10 | note many values live across each import call: omc keeps them over the BL, the veneer keeps x7 and x30 |
| 11 | export fn omega_imp_live fr view ulong 11 to ulong |
| 12 | a = get fr 0 |
| 13 | b = add a 1 |
| 14 | c = add a 2 |
| 15 | d = add a 3 |
| 16 | e = add a 4 |
| 17 | f = add a 5 |
| 18 | g = omega_dep_twice a |
| 19 | h = omega_dep_twice b |
| 20 | ret add add add add add add c d e f g h b |
| 21 | end |
| 22 | note a counter in state ImpS: 1, 2, 3 over the calls |
| 23 | export fn omega_imp_count fr view ulong 11 s edit ulong 8 to ulong |
| 24 | put s 0 add get s 0 1 |
| 25 | ret get s 0 |
| 26 | end |
| 27 | note a trap inside a frame export: the lock must be released on the trap path |
| 28 | export fn omega_imp_trap fr view ulong 11 to ulong |
| 29 | ret div get fr 0 get fr 1 |
| 30 | end |
| 31 | note a dirty result imported as int: omc's int add traps without the veneer's sign extension |
| 32 | export fn omega_imp_dirty fr view ulong 11 to int |
| 33 | ret add omega_dep_dirty int 1 |
| 34 | end |
| 35 | note the import row of omega_dep_sub swaps its arguments |
| 36 | export fn omega_imp_swap fr view ulong 11 to ulong |
| 37 | ret omega_dep_sub get fr 0 get fr 1 |
| 38 | end |
| 39 | note the import row of omega_dep_rd moves the pointer by 8 bytes (two uints) |
| 40 | export fn omega_imp_off fr view ulong 11 t edit uint 1024 to uint |
| 41 | put t 2 uint get fr 0 |
| 42 | ret omega_dep_rd t |
| 43 | end |
| 44 | note the C library's strlen over the text state ImpT |
| 45 | export fn omega_imp_strlen fr view ulong 11 t edit uchar 4096 to ulong |
| 46 | for i ulong get fr 0 bound 4095 |
| 47 | put t i 97 |
| 48 | end |
| 49 | put t get fr 0 0 |
| 50 | ret strlen t |
| 51 | end |
| 52 | note the frame: the second C argument, and the state addresses (fr 8..10) are 64-byte aligned and distinct |
| 53 | export fn omega_imp_frame fr view ulong 11 to ulong |
| 54 | if ne and get fr 8 63 0 |
| 55 | ret 1000 |
| 56 | end |
| 57 | if eq get fr 8 get fr 9 |
| 58 | ret 1001 |
| 59 | end |
| 60 | ret get fr 1 |
| 61 | end |