interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / si / rosetta / tasks / string-length / string-length.om

56 lines · 1062 bytes Raw Blame History
1note Rosetta Code task "String length": https://rosettacode.org/wiki/String_length
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tb " bytes "
6text tc " characters\n"
7text s1 "møøse"
8text s2 "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
9text s3 "J̲o̲s̲é̲"
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note emitu writes n in decimal; 20 digits hold every ulong
22fn emitu n ulong to void
23d = new uchar 20 0
24i = ulong 20
25v = n
26while true bound 20
27i = sub i 1
28put d i uchar add rem v 10 48
29v = div v 10
30if eq v 0
31break
32end
33end
34emit part d i sub 20 i
35end
36note a UTF-8 code point starts at every byte that is not a continuation byte 10xxxxxx
37fn show a view uchar * to void
38n = ulong 0
39for i ulong len a
40if ne and get a i 192 128
41n = add n 1
42end
43end
44emit a
45emit nl
46emitu len a
47emit tb
48emitu n
49emit tc
50end
51fn main to int
52show s1
53show s2
54show s3
55ret 0
56end