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-prepend / string-prepend.om

42 lines · 1013 bytes Raw Blame History
1note Rosetta Code task "String prepend": https://rosettacode.org/wiki/String_prepend
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text s0 "World"
6text pre "Hello, "
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
25note prepend moves the n bytes of b right by len p (last byte first), then copies p in front
26fn prepend b edit uchar * n ulong p view uchar * to ulong
27k = len p
28for i ulong n
29j = sub sub n 1 i
30put b add j k get b j
31end
32r = copyto b 0 p
33ret add n k
34end
35fn main to int
36b = new uchar 64 0
37n = copyto b 0 s0
38n = prepend b n pre
39emit part b 0 n
40emit nl
41ret 0
42end