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 / omc / tests / pools / g3.om
| 1 | note gate-pools 3: enlarge runs inside the value of put, the index of get, and the counts of read and |
| 2 | note write; every call grows the pool it serves by 4096 elements and a blocker pool beside it, so mremap |
| 3 | note moves the regions and later mappings reuse the old addresses (the gate counts both with strace). |
| 4 | note stdin: the 40 bytes abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN. |
| 5 | global P ulong * |
| 6 | global Q ulong * |
| 7 | global U uchar * |
| 8 | global V uchar * |
| 9 | global ob uchar 24 |
| 10 | fn pnum v ulong to void |
| 11 | put ob 23 10 |
| 12 | i = ulong 23 |
| 13 | x = v |
| 14 | go = true |
| 15 | while go bound 21 |
| 16 | i = sub i 1 |
| 17 | put ob i uchar add rem x 10 48 |
| 18 | x = div x 10 |
| 19 | go = ne x 0 |
| 20 | end |
| 21 | k = write 1 ob i sub 24 i |
| 22 | end |
| 23 | fn plong v long to void |
| 24 | if lt v 0 |
| 25 | put ob 0 uchar 45 |
| 26 | k = write 1 ob 0 1 |
| 27 | pnum ulong neg v |
| 28 | else |
| 29 | pnum ulong v |
| 30 | end |
| 31 | end |
| 32 | fn gv v ulong to ulong |
| 33 | r = enlarge P add len P 4096 |
| 34 | r = enlarge Q add len Q 4096 |
| 35 | ret v |
| 36 | end |
| 37 | fn gi j ulong to ulong |
| 38 | r = enlarge P add len P 4096 |
| 39 | r = enlarge Q add len Q 4096 |
| 40 | ret j |
| 41 | end |
| 42 | fn gu n ulong to ulong |
| 43 | r = enlarge U add len U 4096 |
| 44 | r = enlarge V add len V 4096 |
| 45 | ret n |
| 46 | end |
| 47 | fn main to int |
| 48 | r = enlarge Q ulong 1 |
| 49 | r = enlarge P ulong 1 |
| 50 | r = enlarge V ulong 1 |
| 51 | r = enlarge U ulong 64 |
| 52 | j = ulong 0 |
| 53 | while lt j 40 |
| 54 | put P j gv add mul j 3 1 |
| 55 | x = get P gi j |
| 56 | pnum x |
| 57 | k = read 0 U j gu 1 |
| 58 | k = write 1 U j gu 1 |
| 59 | pnum ulong k |
| 60 | j = add j 1 |
| 61 | end |
| 62 | k = write 1 U 0 40 |
| 63 | s = ulong 0 |
| 64 | j = ulong 0 |
| 65 | while lt j 40 |
| 66 | s = add s get P j |
| 67 | j = add j 1 |
| 68 | end |
| 69 | pnum s |
| 70 | pnum len P |
| 71 | pnum len U |
| 72 | ret 0 |
| 73 | end |