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 / research / om-bench / REFERENCE-CARD.md

163 lines · 5470 bytes Raw Blame History Source

Omega (.om) reference card for om-bench v1

Checked against omega-mv 0b77e6ea, compiler seed/out/omc sha256 2c824805...029f. Both examples at the end compile and run with that compiler.

Shape

Values are prefix words with fixed arity (no infix, no brackets needed)

Types

Names and limits

Input and output

Compiler errors: omc: line N: error K

3 unknown name, 4 line ends early, 5 extra words, 6 bad number, 7 type mismatch, 8 number out of range, 9 word not allowed here, 10 duplicate name, 11 bare number needs a type, 12 too many live names, 13 name longer than 8, 15 missing end, 16 unknown word or syntax, 17 line after ret/break/exit, 18 missing ret, 19 global passed as argument, 20 write to text, 21 constant index out of range.

Example 1: sum of non-negative whole numbers on stdin (verified; a '-' sign is skipped, not handled)

global inb uchar 65536
global outb uchar 32
fn readall to ulong
n = ulong 0
while lt n 65536 bound 65537
k = read 0 inb n sub 65536 n
if lt k 0
exit 2
end
if eq k 0
break
end
n = add n ulong k
end
ret n
end
fn printu v ulong to void
i = ulong 31
put outb i 10
x = v
while true bound 21
i = sub i 1
put outb i uchar add rem x 10 48
x = div x 10
if eq x 0
break
end
end
off = i
k = write 1 outb off sub 32 off
if ne k long sub 32 off
exit 3
end
end
fn main to int
n = readall
sum = ulong 0
cur = ulong 0
have = false
for i ulong n
c = get inb i
if and ge c 48 le c 57
cur = add mul cur 10 ulong sub c 48
have = true
else
if have
sum = add sum cur
end
cur = 0
have = false
end
end
if have
sum = add sum cur
end
printu sum
ret 0
end

Example 2: uppercase stdin, then print a fixed word (verified)

global inb uchar 65536
text yes "changed\n"
text no "same\n"
fn readall to ulong
n = ulong 0
while lt n 65536 bound 65537
k = read 0 inb n sub 65536 n
if lt k 0
exit 2
end
if eq k 0
break
end
n = add n ulong k
end
ret n
end
fn main to int
n = readall
hit = false
for i ulong n
c = get inb i
if and ge c 97 le c 122
put inb i sub c 32
hit = true
end
end
k = write 1 inb 0 n
if ne k long n
exit 3
end
if hit
k = write 1 yes 0 len yes
else
k = write 1 no 0 len no
end
ret 0
end