omega-harness
Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories
Brought by drakestapleton
omega-harness / examples / om2_views.om
| 1 | note om2_views: view T * is an unsized read-only parameter; part A off n passes a checked slice |
| 2 | om2 |
| 3 | note ---- OM-2 output helpers: an unsized view parameter takes an array or text of any length |
| 4 | note outv: write all of a to stdout; a short write continues, 0 or an error exits 90 |
| 5 | fn outv a view uchar * to void |
| 6 | e = len a |
| 7 | p = ulong 0 |
| 8 | while lt p e bound 65536 |
| 9 | k = write 1 a p sub e p |
| 10 | if le k 0 |
| 11 | exit 90 |
| 12 | end |
| 13 | p = add p ulong k |
| 14 | end |
| 15 | end |
| 16 | note putu: v in decimal, then a newline |
| 17 | note a part of a global is error 19, so the digits go in a local array |
| 18 | fn putu v ulong to void |
| 19 | b = new uchar 21 0 |
| 20 | i = ulong 20 |
| 21 | put b 20 10 |
| 22 | n = v |
| 23 | while true bound 20 |
| 24 | i = sub i 1 |
| 25 | put b i uchar add rem n 10 48 |
| 26 | n = div n 10 |
| 27 | if eq n 0 |
| 28 | break |
| 29 | end |
| 30 | end |
| 31 | outv part b i sub 21 i |
| 32 | end |
| 33 | text greet "views and slices\n" |
| 34 | fn sum a view uint * to ulong |
| 35 | s = ulong 0 |
| 36 | for i ulong len a |
| 37 | s = add s ulong get a i |
| 38 | end |
| 39 | ret s |
| 40 | end |
| 41 | fn main to int |
| 42 | outv greet |
| 43 | a = new uint 6 0 |
| 44 | for i ulong 6 |
| 45 | put a i uint add i 1 |
| 46 | end |
| 47 | putu sum a |
| 48 | putu sum part a 1 3 |
| 49 | putu sum part a 5 1 |
| 50 | outv part greet 0 6 |
| 51 | outv part greet 16 1 |
| 52 | ret 0 |
| 53 | end |