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 / spec / omega-language-v0.md

153 lines · 10473 bytes Raw Blame History Rendered
1# Omega surface language V0
2
3Status: V0, Omega Visor V1 lane 3. Code: `src/language/omega_lex.[ch]`, `omega_parse.[ch]`,
4`omega_lower.[ch]`. Tests: `tests/language/test_language_v0.c` + `tests/language/golden/v0.txt`
5(`make test-language`, run from the repo root).
6
7## Purpose
8
9A small typed line language for the Visor console. Source text is lexed, parsed into a
10**disposable** syntax tree, and lowered into the **existing** canonical Omega objects through
11the existing builders. The tree is never hashed, stored or used as identity. Lowering builds
12objects only; it never evaluates them. Evaluation, realization and verification stay with the
13existing graph/realizer/verifier code.
14
15## Grammar (EBNF, one statement per line)
16
17```
18line = [ stmt ] ; (* blank / comment-only line = no-op *)
19stmt = let_stmt | fn_def | expr_line ;
20let_stmt = "let" NAME ":" type "=" expr ;
21expr_line = expr [ ":" type ] ;
22fn_def = "fn" NAME "(" NAME ":" type ")" "->" type
23 [ "requires" clause ] [ "ensures" clause ] "{" expr "}" ;
24clause = { clause_token } ; (* up to "ensures" / "{" at paren depth 0 *)
25expr = or_expr [ cmp_op or_expr ] ; (* comparisons parse, then fail closed *)
26or_expr = and_expr { "|" and_expr } ;
27and_expr = add_expr { "&" add_expr } ;
28add_expr = mul_expr { ("+" | "-") mul_expr } ;
29mul_expr = primary { ("*" | "/") primary } ;
30primary = INT | "true" | "false" | NAME | "(" expr [ ":" type ] ")" ;
31type = "u8" | "u16" | "u32" | "u64" | "bool" ;
32cmp_op = "==" | "!=" | "<" | "<=" | ">" | ">=" ;
33INT = DEC | "0x" HEX { HEX } | "0b" BIN { BIN } ; (* DEC may have leading zeros; not octal *)
34NAME = ( letter | "_" ) { letter | digit | "_" } ; (* <= 63 chars; "_" = last result *)
35comments = "//" to end of line | "/*" ... "*/" ;
36```
37
38Precedence, loosest to tightest: comparisons, `|`, `&`, `+ -`, `* /`. All binary operators are
39left-associative. Nesting depth is limited to 32 parenthesis levels, a line to 256 tokens and
401024 bytes, the tree to 128 nodes.
41
42## Literal typing rule
43
44V0 never guesses a width. An integer literal gets its type from exactly one of:
45
461. an explicit ascription: `7: u64` at the end of an expression line, or `(7: u64)` anywhere;
472. the annotation of the enclosing `let` (`let x: u64 = 7`);
483. a typed sibling operand in the same arithmetic expression (`x + 1` where `x` is `u64`;
49 `(1: u64) + 2`), including through parentheses (`(1 + 2) + x`);
504. inside a `fn` body, the parameter type (always `u64` in V0).
51
52A literal with none of these (`7`, `1 + 2`) is rejected: "ambiguous width". A literal that does
53not fit its width (`256: u8`) is rejected, and a literal wider than 64 bits is rejected by the
54lexer. `true`/`false` are always `bool`. There are no suffixes (`7u64` is a syntax error) and no
55implicit conversions: every operand of an operator must have the identical type.
56
57## Overflow policy
58
59All V0 integer arithmetic lowers with `OVERFLOW_WRAP` (modulo 2^width), matching the policy the
60existing realizer uses for u64 binary ops (`src/omega_realize.c`). The policy is part of the
61OPERATION payload, so it is part of the SemanticId: an expression lowered with any other policy
62would have a different identity.
63
64## Lowering (how each construct maps to existing builders)
65
66| Source | Builders | Result |
67|---|---|---|
68| `7: uN` | `omega_build_type_uint(N)`, `omega_build_val_uint(type, N, 7)` | VALUE id |
69| `true` / `false` | `omega_build_type_bool`, `omega_build_val_bool` | VALUE id |
70| `a op b` (`+ - * / & \|`) | `omega_build_op_binary(OP_ADD/SUB/MUL/DIV/AND/OR, OVERFLOW_WRAP, T)`, `omega_build_apply(op, a, b)` | APPLY id |
71| `name` | none (id of the existing binding) | that id |
72| `let x: T = e` | lowering of `e`, then `visor_binding_set(x, OBJECT, id)` | binding |
73| `fn f(x: u64) -> u64 requires P ensures Q { chain }` | `omega_program_build_unary_op` (innermost step), `omega_program_compose` per further step, then name := `f`, pre/post text := P/Q, ids via `omega_build_constraint_id(CONST_PRECONDITION/POSTCONDITION, …)`, `omega_program_compute_id` | OmegaProgram, stored via `visor_program_add`, bound as PROGRAM |
74
75Objects are **deduplicated by SemanticId**: after each builder call, if an identical object
76already exists in the graph the new copy is dropped and the existing id is reused. On any error
77the graph's `object_count` is restored to its value before the line, so no object is left
78dangling. The type of an existing binding is read from the graph (VALUE → its type; APPLY → its
79operation's `output_type`).
80
81A `fn` body is accepted only in the shape the existing program model supports: a chain
82`((x op c1) op c2) ...` where each op is one of `+ - * & |` and each `c` is a constant. For
83`+ * & |` the constant may be written on either side (`2 * x + 1` is the same program as
84`x * 2 + 1`); `-` needs the constant on the right. Contract clauses are canonicalized before
85hashing: tokens re-joined with single spaces (none after `(` or before `)`), comments dropped,
86numbers in decimal, the parameter renamed to `x`. An omitted clause is the text `true`.
87
88## What fails closed, and why
89
90Return codes: `-1` syntax, `-2` unsupported / unrepresentable, `-3` capacity. Every error is a
91single line starting `column N:` and leaves the session unchanged (graph, bindings, programs).
92
93| Construct | Code | Why |
94|---|---|---|
95| bare / all-literal integer (`7`, `1 + 2`) | -2 | ambiguous width |
96| literal > width, literal > 64 bits | -2 | unrepresentable |
97| mixed widths / bool vs int (`(1: u32) + (1: u64)`) | -2 | V0 never converts |
98| arithmetic on bool | -2 | the existing evaluator is integer-only |
99| signed types `i8..i64` | -2 | no signed value builder; evaluator and program model are unsigned-only |
100| comparisons `== != < <= > >=` in expressions | -2 | the only builder (`omega_build_op_binary`) would type the result as the operand type, not `bool`; a mistyped result is worse than a missing feature |
101| division by the constant `0` | -2 | undefined |
102| unary minus, `!`, strings, chars, `[...]`, `{...}` in expressions | -2 | not in V0 |
103| function calls `f(x)`, using a program name as a value | -2 | V0 has no calls |
104| effect / authority / control-flow words (`effect cap capability mint revoke grant publish promote authority admin syscall io print import extern unsafe asm if else while for loop return match struct enum mut var const self rec`) | -2 | V0 cannot express effects or authority; these words are reserved so they never become names |
105| unknown name | -2 | nothing to lower |
106| `fn` not `(x: u64) -> u64`, more than one parameter | -2 | `omega_program_build_unary_op` is fixed at u64 → u64 |
107| `fn` body not a constant-step chain (`x * x`, `x * (2 + 1)`, just `x`, constants only, other names) | -2 | the program model only has unary-op steps + composition; folding constants would be evaluation |
108| `/` in a `fn` body | -2 | not in the program builder's op set |
109| `fn` body constant > 0xFFFFFFFF | -2 | the builder loads immediates with MOVZ + one MOVK (32 bits); a wider constant would be silently truncated in the code while the contract text carried the full value |
110| recursion (`f` in `f`'s body) | -2 | not supported |
111| `result` in `requires`, other names in clauses, clause > 63 chars | -2 | the contract text field is 64 bytes; no silent truncation |
112| a `fn` whose program id equals an existing program's but whose realization differs | -2 | internal builder-invariant violation (cannot happen from source since program identity v2; see identity laws) |
113| nesting > 32, > 256 tokens, > 128 nodes, graph full (256 objects), binding table full (64), program table full (16), > 32 fn steps | -3 | capacity |
114
115## Identity laws (locked by tests + golden vectors)
116
1171. Literal spelling never matters: `7: u64`, `07: u64`, `0x07: u64`, `0b111: u64`, `(7: u64)`
118 are one SemanticId, equal to `omega_build_val_uint(u64, 7)`.
1192. Whitespace and comments never matter: `x + y`, `x+y`, `x + /* c */ y` are one APPLY id,
120 equal to `omega_build_apply(omega_build_op_binary(OP_ADD, OVERFLOW_WRAP, u64), x, y)`.
1213. Binding names never enter an object id: `let a: u64 = 7` and `let b: u64 = 7` bind the same
122 VALUE id, and the second adds no object.
1234. Width is identity: `7: u32` and `7: u64` differ.
1245. Determinism: the same line lowered into two fresh graphs gives the same id.
1256. Programs (program identity v2, `spec/program-identity.md`): the program id binds the canonical
126 semantic body and the contract. The parameter name, the **fn name**, contract spacing/comments,
127 literal spelling, and the side of a commutative constant do not change it; a different body
128 (`x + 1` vs `x + 2`) or a different contract always does. Redefining a name with a different
129 body adds a new program and rebinds the name; an identical program (under any name) is reused
130 (dedupe). Cost and realization code are not part of the id.
131
132Golden vectors (`tests/language/golden/v0.txt`): `kind<TAB>source<TAB>encoding_hex<TAB>id_hex`.
133`E` rows are the canonical encoding (`omega_canonical_encode`) of the root object in a fresh
134graph; `P` rows are the program's realization code bytes and `program_id`. Regenerate only on a
135deliberate semantic change: `./build/tests-language/test_language_v0 --regen`.
136
137The payload bytes come from memcpy of host C structs (existing bootstrap representation), so the
138golden bytes are pinned to this ABI (aarch64/x86-64 LP64, 4-byte enums).
139
140## Non-claims
141
142- No evaluator: lowering never computes a value. `x * 2 + 1` is an object, not `7`.
143- `fn` lowering does not call `omega_program_verify`. `omega_program_build_unary_op`/`compose`
144 fill `realization` through `omega_program_realize` (spec/program-realization.md) and set
145 `is_realized = true`; that is the realization's claim, not this lane's. `is_verified` stays false.
146- u8/u16/u32 lower to correct canonical objects; whether they realize/execute correctly is the
147 realizer's claim, not this lane's (V0 realization handles u8..u64 program bodies; Language V0
148 `fn` is u64 only).
149- Contract clauses are canonical **text**; nothing checks that the body satisfies them.
150- Comparisons, signed integers, bool operators, calls, recursion, containers, strings, effects
151 and authority are not in V0. No capability is ever minted, published or promoted.
152- Identifiers are `[A-Za-z_][A-Za-z0-9_]*`; the Visor session also accepts `.` in names, the
153 language does not.