Phase 2: I/O intrinsics, linear resources, deterministic profile (RFC 0007)
- air: resource types file<read|write|append>, listener, stream; io_error; intrinsic registry (19 intrinsics) synced with reference/intrinsics.md; fallible intrinsics as ok/err terminators; fs prefix narrowing; linear_aggregates gating - verifier: intrinsic form, operand, result and capability-kind checks (E1001, E3201, E5002); intrinsic effects (E3101); resource linearity in the borrow walker with per-edge moves: E3002 leaks and join mismatches, E3001, E2001, E2002, E2101 for close while borrowed; resources as borrow roots - interp: deterministic world (captured console, VFS, loopback TCP, instruction clock, pinned xoshiro256 PRNG), blocked outcome, run record with stdout/stderr/files - CLI: --stdin, --vfs, --seed, --result-file, --profile (hosted: exit 3), exit code 7; runner: stdin/vfs/seed/stdout/stderr/file/blocked headers - conformance: hello, file copy and TCP echo exit programs; 37 new tests; 4000 mutants without a crash
This commit is contained in:
1 parent
571cc6e362
commit
d405d4ea50
49 files changed
+2325
-81
No files matched your search
+44
-8
@@ -7,7 +7,8 @@
|
||||
//! - exit codes: 0 accepted / returned, 1 rejected, 2 usage or I/O error,
|
||||
//! 3 input not decidable yet (pipeline stage unimplemented), 4 trapped,
|
||||
//! 5 execution limit exceeded (`--fuel`, spec 11 §7),
|
||||
//! 6 not instantiated (missing or invalid `--grant`, spec 05 §10.2).
|
||||
//! 6 not instantiated (missing or invalid `--grant`, spec 05 §10.2),
|
||||
//! 7 blocked: no future event can complete a wait (spec 11 §8).
|
||||
|
||||
const std = @import("std");
|
||||
const aji = @import("aji");
|
||||
@@ -20,7 +21,10 @@ const usage =
|
||||
\\ run [--fuel N] [--grant P=KIND[:SCOPE]]... <file.air>
|
||||
\\ verify, then run @main and print the run record;
|
||||
\\ --fuel stops after N executed instructions;
|
||||
\\ --grant binds capability parameter P of @main
|
||||
\\ --grant binds capability parameter P of @main;
|
||||
\\ deterministic world: --stdin TEXT, --vfs PATH=TEXT,
|
||||
\\ --seed N; --result-file PATH also writes the record;
|
||||
\\ --profile hosted is not implemented yet
|
||||
\\ codes list diagnostic codes as JSON Lines
|
||||
\\ features print supported AIR format, language version and features
|
||||
\\ explain <code> show one diagnostic code
|
||||
@@ -28,7 +32,7 @@ const usage =
|
||||
\\
|
||||
;
|
||||
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4, limit_exceeded = 5, not_instantiated = 6 };
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4, limit_exceeded = 5, not_instantiated = 6, blocked = 7 };
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const arena = init.arena.allocator();
|
||||
@@ -80,16 +84,36 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
if (std.mem.eql(u8, cmd, "check") or std.mem.eql(u8, cmd, "run")) {
|
||||
var options: aji.interp.Options = .{};
|
||||
var grants: std.ArrayList(aji.interp.Grant) = .empty;
|
||||
var files: std.ArrayList(struct { []const u8, []const u8 }) = .empty;
|
||||
var result_file: ?[]const u8 = null;
|
||||
var rest = args[2..];
|
||||
while (std.mem.eql(u8, cmd, "run") and rest.len >= 3) {
|
||||
if (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");
|
||||
} else if (std.mem.eql(u8, rest[0], "--grant")) {
|
||||
try grants.append(arena, parseGrant(rest[1]) orelse return usageError("--grant takes <parameter>=<kind>[:<scope>]"));
|
||||
const flag = rest[0];
|
||||
const value = rest[1];
|
||||
if (std.mem.eql(u8, flag, "--fuel")) {
|
||||
options.fuel = std.fmt.parseInt(u64, value, 10) catch return usageError("--fuel takes a non-negative integer");
|
||||
} else if (std.mem.eql(u8, flag, "--grant")) {
|
||||
try grants.append(arena, parseGrant(value) orelse return usageError("--grant takes <parameter>=<kind>[:<scope>]"));
|
||||
} else if (std.mem.eql(u8, flag, "--profile")) {
|
||||
if (std.mem.eql(u8, value, "hosted")) {
|
||||
std.debug.print("aji: not implemented yet: hosted profile\n", .{});
|
||||
return .unimplemented;
|
||||
}
|
||||
if (!std.mem.eql(u8, value, "deterministic")) return usageError("--profile takes deterministic or hosted");
|
||||
} else if (std.mem.eql(u8, flag, "--stdin")) {
|
||||
options.world.stdin = value;
|
||||
} else if (std.mem.eql(u8, flag, "--vfs")) {
|
||||
const eq = std.mem.indexOfScalar(u8, value, '=') orelse return usageError("--vfs takes <path>=<text>");
|
||||
try files.append(arena, .{ value[0..eq], value[eq + 1 ..] });
|
||||
} else if (std.mem.eql(u8, flag, "--seed")) {
|
||||
options.world.seed = std.fmt.parseInt(u64, value, 10) catch return usageError("--seed takes a non-negative integer");
|
||||
} else if (std.mem.eql(u8, flag, "--result-file")) {
|
||||
result_file = value;
|
||||
} else break;
|
||||
rest = rest[2..];
|
||||
}
|
||||
options.grants = grants.items;
|
||||
options.world.files = files.items;
|
||||
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| {
|
||||
@@ -103,18 +127,30 @@ 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.?;
|
||||
var output: aji.interp.Output = undefined;
|
||||
options.output = &output;
|
||||
const outcome = aji.interp.run(arena, module, "main", options) catch |err| switch (err) {
|
||||
error.EntryNotFound => return usageError("module has no @main whose parameters are all capabilities"),
|
||||
error.DuplicateGrant => return usageError("a parameter is granted more than once"),
|
||||
else => |e| return e,
|
||||
};
|
||||
try aji.interp.writeOutcome(module, outcome, out);
|
||||
try aji.interp.writeOutcome(module, outcome, output, out);
|
||||
try out.writeByte('\n');
|
||||
if (result_file) |rpath| {
|
||||
var rec: std.Io.Writer.Allocating = .init(arena);
|
||||
try aji.interp.writeOutcome(module, outcome, output, &rec.writer);
|
||||
try rec.writer.writeByte('\n');
|
||||
std.Io.Dir.cwd().writeFile(io, .{ .sub_path = rpath, .data = rec.written() }) catch |err| {
|
||||
std.debug.print("aji: cannot write {s}: {t}\n", .{ rpath, err });
|
||||
return .usage;
|
||||
};
|
||||
}
|
||||
return switch (outcome) {
|
||||
.returned => .accepted,
|
||||
.trapped => .trapped,
|
||||
.limit_exceeded => .limit_exceeded,
|
||||
.not_instantiated => .not_instantiated,
|
||||
.blocked => .blocked,
|
||||
};
|
||||
}
|
||||
return switch (report.status) {
|
||||
|
||||
Reference in new issue
Block a user