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