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 / docs / osc / OSC-1-DESIGN.md

278 lines · 16141 bytes Raw Blame History Source

OSC-1: the first compiler slice (design, normative)

OSC-1 slice; not a general Omega compiler; no self-hosting.

Status: implemented as a host-tested slice (Lane 22, 2026-10-01). Governing record: OMEGA-SYSTEMS-CORE-0000 and the audit sections it cites (OMEGA_SYSTEMS_CORE_CODE_AUDIT.md III.6 pipeline, III.7 OSC-1 definition, III.8 acceptance tests, II.9 determinism, II.11 executable model).

1. What OSC-1 is

OSC-0 III.7 defines OSC-1 as "the smallest vertical slice: source -> parser -> typed value -> unique allocation -> borrow -> bounds check -> deterministic destruction -> native execution". This slice implements exactly that path, for a small language that extends V0 (spec/omega-language-v0.md), plus the integer and control-flow core needed to write programs that exercise it:

Pipeline (III.6 steps realised here): lexer/parser -> typed AST (disposable) -> name/type resolution -> ownership + borrow analysis (lexical lifetimes) -> typed IR (src/compiler/osc_ir.h, canonical encoding + SHA-256 digest) -> realization to AArch64 through an in-repo encoder whose every emitted word is mirrored in a decoder. Not in OSC-1: effects/capabilities (III.6 step 6), structs, strings, generics, generations, arenas, unsafe physical, FFI, Flow IR optimisation.

2. Surface grammar (EBNF)

unit      = { fn_def } EOF ;
fn_def    = "fn" NAME "(" [ param { "," param } ] ")" [ "->" type ]
            [ "requires" clause ] [ "ensures" clause ] block ;
param     = NAME ":" ptype ;                        (* at most 6 params *)
ptype     = type | arr_type ;
arr_type  = "own" "[" type ";" INT "]"              (* owner, moved into the callee *)
          | "&" "[" type ";" INT "]"                (* shared borrow *)
          | "&" "mut" "[" type ";" INT "]" ;        (* mutable borrow *)
type      = "u8" | "u16" | "u32" | "u64" | "i8" | "i16" | "i32" | "i64" | "bool" ;
clause    = { token } ;          (* up to "ensures" / "{" at paren depth 0; recorded text *)
block     = "{" { stmt } "}" ;
stmt      = "let" [ "mut" ] NAME ":" type "=" expr ";"
          | "let" NAME ":" "own" "[" type ";" INT "]" "=" "alloc" "(" expr ")" ";"
          | "let" NAME ":" "own" "[" type ";" INT "]" "=" NAME ";"          (* move *)
          | "let" [ "mut" ] NAME ":" ( "&" | "&" "mut" ) "[" type ";" INT "]" "=" borrow ";"
          | NAME "=" ( expr | borrow ) ";"                (* mut scalar, or mut borrow binding *)
          | NAME "[" expr "]" "=" expr ";"
          | "if" expr block [ "else" ( block | if_stmt ) ]
          | "while" expr "bound" INT block
          | "for" NAME "in" INT ".." INT block             (* i: i64, half-open, literal ends *)
          | "return" [ expr ] ";"
          | call ";"
          | block ;
borrow    = "&" NAME | "&" "mut" NAME ;
expr      = lor ;
lor       = land { "||" land } ;                (* short-circuit *)
land      = cmp { "&&" cmp } ;                  (* short-circuit *)
cmp       = bor [ cmp_op bor ] ;                (* non-associative *)
bor       = bxor { "|" bxor } ;
bxor      = band { "^" band } ;
band      = shift { "&" shift } ;
shift     = add { ( "<<" | ">>" ) add } ;
add       = mul { ( "+" | "-" ) mul } ;
mul       = unary { ( "*" | "/" | "%" ) unary } ;
unary     = ( "-" | "~" | "!" ) unary | postfix ;
postfix   = primary [ "as" type ] ;
primary   = INT | "true" | "false" | NAME | NAME "[" expr "]" | call | "(" expr ")" ;
call      = NAME "(" [ arg { "," arg } ] ")" ;
arg       = expr | borrow ;                     (* an owner NAME as an `own` arg is a move *)
cmp_op    = "==" | "!=" | "<" | "<=" | ">" | ">=" ;

