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 / fibonacci-sequence / fibonacci-sequence.om

49 lines · 994 bytes Raw Blame History
1note Rosetta Code task "Fibonacci sequence": https://rosettacode.org/wiki/Fibonacci_sequence
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note emit writes every byte of a to stdout; a short write is retried, an error exits 1
6fn emit a view uchar * to void
7o = ulong 0
8while lt o len a bound 4096
9k = write 1 a o sub len a o
10if le k 0
11exit 1
12end
13o = add o ulong k
14end
15end
16note emitu writes n in decimal; 20 digits hold every ulong
17fn emitu n ulong to void
18d = new uchar 20 0
19i = ulong 20
20v = n
21while true bound 20
22i = sub i 1
23put d i uchar add rem v 10 48
24v = div v 10
25if eq v 0
26break
27end
28end
29emit part d i sub 20 i
30end
31note fib n is F(n) with F(0) = 0 and F(1) = 1; F(93) is the largest that fits a ulong
32note (the loop computes one term past the one returned; unsigned add wraps, it never traps)
33fn fib n ulong to ulong
34a = ulong 0
35b = ulong 1
36for i ulong n
37t = add a b
38a = b
39b = t
40end
41ret a
42end
43fn main to int
44for n ulong 94
45emitu fib n
46emit nl
47end
48ret 0
49end