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