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 / omega_emit / SCHEMA.md

65 lines · 3813 bytes Raw Blame History Rendered
1# Op-list schema v1 (omega_emit input)
2
3You describe a program as one JSON object. `omega_emit` checks every op as it reads it and refuses
4the first invalid one with a reason; a fully valid list becomes canonical OSC binary IR.
5
6## Shape
7
8```
9{"functions": [ FUNCTION, ... ]} 1..32 functions
10FUNCTION = {"name": NAME, "params": [TYPE, ...], "ret": TYPE or "void",
11 "locals": [TYPE, ...], "blocks": [ BLOCK, ... ]}
12BLOCK = [ OP, ... ] 1 or more ops; the LAST op is br, cbr or ret, and only the last
13```
14
15- Strict JSON: no comments, no trailing commas, no extra keys, every listed key present.
16- NAME: `[A-Za-z_][A-Za-z0-9_]{0,62}`, unique in the unit.
17- Registers are numbered: the params are registers 0..P-1 (in order), then the locals are
18 registers P, P+1, ... (in order). At most 6 params and 480 registers in total.
19- TYPE: `bool`, `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64`, or an array reference
20 `own:<elem>:<len>`, `shared:<elem>:<len>`, `mut:<elem>:<len>` (elem a scalar type, len 1..64).
21 `ret` is a scalar type or `"void"`.
22- Blocks are numbered from 0; block 0 is where the function starts. A function may call only
23 functions listed before it (no recursion).
24- Every register is read only after it has been written on every path that reaches the read
25 (params count as written). Registers may be written more than once.
26
27## Ops
28
29Fields are register numbers unless stated. `dst` is written; the others are read.
30
31| op | fields | meaning |
32|---|---|---|
33| `const` | `dst`, `value` | dst = value (a whole decimal number that fits dst's type; `true`/`false` for bool) |
34| `mov` | `dst`, `a` | dst = a: the same scalar type; or, for an array dst, an array of the same element type and length: `own:` from `own:` (a move), `mut:` from `own:` or `mut:`, `shared:` from any |
35| `add` `sub` `mul` `div` `rem` | `dst`, `a`, `b` | dst = a op b; dst, a, b the same integer type |
36| `and` `or` `xor` | `dst`, `a`, `b` | bitwise (or logical, on bool); dst, a, b the same type |
37| `shl` `shr` | `dst`, `a`, `b` | dst = a shifted by b; dst and a the same integer type, b any integer type |
38| `neg` `bnot` | `dst`, `a` | dst = -a / bitwise not of a (same integer type) |
39| `not` | `dst`, `a` | dst = logical not of a (bool) |
40| `eq` `ne` `lt` `le` `gt` `ge` | `dst`, `a`, `b` | dst (bool) = a compared with b (a, b the same type) |
41| `cast` | `dst`, `a` | dst = a converted to dst's integer type |
42| `alloc` | `dst`, `init` | dst (an `own:` array) = new array, every element = init (element type) |
43| `release` | `arr` | give an `own:` array back |
44| `load` | `dst`, `arr`, `index` | dst = arr[index] (dst has the element type, index any integer type) |
45| `store` | `arr`, `index`, `value` | arr[index] = value (arr is `own:` or `mut:`) |
46| `call` | `func` (a function NAME), `args` (list of registers), `dst` (omit for a void callee) | dst = func(args) |
47| `trap` | `code` (1..14) | stop with that trap code (the block still ends with br, cbr or ret) |
48| `br` | `to` (block number) | continue at block `to` |
49| `cbr` | `cond` (bool register), `then`, `else` (block numbers) | continue at `then` if cond, else at `else` |
50| `ret` | `a` (omit in a void function) | return a (the function's ret type) |
51
52Example: `fn clamp_sub(a: u32, b: u32) -> u32`: a - b when a >= b, else 0.
53
54```
55{"functions": [
56 {"name": "clamp_sub", "params": ["u32", "u32"], "ret": "u32", "locals": ["bool", "u32", "u32"],
57 "blocks": [
58 [{"op": "ge", "dst": 2, "a": 0, "b": 1}, {"op": "cbr", "cond": 2, "then": 1, "else": 2}],
59 [{"op": "sub", "dst": 3, "a": 0, "b": 1}, {"op": "ret", "a": 3}],
60 [{"op": "const", "dst": 4, "value": 0}, {"op": "ret", "a": 4}]
61 ]}
62]}
63```
64
65A loop is a block that branches back to an earlier block (`br` or `cbr` to a lower block number).