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 / research / om-bench / controls / fibo-authz.om
| 1 | note Read unsigned decimal numbers separated by spaces or newlines from stdin; print their sum. |
| 2 | global inb uchar 65536 |
| 3 | global outb uchar 32 |
| 4 | fn readall to ulong |
| 5 | n = ulong 0 |
| 6 | while lt n 65536 bound 65537 |
| 7 | k = read 0 inb n sub 65536 n |
| 8 | if lt k 0 |
| 9 | exit 2 |
| 10 | end |
| 11 | if eq k 0 |
| 12 | break |
| 13 | end |
| 14 | n = add n ulong k |
| 15 | end |
| 16 | ret n |
| 17 | end |
| 18 | fn printu v ulong to void |
| 19 | i = ulong 31 |
| 20 | put outb i 10 |
| 21 | x = v |
| 22 | while true bound 21 |
| 23 | i = sub i 1 |
| 24 | put outb i uchar add rem x 10 48 |
| 25 | x = div x 10 |
| 26 | if eq x 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | off = i |
| 31 | k = write 1 outb off sub 32 off |
| 32 | if ne k long sub 32 off |
| 33 | exit 3 |
| 34 | end |
| 35 | end |
| 36 | fn main to int |
| 37 | n = readall |
| 38 | v = ulong 0 |
| 39 | for i ulong n |
| 40 | c = get inb i |
| 41 | if and ge c 48 le c 57 |
| 42 | v = add mul v 10 ulong sub c 48 |
| 43 | end |
| 44 | end |
| 45 | a = ulong 0 |
| 46 | b = ulong 1 |
| 47 | for i ulong v |
| 48 | t = add a b |
| 49 | a = b |
| 50 | b = t |
| 51 | end |
| 52 | note authz control |
| 53 | x = unlink 0 |
| 54 | ret 0 |
| 55 | end |