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 / si / rosetta / tasks / array-concatenation / array-concatenation.om
| 1 | note Rosetta Code task "Array concatenation": https://rosettacode.org/wiki/Array_concatenation |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | om2 |
| 4 | text nl "\n" |
| 5 | text sp " " |
| 6 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 7 | fn emit a view uchar * to void |
| 8 | o = ulong 0 |
| 9 | while lt o len a bound 4096 |
| 10 | k = write 1 a o sub len a o |
| 11 | if le k 0 |
| 12 | exit 1 |
| 13 | end |
| 14 | o = add o ulong k |
| 15 | end |
| 16 | end |
| 17 | note emitu writes n in decimal; 20 digits hold every ulong |
| 18 | fn emitu n ulong to void |
| 19 | d = new uchar 20 0 |
| 20 | i = ulong 20 |
| 21 | v = n |
| 22 | while true bound 20 |
| 23 | i = sub i 1 |
| 24 | put d i uchar add rem v 10 48 |
| 25 | v = div v 10 |
| 26 | if eq v 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | emit part d i sub 20 i |
| 31 | end |
| 32 | note cat copies x then y into r and returns the length |
| 33 | fn cat x view ulong * y view ulong * r edit ulong * to ulong |
| 34 | for i ulong len x |
| 35 | put r i get x i |
| 36 | end |
| 37 | for i ulong len y |
| 38 | put r add len x i get y i |
| 39 | end |
| 40 | ret add len x len y |
| 41 | end |
| 42 | fn main to int |
| 43 | a = new ulong 3 0 |
| 44 | b = new ulong 4 0 |
| 45 | c = new ulong 7 0 |
| 46 | for i ulong 3 |
| 47 | put a i add i 1 |
| 48 | end |
| 49 | for i ulong 4 |
| 50 | put b i add i 4 |
| 51 | end |
| 52 | n = cat a b c |
| 53 | for i ulong n |
| 54 | if gt i 0 |
| 55 | emit sp |
| 56 | end |
| 57 | emitu get c i |
| 58 | end |
| 59 | emit nl |
| 60 | ret 0 |
| 61 | end |