Phase 6A: .aji frontend, layer 1 (scalars, expressions, functions, control flow)

src/frontend: lexer, AST, parser for the full 6A grammar (first error
only: one E7001 with span, expected and found), lowering to canonical
text AIR with a line map. Variables become SSA with block parameters
carried across if/while/for/loop joins; short-circuit and/or; checked,
wrapping and cast forms; calls; untyped let literals typed from later
uses, never guessed (E7007). The frontend repairs nothing.

check.checkFile: .aji → frontend → existing AIR parser and verifier;
every diagnostic at its source location, AIR location kept as
air_line/air_col; trap records gain source_location. CLI: check/run on
.aji, aji lower [--annotate].

Runner: .aji tests with the same headers; every accepted module must
lower deterministically, be canonical (lower → parse → print
unchanged) and match <file>.expected if present. Layer-1 tests: 6 run,
6 E7xxx rejects, 2 verifier-caught (E1002, E3101).
This commit is contained in:
dev committed 2026-10-05 11:23:18 +03:00
1 parent bfb4c445cd
commit ba3e9b3719
26 files changed
+2478 -13

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
// Function calls and recursion.
// expect: run
// result: 3628800
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.calls
fn fact(n: u64) -> u64
effects []
{
if n <= 1 { return 1; }
return n * fact(n - 1);
}
fn main() -> u64
effects []
{
return fact(10);
}
+16
View File
@@ -0,0 +1,16 @@
// Casts keep AIR's explicit modes: `as` widens, `as!` checks, `as%` wraps.
// expect: run
// result: 300
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.casts
fn main() -> u64
effects []
{
let small: u8 = 200;
let wide = small as u64;
let back = 44u64 as! u8;
let wrapped = 300u64 as% u8;
return wide + back as u64 + wrapped as u64 + 12;
}
@@ -0,0 +1,29 @@
// while, for, loop, break, continue, if as an expression and variables carried across joins.
// expect: run
// result: 1062
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.control
fn main() -> u64
effects []
{
var evens: u64 = 0;
for i in 0..10u64 {
if i % 2 == 1 { continue; }
evens = evens + i;
}
var n: u64 = 0;
var steps: u64 = 0;
while n < 1000 {
n = n + 37;
steps = steps + 1;
}
var k: u64 = 0;
loop {
k = k + 1;
if k == 5 { break; }
}
let big = if steps > 20 { 1 } else { 0 };
return evens + n + k + big;
}
@@ -0,0 +1,13 @@
// Checked arithmetic traps on overflow; the trap record carries the source location.
// expect: run
// trap: T0003
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.overflow
fn main() -> u8
effects []
{
let a: u8 = 250;
return a + 10;
}
@@ -0,0 +1,11 @@
// The frontend never guesses an integer type.
// expect: reject E7007
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.ambiguous
fn main() -> void
effects []
{
let unused = 5;
}
@@ -0,0 +1,13 @@
// Only `var` can be reassigned.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.assign
fn main() -> u64
effects []
{
let x: u64 = 1;
x = 2;
return x;
}
@@ -0,0 +1,11 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.noreturn
fn main() -> u64
effects []
{
let x: u64 = 1;
if x > 0 { return x; }
}
@@ -0,0 +1,12 @@
// One precise syntax error, no cascade.
// expect: reject E7001
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.syntax
fn main() -> u64
effects []
{
let a = 1
return a;
}
@@ -0,0 +1,11 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.mismatch
fn main() -> u64
effects []
{
let ok = true;
return ok;
}
@@ -0,0 +1,10 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.unknown
fn main() -> u64
effects []
{
return missing + 1;
}
@@ -0,0 +1,17 @@
// Effects stay explicit: the verifier reports E3101 at the call, with suggested_effects.
// expect: reject E3101
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.effects
fn alloc_something() -> void
effects [mem.alloc]
{
return;
}
fn main() -> void
effects []
{
alloc_something();
}
@@ -0,0 +1,12 @@
// The frontend does not duplicate the verifier: a lossy `as` lowers to cast.widen and the verifier rejects it (E1002).
// expect: reject E1002
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.widen
fn main() -> u8
effects []
{
let big: u64 = 1;
return big as u8;
}
@@ -0,0 +1,15 @@
// `and` evaluates its right operand only when the left one is true, so this does not divide by zero.
// expect: run
// result: 7
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.short
fn main() -> u8
effects []
{
let d: u8 = 0;
if d != 0 and 10 / d > 1 { return 1; }
if d == 0 or 10 / d > 1 { return 7; }
return 2;
}
+14
View File
@@ -0,0 +1,14 @@
// The first end-to-end slice: untyped literals take their type from the return.
// expect: run
// result: 30
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.sum
fn main() -> u64
effects []
{
let a = 10;
let b = 20;
return a + b;
}
@@ -0,0 +1,12 @@
module demo.sum
air 0
lang 0.1
features [effects]
fn @main() -> u64
effects []
entry:
%c_1 = const.u64 10
%c_2 = const.u64 20
%t_3 = add.checked.u64 %c_1, %c_2
ret %t_3