spec: single normative source, accept RFC 0004, freeze AIR format 0, fuel

Owner decisions after the Phase 0 review:

- precedence: docs/spec/ is the single normative source; RFCs are
  decision records whose accepted rules are integrated into the spec in
  the same change (AGENTS.md, docs/README.md, rfcs/README.md, DD-011)
- RFC 0004 Accepted (scope: AIR format 0, language 0.1)
- AIR format 0 frozen as the semantic baseline; spec 07 §8.7 defines the
  only permitted additive changes, everything else needs `air 1` (DD-012)
- Q-019 resolved: deterministic instruction fuel (spec 11 §7). Outcome
  `limit_exceeded` is a runner outcome, not a trap; `aji run --fuel N`,
  exit code 5; conformance runs always use fuel (default 1 000 000,
  `fuel:` header); fuel/schedule budget/quantum kept separate for P3
  (DD-013)
This commit is contained in:
dev committed 2026-10-04 12:40:32 +03:00
1 parent dc36b5cfc0
commit 03dda1245a
24 files changed
+268 -63

No files matched your search

+20 -7
View File
@@ -5,7 +5,8 @@
//! - human-oriented notes go to stderr;
//! - `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.
//! 3 input not decidable yet (pipeline stage unimplemented), 4 trapped,
//! 5 execution limit exceeded (`--fuel`, spec 11 §7).
const std = @import("std");
const aji = @import("aji");
@@ -15,14 +16,16 @@ 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
\\ run [--fuel N] <file.air>
\\ verify, then run @main and print the run record;
\\ --fuel stops after N executed instructions
\\ 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, trapped = 4 };
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4, limit_exceeded = 5 };
pub fn main(init: std.process.Init) !void {
const arena = init.arena.allocator();
@@ -62,8 +65,14 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
return .accepted;
}
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];
var options: aji.interp.Options = .{};
var rest = args[2..];
if (std.mem.eql(u8, cmd, "run") and rest.len == 3 and std.mem.eql(u8, rest[0], "--fuel")) {
options.fuel = std.fmt.parseInt(u64, rest[1], 10) catch return usageError("--fuel takes a non-negative integer");
rest = rest[2..];
}
if (rest.len != 1) return usageError("check and run take exactly one file");
const path = rest[0];
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 });
return .usage;
@@ -75,13 +84,17 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
}
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) {
const outcome = aji.interp.run(arena, module, "main", options) 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 (outcome) {
.returned => .accepted,
.trapped => .trapped,
.limit_exceeded => .limit_exceeded,
};
}
return switch (report.status) {
.accepted => .accepted,