# Aether 0.0.1 coding rules

Aether is a small statically typed language. Write only the syntax below; it is
not Rust or Go. Check every file with `aetherc verify FILE [flags]` and run it
with `aetherc eval FILE --result-protocol` (or `eval-ssa` when buffers are used)
before reporting success.

## Program shape
- Entry point: exactly `fn main() -> i32 { ... }`.
- Functions: `fn name(a: i32, b: i64) -> bool { ... }`; generics `fn f<T>(x: T) -> T`, called as `f::<i32>(x)`.
- Every path returns. A `while` loop is never assumed to end: put a `return` after it.
- `;` is optional. Comments: `//`.

## Types
- Scalars: `i32`, `i64`, `bool`. No unsigned, float, char or string types.
- Integer literals are `i32` (0..2147483647). Use `i64(x)` / `i32(x)`; no implicit conversion.
- Fixed arrays: `array_i32_3(1, 2, 3)`, `[0; 8]`, type `[i32; 3]`; read `at(a, i)`, length `length(a)`, update copy `with_at(a, i, v)`.
- Tuples (2–3 scalars): `tuple(a, b)`, read `first(t)`, `second(t)`, `third(t)`.
- `struct P { x: i32, y: i32 }`, build `P(1, 2)`, read `p.x`. Declare before use.
- `enum E { A: i32, B: (i32, i32) }`, build `E.A(1)`, dispatch `match_enum(e, on_a, on_b)`.
- Strings only inside `length("...")` or `at("...", i)` (UTF-8 bytes).

## Statements
- `x := expr`, `let x: T = expr`, `mut x := expr`, `let mut x: T = expr`, `x = expr` (mutable only).
- `if cond { } else { }` (no `else if`: nest), `while cond { }`, `return expr`.
- No `for`, `break`, `continue`, `match`, `+=`, closures, methods, traits, macros.
- A call whose result is unused must still be bound: `ignored := f()`.
- `comptime(expr)` folds a closed constant expression.

## Operators
`|| && == != < <= > >= + - * / %`, unary `- !`. Integer arithmetic wraps. Division
by a runtime zero traps (`trap:division-by-zero`, exit 125); a literal zero
divisor is a compile error.

## Reserved names (never use as variables)
`first second third at length slice with_at tuple match_enum own move borrow
borrow_mut borrow_field borrow_mut_field load store comptime extern struct enum
fn pub module return let mut if else while true false` and type names.

## Ownership
- `c := own(v)`, `m := move(c)`, `r := borrow(c)`, `w := borrow_mut(c)`, `load(r)`, `store(w, v)`.
- These must initialize an immutable local. Owners/references cannot be copied, reassigned, returned or stored.
- Exclusive borrow conflicts with any other borrow; no move while borrowed; no use after move.
- Borrows last to the end of the block unless `--nll` is passed.

## Opt-in features (state the flags in a header comment)
- `--nll`: reference parameters `ref_i32`, `mutref_i32`, … and early borrow expiry.
- `--dynamic-buffers`: `buffer_new(n)`, `buffer_len(b)`, `buffer_get(b, i)`, `buffer_set(b, i, v)` (i32 only).
- `--owned-signatures` (with `--dynamic-buffers`): `own_buffer_i32` parameters/returns; pass `move(b)`, return `return move(b)`.
- `--host-io`: `input_len()`, `input_byte(i)`, `output_byte(b)`.
- `--module-root DIR`: `module a.b;` then `import c.d;` → file `DIR/c/d.ae`.
- `extern "C" { fn f(x: i32) -> i32; }` and `extern "C" fn g(x: i32) -> i32 { }`: native backend only, `bool`/`i32`/`i64` only.

## Build
`aetherc build FILE --backend c-aggregate --release -o out` (full language);
`--backend native --target linux-x64|macos-arm64|win-x64|...` (scalar + FFI).

## Porting from Rust
- Check scope first: `String`, `Vec<T>` (T other than i32), `HashMap`, traits, closures, iterators, floats, unsigned/`usize` business values, threads, `async` are not available in 0.0.1. Say so; do not emulate with wrong semantics.
- Arithmetic always wraps (Rust's `wrapping_*`); Rust debug-mode overflow panics have no equivalent; add explicit checks if the Rust code relies on them. `i32::MIN / -1` wraps instead of panicking.
- `for i in 0..n` → `while`; `a[i] = v` → `a = with_at(a, i, v)`; `match` on enums → `match_enum`; `Option`/`Result` → declare an `enum`; methods → free functions; `&mut` parameters → `--nll` with `mutref_*`; returned references → return values.
- Compare `aetherc eval --result-protocol` output with the Rust program on the same input before reporting success.
