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:
1 parent
bfb4c445cd
commit
ba3e9b3719
26 files changed
+2478
-13
No files matched your search
+41
-4
@@ -94,7 +94,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
var walker = try dir.walk(arena);
|
||||
defer walker.deinit();
|
||||
while (try walker.next(io)) |entry| {
|
||||
if (entry.kind != .file or !std.mem.endsWith(u8, entry.path, ".air")) continue;
|
||||
if (entry.kind != .file or !(std.mem.endsWith(u8, entry.path, ".air") or std.mem.endsWith(u8, entry.path, ".aji"))) continue;
|
||||
if (std.mem.indexOf(u8, entry.path, filter) == null) continue;
|
||||
try paths.append(arena, try arena.dupe(u8, entry.path));
|
||||
}
|
||||
@@ -108,7 +108,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
for (paths.items) |rel| {
|
||||
const source = try dir.readFileAlloc(io, rel, arena, .limited(16 << 20));
|
||||
const display = try std.fs.path.join(arena, &.{ root, rel });
|
||||
const result = try runOne(arena, display, source);
|
||||
const result = if (std.mem.endsWith(u8, rel, ".aji")) try runSource(arena, io, dir, rel, display, source) else try runOne(arena, display, source);
|
||||
counts.getPtr(result.outcome).* += 1;
|
||||
if (json) {
|
||||
var s: std.json.Stringify = .{ .writer = out };
|
||||
@@ -136,6 +136,42 @@ var stress_seeds: ?u64 = null;
|
||||
/// and odd slices (spec 04 §36.3); the test's own quantum is added.
|
||||
const stress_quanta = [_]u64{ 1, 2, 7 };
|
||||
|
||||
/// A `.aji` test (spec 15): the same header keys as AIR tests. Every
|
||||
/// accepted module must also lower deterministically, survive the round
|
||||
/// trip lower → parse → print unchanged, and match `<file>.expected` if
|
||||
/// that file exists (golden canonical AIR).
|
||||
fn runSource(arena: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, rel: []const u8, path: []const u8, source: []const u8) !Result {
|
||||
const header = parseHeader(arena, source) catch |err|
|
||||
return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "bad header: {t}", .{err}) };
|
||||
const report = try aji.check.checkFile(arena, path, source);
|
||||
if (report.status == .unimplemented) return .{ .outcome = .pending, .detail = report.missing_stage };
|
||||
if (report.lowered) |lowered| {
|
||||
const again = try aji.frontend.compile(arena, path, source);
|
||||
if (again != .ok or !std.mem.eql(u8, again.ok.air, lowered.air)) return .{ .outcome = .fail, .detail = "lowering is not deterministic" };
|
||||
const parsed = try aji.air.parse.parse(arena, path, lowered.air);
|
||||
if (parsed.module) |m| {
|
||||
var w: std.Io.Writer.Allocating = .init(arena);
|
||||
try aji.air.print.print(m, &w.writer);
|
||||
if (!std.mem.eql(u8, w.written(), lowered.air)) return .{ .outcome = .fail, .detail = "lowered AIR is not canonical (parse → print differs)" };
|
||||
}
|
||||
const golden_path = try std.fmt.allocPrint(arena, "{s}.expected", .{rel});
|
||||
if (dir.readFileAlloc(io, golden_path, arena, .limited(16 << 20))) |golden| {
|
||||
if (!std.mem.eql(u8, golden, lowered.air)) return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "lowered AIR differs from {s}", .{golden_path}) };
|
||||
} else |_| {}
|
||||
}
|
||||
var got: std.ArrayList([]const u8) = .empty;
|
||||
for (report.diagnostics) |d| if (d.severity == .@"error") try got.append(arena, d.code.id);
|
||||
std.mem.sort([]const u8, got.items, {}, lessThan);
|
||||
switch (header.expect) {
|
||||
.accept => if (report.status == .accepted) return .{ .outcome = .pass },
|
||||
.reject => |want| if (report.status == .rejected and eqlCodes(want, got.items)) return .{ .outcome = .pass },
|
||||
.run => |want| if (report.status == .accepted) return runModule(arena, path, report.module.?, want, header),
|
||||
}
|
||||
return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "expected {f}, got {t} {s}", .{
|
||||
fmtExpect(header.expect), report.status, try std.mem.join(arena, " ", got.items),
|
||||
}) };
|
||||
}
|
||||
|
||||
fn lessThan(_: void, a: []const u8, b: []const u8) bool {
|
||||
return std.mem.lessThan(u8, a, b);
|
||||
}
|
||||
@@ -372,8 +408,9 @@ fn parseHeader(arena: std.mem.Allocator, source: []const u8) HeaderError!Header
|
||||
|
||||
var lines = std.mem.splitScalar(u8, source, '\n');
|
||||
while (lines.next()) |line| {
|
||||
if (!std.mem.startsWith(u8, line, ";")) break;
|
||||
const content = std.mem.trim(u8, line[1..], " \t\r");
|
||||
// `.air` tests use `;` comments, `.aji` tests `//`.
|
||||
const prefix: usize = if (std.mem.startsWith(u8, line, "//")) 2 else if (std.mem.startsWith(u8, line, ";")) 1 else break;
|
||||
const content = std.mem.trim(u8, line[prefix..], " \t\r");
|
||||
const colon = std.mem.indexOfScalar(u8, content, ':') orelse continue; // free-form comment
|
||||
const key = content[0..colon];
|
||||
if (!isKey(key)) continue; // free-form comment containing a colon
|
||||
|
||||
Reference in new issue
Block a user