interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

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

45 lines · 999 bytes Raw Blame History
1note Rosetta Code task "Empty string": https://rosettacode.org/wiki/Empty_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tempty "s is empty\n"
6text tfull "s is not empty: "
7text word "abc"
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note copyto copies s into d at offset off and returns the offset after it (past the end traps 3)
20fn copyto d edit uchar * off ulong s view uchar * to ulong
21for i ulong len s
22put d add off i get s i
23end
24ret add off len s
25end
26note a string here is a buffer b and its length n; the empty string is length 0
27fn check b view uchar * to void
28if eq len b 0
29emit tempty
30else
31emit tfull
32emit b
33emit nl
34end
35end
36fn main to int
37b = new uchar 16 0
38n = ulong 0
39check part b 0 n
40n = copyto b 0 word
41check part b 0 n
42n = 0
43check part b 0 n
44ret 0
45end