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 / omegese.md
| 1 | REPRESENTATION: omegese |
| 2 | |
| 3 | Write the program in Omegese: one statement per line, words separated by single spaces. No commas, |
| 4 | no semicolons, no indentation, no comments. A checker reads it line by line and refuses |
| 5 | the first invalid line with a reason; a valid program becomes the program. |
| 6 | |
| 7 | Types (Omegese name = type): bool = bool, uchar = u8, ushort = u16, uint = u32, ulong = u64, |
| 8 | byte = i8, short = i16, int = i32, long = i64. The names u8 .. i64 are accepted too. |
| 9 | |
| 10 | Statements: |
| 11 | |
| 12 | fn <name> <param> <type> <param> <type> ... to <type> (or: to void); end closes the function |
| 13 | <name> = <value> write a value: a new name, or an existing name of the same type |
| 14 | if <cond> ... else ... end (else is optional) |
| 15 | while <cond> bound <N> ... end N in 1..1000000; more than N iterations is trap 4 |
| 16 | for <i> <type> <count> ... end i = 0, 1, ..., count-1 (count is a number or a value) |
| 17 | break leave the innermost while or for |
| 18 | ret <value> (ret alone in a void function) |
| 19 | put <array> <index> <value> |
| 20 | free <array> |
| 21 | trap <code> code 1..14; like ret, it ends the path |
| 22 | <function> <args> call a void function |
| 23 | |
| 24 | Values (each op takes a fixed number of values; each value may itself be an op): |
| 25 | |
| 26 | <name> or <number> |
| 27 | add sub mul div rem and or xor shl shr <a> <b> |
| 28 | eq ne lt le gt ge <a> <b> (gives bool) |
| 29 | neg <a> (signed) not <a> (bool: logical; number: bitwise) |
| 30 | <type> <number> a typed number, e.g. uint 0 |
| 31 | <type> <value> convert, e.g. ulong x (trap 5 if the value does not fit) |
| 32 | get <array> <index> |
| 33 | new <type> <len> <init> only as a whole line: <name> = new ... |
| 34 | own <array> edit <array> view <array> |
| 35 | <function> <args> call a function written earlier in the program |
| 36 | |
| 37 | Values nest in prefix order: `add mul a a 1` is (a*a)+1, `eq rem n 2 0` is n%2 == 0. Brackets are |
| 38 | optional and change nothing: `add (mul a a) 1`. A ( must hold exactly one value. |
| 39 | |
| 40 | Rules: |
| 41 | - Types are inferred: a new name takes the type of its value. A plain number takes the type of the |
| 42 | other value of its op (`add x 1`); where there is none, write the type (`s = uint 0`). Both values |
| 43 | of an op have one type; convert explicitly. Two plain numbers in one op are refused. |
| 44 | - A condition is any value giving bool (`while ne b 0 bound 64`, `if or lt p 0 gt p 9`). |
| 45 | - A name first written inside if/else/while/for exists only until that block's end. To use a value |
| 46 | after the block, write it before the block, then overwrite it inside. |
| 47 | - Every name you write must be read later. Parameters may be overwritten. A for counter may not. |
| 48 | - Every path through a function that returns a value must end in ret or trap. |
| 49 | - Parameters of array type: own|edit|view <type> <len>, e.g. `v view uint 4`. |
| 50 | |
| 51 | Word card: every fixed word and what it does. |
| 52 | |
| 53 | fn start a function: fn <name> <param> <type> ... to <type> |
| 54 | to in a fn line: the return type follows |
| 55 | void in a fn line: the function returns nothing (to void) |
| 56 | end close the innermost fn, if, else, while or for |
| 57 | if if <cond>: run the lines up to else or end when cond is true |
| 58 | else the lines run when the if condition is false |
| 59 | while while <cond> bound <N>: repeat while cond is true |
| 60 | bound in a while line: the most passes allowed; one more is trap 4 |
| 61 | for for <i> <type> <count>: run with i = 0, 1, ..., count-1 |
| 62 | break leave the innermost while or for |
| 63 | ret return a value (ret alone in a void function) |
| 64 | trap trap <code>: stop the run with that trap code |
| 65 | put put <array> <index> <value>: store into an array |
| 66 | free free <array>: release an array made with new |
| 67 | true the bool value true |
| 68 | false the bool value false |
| 69 | add add <a> <b>: a + b |
| 70 | sub sub <a> <b>: a - b |
| 71 | mul mul <a> <b>: a * b |
| 72 | div div <a> <b>: a / b, truncated toward zero |
| 73 | rem rem <a> <b>: remainder of a / b, sign of a |
| 74 | and and <a> <b>: bitwise and; on bools, logical and |
| 75 | or or <a> <b>: bitwise or; on bools, logical or |
| 76 | xor xor <a> <b>: bitwise exclusive or |
| 77 | shl shl <a> <b>: a shifted left by b bits |
| 78 | shr shr <a> <b>: a shifted right by b bits |
| 79 | eq eq <a> <b>: a == b (bool) |
| 80 | ne ne <a> <b>: a != b (bool) |
| 81 | lt lt <a> <b>: a < b (bool) |
| 82 | le le <a> <b>: a <= b (bool) |
| 83 | gt gt <a> <b>: a > b (bool) |
| 84 | ge ge <a> <b>: a >= b (bool) |
| 85 | neg neg <a>: -a (signed) |
| 86 | not not <a>: logical not of a bool, bitwise not of a number |
| 87 | get get <array> <index>: read an element |
| 88 | new <name> = new <type> <len> <init>: a new array of len elements, all init |
| 89 | bool type bool; bool <v> converts or types a value |
| 90 | uchar type u8 (unsigned 8-bit); uchar <v> converts or types a value |
| 91 | ushort type u16 (unsigned 16-bit) |
| 92 | uint type u32 (unsigned 32-bit) |
| 93 | ulong type u64 (unsigned 64-bit) |
| 94 | byte type i8 (signed 8-bit) |
| 95 | short type i16 (signed 16-bit) |
| 96 | int type i32 (signed 32-bit) |
| 97 | long type i64 (signed 64-bit) |
| 98 | own own <array>: move the array (a parameter: own <type> <len>) |
| 99 | edit edit <array>: lend the array for writing (a parameter: edit <type> <len>) |
| 100 | view view <array>: lend the array for reading (a parameter: view <type> <len>) |