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

+20
View File
@@ -5,6 +5,7 @@ const std = @import("std");
const air = @import("air.zig");
const diag = @import("diag.zig");
const verifier = @import("verifier.zig");
const frontend = @import("frontend.zig");
pub const Status = enum {
/// Module verified; no error diagnostics.
@@ -22,8 +23,27 @@ pub const Report = struct {
module: ?air.Module = null,
/// Pipeline stage that is missing when `status == .unimplemented`.
missing_stage: []const u8 = "",
/// For `.aji` input: the lowered AIR and its line map (spec 15 §10).
lowered: ?frontend.lower_mod.Output = null,
};
/// Checks a `.aji` module (frontend, then the AIR pipeline, with every
/// diagnostic at its source location) or a text AIR module.
pub fn checkFile(arena: std.mem.Allocator, file_name: []const u8, source: []const u8) !Report {
if (!std.mem.endsWith(u8, file_name, ".aji")) return checkAir(arena, file_name, source);
const lowered = switch (try frontend.compile(arena, file_name, source)) {
.ok => |o| o,
.err => |d| return .{ .status = .rejected, .diagnostics = try arena.dupe(diag.Diagnostic, &.{d}) },
.unimplemented => |what| return .{ .status = .unimplemented, .diagnostics = &.{}, .missing_stage = what },
};
var r = try checkAir(arena, file_name, lowered.air);
const mapped = try arena.alloc(diag.Diagnostic, r.diagnostics.len);
for (r.diagnostics, mapped) |d, *m| m.* = try frontend.mapDiagnostic(arena, d, file_name, lowered.lines);
r.diagnostics = mapped;
r.lowered = lowered;
return r;
}
/// Checks a text AIR module. All allocations go into `arena`.
pub fn checkAir(arena: std.mem.Allocator, file_name: []const u8, source: []const u8) !Report {
const parsed = try air.parse.parse(arena, file_name, source);