interp: deterministic interpreter, aji run, run tests (P0-11, P0-12)
- src/interp/machine.zig: format-0 interpreter on the air64 target; checked/wrapping arithmetic, shifts, casts, aggregates, calls with a 1024-frame limit, traps as records with T0xxx codes - aji run: prints one JSON run record; exit code 4 on trap - conformance runner: `expect: run` with `result:`/`trap:`, every run executed twice and compared byte-for-byte; header keys must be single lowercase words - Phase 0 corpus: 3 accept, 19 reject, 15 run tests (41 total)
This commit is contained in:
1 parent
50bf990355
commit
1f5008bb37
45 files changed
+1463
-23
No files matched your search
+17
-5
@@ -3,8 +3,9 @@
|
||||
//! Output contract (stable, consumed by agents):
|
||||
//! - diagnostics go to stdout as JSON Lines, one object per line;
|
||||
//! - human-oriented notes go to stderr;
|
||||
//! - exit codes: 0 accepted, 1 rejected, 2 usage or I/O error,
|
||||
//! 3 input not decidable yet (pipeline stage unimplemented).
|
||||
//! - `aji run` writes one run record (spec 07a "Run result") to stdout;
|
||||
//! - exit codes: 0 accepted / returned, 1 rejected, 2 usage or I/O error,
|
||||
//! 3 input not decidable yet (pipeline stage unimplemented), 4 trapped.
|
||||
|
||||
const std = @import("std");
|
||||
const aji = @import("aji");
|
||||
@@ -14,13 +15,14 @@ const usage =
|
||||
\\
|
||||
\\commands:
|
||||
\\ check <file.air> parse and verify a text AIR module
|
||||
\\ run <file.air> verify, then run @main and print the run record
|
||||
\\ codes list diagnostic codes as JSON Lines
|
||||
\\ explain <code> show one diagnostic code
|
||||
\\ version print toolchain version
|
||||
\\
|
||||
;
|
||||
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3 };
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4 };
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const arena = init.arena.allocator();
|
||||
@@ -59,8 +61,8 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
try writeCode(out, c.*);
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "check")) {
|
||||
if (args.len != 3) return usageError("check takes exactly one file");
|
||||
if (std.mem.eql(u8, cmd, "check") or std.mem.eql(u8, cmd, "run")) {
|
||||
if (args.len != 3) return usageError("check and run take exactly one file");
|
||||
const path = args[2];
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
@@ -71,6 +73,16 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
try d.writeJson(out);
|
||||
try out.writeByte('\n');
|
||||
}
|
||||
if (report.status == .accepted and std.mem.eql(u8, cmd, "run")) {
|
||||
const module = report.module.?;
|
||||
const outcome = aji.interp.run(arena, module, "main") catch |err| switch (err) {
|
||||
error.EntryNotFound => return usageError("module has no parameterless @main"),
|
||||
else => |e| return e,
|
||||
};
|
||||
try aji.interp.writeOutcome(module, outcome, out);
|
||||
try out.writeByte('\n');
|
||||
return if (outcome == .trapped) .trapped else .accepted;
|
||||
}
|
||||
return switch (report.status) {
|
||||
.accepted => .accepted,
|
||||
.rejected => .rejected,
|
||||
|
||||
Reference in new issue
Block a user