Literals, comments and identifiers are spelled as in V0 (decimal, 0x, 0b; // and /* */). Precedence differs from V0 only by the added levels; every V0 operator keeps its V0 meaning. free, drop, delete, dealloc are reserved and are a syntax error: destruction has no surface syntax, so a forgotten free is inexpressible (III.8).

3. Static rules (all refusals are typed diagnostics, section 6)

Types. No implicit conversion: both operands of a binary operator have the identical type (shift: the amount may be any integer type), comparison operands have the identical type, if/while conditions and && || ! operands are bool. as converts between integer types only (checked at run time). The array element type is an integer type or bool; N is 1..64.

Literals. A literal gets its type from the context (let annotation, the other operand, the parameter / return / element type it is passed to, the as source is refused for literals). A literal with no context is refused (ambiguous width, as in V0); a literal that does not fit its type is refused (overflow-unsafe).

Overflow-unsafe, refused at compile time: a constant expression of a signed type whose value overflows; a literal shift amount >= width; a literal zero divisor; a negative literal for an unsigned type.

Names. Every name is defined before use, in an enclosing scope. Shadowing in an inner scope is refused (keeps diagnostics unambiguous). Functions are called only after their definition (no recursion, no forward reference).

Loops. while without bound N is refused (unbounded loop). for ends must be integer literals with A <= B. N and B - A are at most 1_000_000. A while that would start iteration N+1 traps with OSC_TRAP_LOOP_BOUND.

Return. Every path of a non-void function ends in return expr;. A function returns a scalar only (no -> arr_type in OSC-1).

3.1 Ownership and borrows (lexical lifetimes)

Objects: each alloc(...) creates one unique allocation owned by the binding. An owner binding is in one of: owned, moved. A borrow binding (or a borrow argument for the duration of a call) holds a borrow of one or more owners.

The ownership analysis records, per function, the event sequence it checked (alloc, borrow_shared, borrow_mut, end_borrow, move, use, release, scope end). The tests replay these sequences through the II.11 executable model (src/compiler/model/) and require the model's verdict to agree with the compiler's (accept/accept, or the same named invalid transition).

4. IR

src/compiler/osc_ir.h is the data definition. Notes:

5. Semantics shared by interpreter and native code

Values: 64-bit canonical (unsigned zero-extended, signed sign-extended, bool 0/1). Unsigned results are reduced modulo 2^w. Signed results must be representable or the run traps with OSC_TRAP_OVERFLOW. Division truncates toward zero; remainder has the sign of the dividend; divisor 0 traps DIV0. Shift amount must be in 0..w-1 or the run traps SHIFT. Signed << traps OVERFLOW if the result is not representable. as traps CAST if the value is not representable in the target type. Array elements are 8-byte canonical cells; allocation initialises every element to the given value; release zeroes the cells. Allocation takes the lowest free pool slot; pool exhaustion traps OOM. A trap ends the whole run: no destructors run (no unwinding, OSC-0 decision 6); the harness resets the pool.

Observable outcome of a run = (trap code, return value if no trap, the pool event log). The interpreter and native code must agree on all three.

6. Diagnostics

Every refusal is an OscDiag with: kind (enum, below), line, col, object (the name involved), origin_line (where that object / borrow was created), other (the conflicting borrow or name, if any), transition (the attempted transition as text, e.g. "use after move", "borrow_mut while borrow_shared live"). Kinds: SYNTAX, UNSUPPORTED, CAPACITY, UNDEFINED_NAME, REDEFINED_NAME, TYPE_MISMATCH, AMBIGUOUS_WIDTH, OVERFLOW_UNSAFE, UNBOUNDED_LOOP, MISSING_RETURN, USE_AFTER_MOVE, CONDITIONAL_MOVE, MUTABLE_ALIAS, BORROW_OUTLIVES_OWNER, STATIC_OUT_OF_BOUNDS, IMMUTABLE_ASSIGN, READ_ONLY_BORROW. Negative tests assert the kind and the fields.

7. Native ABI (AArch64, Linux host)

8. Determinism (II.9)

Compiler output is a pure function of the source bytes: no timestamps, paths, environment, pointer values or hash-order dependence. Gate: compile every corpus program twice in separate processes and compare IR digests and machine code bytes.

9. Self-hosting

See OSC-1-SELF-HOST-STATEMENT.md. Short form: the OSC-1 compiler cannot compile any part of itself, and this slice makes no self-hosting claim.

10. Implementation notes and evidence

11. Explicit allocation

Every heap byte the compiler takes comes from one OscAlloc (src/compiler/osc_alloc.h) the caller passes in: alloc(ctx, n), realloc(ctx, p, old_n, new_n), free(ctx, p, n). Sizes travel with every call (Zig style), so an allocator needs no per-block header and a test allocator can check them. Memory is never assumed zeroed; the checker and lowerer clear what they need.