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 / seed / ng / a64 / tests / macho / lib / libmath.om
| 1 | target macos |
| 2 | note libmath: the float registers. sqrt(2.0) through d0 and pow(2.0, 10.0) through d0 and d1; the results come |
| 3 | note back at byte 64 of the register file. Status 1 when both have the exact bits, else 2 or 3. |
| 4 | text s_sqrt "sqrt" |
| 5 | text s_pow "pow" |
| 6 | |
| 7 | fn p64 b edit uchar 128 o ulong v ulong to void |
| 8 | for i ulong 8 |
| 9 | put b add o i uchar and shr v mul i 8 255 |
| 10 | end |
| 11 | end |
| 12 | |
| 13 | fn g64 b view uchar 128 o ulong to ulong |
| 14 | v = ulong 0 |
| 15 | for i ulong 8 |
| 16 | v = or v shl ulong get b add o i mul i 8 |
| 17 | end |
| 18 | ret v |
| 19 | end |
| 20 | |
| 21 | note the address of the library function named by the n bytes of nm (nm is zero after them) |
| 22 | fn sym rg edit uchar 128 nm edit uchar 64 to ulong |
| 23 | p64 rg 0 18446744073709551614 |
| 24 | p64 rg 8 ulong libptr nm 0 64 |
| 25 | ret ulong libcall ulong libfn 1 rg 0 128 |
| 26 | end |
| 27 | |
| 28 | fn main to int |
| 29 | rg = new uchar 128 0 |
| 30 | nm = new uchar 64 0 |
| 31 | for i ulong len s_sqrt |
| 32 | put nm i get s_sqrt i |
| 33 | end |
| 34 | put nm len s_sqrt 0 |
| 35 | f = sym rg nm |
| 36 | p64 rg 64 4611686018427387904 |
| 37 | r = libcall f rg 0 128 |
| 38 | if ne g64 rg 64 4609047870845172685 |
| 39 | ret 2 |
| 40 | end |
| 41 | for i ulong len s_pow |
| 42 | put nm i get s_pow i |
| 43 | end |
| 44 | put nm len s_pow 0 |
| 45 | g = sym rg nm |
| 46 | p64 rg 64 4611686018427387904 |
| 47 | p64 rg 72 4621819117588971520 |
| 48 | r = libcall g rg 0 128 |
| 49 | if ne g64 rg 64 4652218415073722368 |
| 50 | ret 3 |
| 51 | end |
| 52 | ret 1 |
| 53 | end |