interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / string-append / string-append.om

33 lines · 850 bytes Raw Blame History
1note Rosetta Code task "String append": https://rosettacode.org/wiki/String_append
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text s0 "Hello,"
6text more " World!"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note copyto copies s into d at offset off and returns the offset after it (past the end traps 3)
19fn copyto d edit uchar * off ulong s view uchar * to ulong
20for i ulong len s
21put d add off i get s i
22end
23ret add off len s
24end
25fn main to int
26note the string lives in a 64-byte buffer b with length n; appending copies after byte n
27b = new uchar 64 0
28n = copyto b 0 s0
29n = copyto b n more
30emit part b 0 n
31emit nl
32ret 0
33end