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 / tools / exp445 / arms / text.md

86 lines · 4255 bytes Raw Blame History Rendered
1REPRESENTATION: text
2
3Write the program as OSC text, the language below (from docs/osc/OSC-1-DESIGN.md).
4
5Grammar (EBNF):
6
7
8```
9unit = { fn_def } EOF ;
10fn_def = "fn" NAME "(" [ param { "," param } ] ")" [ "->" type ]
11 [ "requires" clause ] [ "ensures" clause ] block ;
12param = NAME ":" ptype ; (* at most 6 params *)
13ptype = type | arr_type ;
14arr_type = "own" "[" type ";" INT "]" (* owner, moved into the callee *)
15 | "&" "[" type ";" INT "]" (* shared borrow *)
16 | "&" "mut" "[" type ";" INT "]" ; (* mutable borrow *)
17type = "u8" | "u16" | "u32" | "u64" | "i8" | "i16" | "i32" | "i64" | "bool" ;
18clause = { token } ; (* up to "ensures" / "{" at paren depth 0; recorded text *)
19block = "{" { stmt } "}" ;
20stmt = "let" [ "mut" ] NAME ":" type "=" expr ";"
21 | "let" NAME ":" "own" "[" type ";" INT "]" "=" "alloc" "(" expr ")" ";"
22 | "let" NAME ":" "own" "[" type ";" INT "]" "=" NAME ";" (* move *)
23 | "let" [ "mut" ] NAME ":" ( "&" | "&" "mut" ) "[" type ";" INT "]" "=" borrow ";"
24 | NAME "=" ( expr | borrow ) ";" (* mut scalar, or mut borrow binding *)
25 | NAME "[" expr "]" "=" expr ";"
26 | "if" expr block [ "else" ( block | if_stmt ) ]
27 | "while" expr "bound" INT block
28 | "for" NAME "in" INT ".." INT block (* i: i64, half-open, literal ends *)
29 | "return" [ expr ] ";"
30 | call ";"
31 | block ;
32borrow = "&" NAME | "&" "mut" NAME ;
33expr = lor ;
34lor = land { "||" land } ; (* short-circuit *)
35land = cmp { "&&" cmp } ; (* short-circuit *)
36cmp = bor [ cmp_op bor ] ; (* non-associative *)
37bor = bxor { "|" bxor } ;
38bxor = band { "^" band } ;
39band = shift { "&" shift } ;
40shift = add { ( "<<" | ">>" ) add } ;
41add = mul { ( "+" | "-" ) mul } ;
42mul = unary { ( "*" | "/" | "%" ) unary } ;
43unary = ( "-" | "~" | "!" ) unary | postfix ;
44postfix = primary [ "as" type ] ;
45primary = INT | "true" | "false" | NAME | NAME "[" expr "]" | call | "(" expr ")" ;
46call = NAME "(" [ arg { "," arg } ] ")" ;
47arg = expr | borrow ; (* an owner NAME as an `own` arg is a move *)
48cmp_op = "==" | "!=" | "<" | "<=" | ">" | ">=" ;
49```
50
51Literals, comments and identifiers are spelled as in V0 (decimal, `0x`, `0b`;
52`//` and `/* */`). Precedence differs from V0 only by the added levels; every V0
53operator keeps its V0 meaning. `free`, `drop`, `delete`, `dealloc` are reserved
54and are a syntax error: destruction has no surface syntax, so a forgotten free
55is inexpressible (III.8).
56
57
58Static rules:
59
60
61Types. No implicit conversion: both operands of a binary operator have the
62identical type (shift: the amount may be any integer type), comparison operands
63have the identical type, `if`/`while` conditions and `&& || !` operands are
64`bool`. `as` converts between integer types only (checked at run time). The
65array element type is an integer type or bool; N is 1..64.
66
67Literals. A literal gets its type from the context (let annotation, the other
68operand, the parameter / return / element type it is passed to, the `as`
69source is refused for literals). A literal with no context is refused
70(ambiguous width, as in V0); a literal that does not fit its type is refused
71(`overflow-unsafe`).
72
73Overflow-unsafe, refused at compile time: a constant expression of a signed
74type whose value overflows; a literal shift amount >= width; a literal zero
75divisor; a negative literal for an unsigned type.
76
77Names. Every name is defined before use, in an enclosing scope. Shadowing in
78an inner scope is refused (keeps diagnostics unambiguous). Functions are called
79only after their definition (no recursion, no forward reference).
80
81Loops. `while` without `bound N` is refused (`unbounded loop`). `for` ends must
82be integer literals with A <= B. N and B - A are at most 1_000_000. A `while`
83that would start iteration N+1 traps with OSC_TRAP_LOOP_BOUND.
84
85Return. Every path of a non-void function ends in `return expr;`. A function
86returns a scalar only (no `->` arr_type in OSC-1).