Phase 2: effects and capabilities (RFC 0006)
- air: cap<K> and built-in enums (cap_error) as types; enum.switch over built-in enums; cap.narrow terminator with ok/err targets; intrinsic syntax (registry still empty: E0004); registries for effects, capability kinds and built-in enums, synced with reference docs - verifier: effect stage (E3101, flat, direct callees); cap.narrow form check (E3202) and ok/err parameter rules (E5002, E1001); capabilities are copyable, not zeroable, not comparable; sizes cap 8, built-in tag - interp: host authority table; @main instantiation from grants by parameter name with not_instantiated reasons; capabilities render as opaque - CLI: --grant P=KIND[:SCOPE], exit code 6; runner: grant: and not_instantiated: headers, pending only for unsupported features - conformance: 18 Phase 2 tests; 4000 mutants without a crash
This commit is contained in:
1 parent
fb4338cea6
commit
9c29a80b72
41 files changed
+908
-58
No files matched your search
+40
-7
@@ -6,7 +6,8 @@
|
||||
//! - `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,
|
||||
//! 5 execution limit exceeded (`--fuel`, spec 11 §7).
|
||||
//! 5 execution limit exceeded (`--fuel`, spec 11 §7),
|
||||
//! 6 not instantiated (missing or invalid `--grant`, spec 05 §10.2).
|
||||
|
||||
const std = @import("std");
|
||||
const aji = @import("aji");
|
||||
@@ -16,9 +17,10 @@ const usage =
|
||||
\\
|
||||
\\commands:
|
||||
\\ check <file.air> parse and verify a text AIR module
|
||||
\\ run [--fuel N] <file.air>
|
||||
\\ run [--fuel N] [--grant P=KIND[:SCOPE]]... <file.air>
|
||||
\\ verify, then run @main and print the run record;
|
||||
\\ --fuel stops after N executed instructions
|
||||
\\ --fuel stops after N executed instructions;
|
||||
\\ --grant binds capability parameter P of @main
|
||||
\\ codes list diagnostic codes as JSON Lines
|
||||
\\ features print supported AIR format, language version and features
|
||||
\\ explain <code> show one diagnostic code
|
||||
@@ -26,7 +28,7 @@ const usage =
|
||||
\\
|
||||
;
|
||||
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4, limit_exceeded = 5 };
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3, trapped = 4, limit_exceeded = 5, not_instantiated = 6 };
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const arena = init.arena.allocator();
|
||||
@@ -77,11 +79,17 @@ 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 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");
|
||||
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>]"));
|
||||
} else break;
|
||||
rest = rest[2..];
|
||||
}
|
||||
options.grants = grants.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| {
|
||||
@@ -96,7 +104,8 @@ 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", options) catch |err| switch (err) {
|
||||
error.EntryNotFound => return usageError("module has no parameterless @main"),
|
||||
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);
|
||||
@@ -105,6 +114,7 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
.returned => .accepted,
|
||||
.trapped => .trapped,
|
||||
.limit_exceeded => .limit_exceeded,
|
||||
.not_instantiated => .not_instantiated,
|
||||
};
|
||||
}
|
||||
return switch (report.status) {
|
||||
@@ -129,3 +139,26 @@ fn usageError(msg: []const u8) ExitCode {
|
||||
std.debug.print("aji: {s}\n\n{s}", .{ msg, usage });
|
||||
return .usage;
|
||||
}
|
||||
|
||||
/// `<parameter>=<kind>[:<scope>]` (reference/capabilities.md).
|
||||
pub fn parseGrant(text: []const u8) ?aji.interp.Grant {
|
||||
const eq = std.mem.indexOfScalar(u8, text, '=') orelse return null;
|
||||
const rest = text[eq + 1 ..];
|
||||
const colon = std.mem.indexOfScalar(u8, rest, ':');
|
||||
const g: aji.interp.Grant = .{
|
||||
.parameter = text[0..eq],
|
||||
.kind = if (colon) |c| rest[0..c] else rest,
|
||||
.scope = if (colon) |c| rest[c + 1 ..] else null,
|
||||
};
|
||||
if (g.parameter.len == 0 or g.kind.len == 0) return null;
|
||||
return g;
|
||||
}
|
||||
|
||||
test parseGrant {
|
||||
const g = parseGrant("data=fs.read:/var/data").?;
|
||||
try std.testing.expectEqualStrings("data", g.parameter);
|
||||
try std.testing.expectEqualStrings("fs.read", g.kind);
|
||||
try std.testing.expectEqualStrings("/var/data", g.scope.?);
|
||||
try std.testing.expect(parseGrant("out=io.write").?.scope == null);
|
||||
try std.testing.expect(parseGrant("io.write") == null);
|
||||
}
|
||||
Reference in new issue
Block a user