Phase 6A: .aji layer 6 (intrinsics, resources, narrowing, unsafe operations)
- intrinsics from the registry as plain calls: fallible ones are outcome matches or `or trap` (E7006 otherwise), infallible ones plain calls - resource operands by name, borrowed mut for the one operation and ended on every edge; a mut binding/parameter passes as is; `mut f` is E7006 - closes consume with `move` (E7003); no inserted closes (E3002/E3001) - data operands explicit (ref/mut/byte string, E7005 otherwise) - file<…>, stream, listener types; cap.narrow.prefix with cap_error edges - ref/mut unchecked s[i] (also as a binding) and assume(c) under effects [unsafe]; boundary left to the verifier (E6001) - trusted is reserved and rejected (E7006) - parameter names preserved; generated names avoid them (normative) - parser: >> closes two type arguments - conformance: `equivalent:` compares the run record with a reference AIR program (hello, file_copy, tcp_echo, narrow ok/not_subset/invalid, random) - spec 15, grammar, quick reference (io_error match fixed), plan, examples
This commit is contained in:
1 parent
bdcf871e5d
commit
c18fb7acc1
39 files changed
+1309
-69
No files matched your search
+30
-11
@@ -16,7 +16,7 @@ pub const Result = union(enum) { ok: ast.Module, err: Failure };
|
||||
|
||||
pub fn parse(arena: Allocator, src: []const u8) Allocator.Error!Result {
|
||||
const tokens = try lex.tokenize(arena, src);
|
||||
var p: Parser = .{ .arena = arena, .tokens = tokens };
|
||||
var p: Parser = .{ .arena = arena, .tokens = try arena.dupe(Token, tokens) };
|
||||
const m = p.module() catch |e| switch (e) {
|
||||
error.Syntax => return .{ .err = p.failure.? },
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
@@ -28,7 +28,7 @@ const Error = error{ Syntax, OutOfMemory };
|
||||
|
||||
const Parser = struct {
|
||||
arena: Allocator,
|
||||
tokens: []const Token,
|
||||
tokens: []Token,
|
||||
pos: usize = 0,
|
||||
failure: ?Failure = null,
|
||||
/// Struct literals are not allowed where a `{` starts a block (conditions).
|
||||
@@ -63,6 +63,21 @@ const Parser = struct {
|
||||
return p.next();
|
||||
}
|
||||
|
||||
/// The `>` closing a type argument. `>>` closes two (`mut<file<write>>`):
|
||||
/// the first half is taken and the second stays as the next token.
|
||||
fn closeAngle(p: *Parser) Error!void {
|
||||
const t = p.peek();
|
||||
if (t.tag == .shr) {
|
||||
var rest = t;
|
||||
rest.tag = .gt;
|
||||
rest.text = t.text[1..];
|
||||
rest.pos.col += 1;
|
||||
p.tokens[p.pos] = rest;
|
||||
return;
|
||||
}
|
||||
_ = try p.expect(.gt, "`>`");
|
||||
}
|
||||
|
||||
fn isWord(t: Token, w: []const u8) bool {
|
||||
return t.tag == .ident and std.mem.eql(u8, t.text, w);
|
||||
}
|
||||
@@ -197,9 +212,11 @@ const Parser = struct {
|
||||
_ = try p.expect(.r_bracket, "`]`");
|
||||
var trusted: ?[]const u8 = null;
|
||||
if (p.atWord("trusted")) {
|
||||
_ = p.next();
|
||||
const t = try p.expect(.bytes, "an obligation string b\"…\"");
|
||||
trusted = (try lex.decodeBytes(p.arena, t.text)) orelse return p.fail(t, "a valid string");
|
||||
// Reserved: lowering rejects it with E7006 (spec 15 §8), so the
|
||||
// obligation text, in whatever form, is skipped up to the body.
|
||||
const t = p.next();
|
||||
while (p.peek().tag != .l_brace and p.peek().tag != .eof) _ = p.next();
|
||||
trusted = t.text;
|
||||
}
|
||||
const body = try p.block();
|
||||
return .{ .name = name, .span = p.span(start), .params = params.items, .ret = ret, .from = from, .effects = effects.items, .trusted = trusted, .body = body };
|
||||
@@ -225,16 +242,16 @@ const Parser = struct {
|
||||
_ = p.next();
|
||||
if (std.mem.eql(u8, t.text, "cap")) {
|
||||
const k = try p.path();
|
||||
_ = try p.expect(.gt, "`>`");
|
||||
try p.closeAngle();
|
||||
return .{ .span = p.span(start), .kind = .{ .cap = k } };
|
||||
}
|
||||
if (std.mem.eql(u8, t.text, "file")) {
|
||||
const m = try p.ident("`read`, `write` or `append`");
|
||||
_ = try p.expect(.gt, "`>`");
|
||||
try p.closeAngle();
|
||||
return .{ .span = p.span(start), .kind = .{ .file = m } };
|
||||
}
|
||||
const inner = try p.typeExpr();
|
||||
_ = try p.expect(.gt, "`>`");
|
||||
try p.closeAngle();
|
||||
return .{ .span = p.span(start), .kind = .{ .wrapped = .{ .wrapper = t.text, .inner = try p.box(ast.Type, inner) } } };
|
||||
}
|
||||
|
||||
@@ -279,13 +296,15 @@ const Parser = struct {
|
||||
_ = try p.expect(.semicolon, "`;`");
|
||||
return .{ .span = p.span(start), .kind = .{ .let = .{ .names = names.items, .ty = ty, .e = e } } };
|
||||
}
|
||||
if ((isWord(t, "ref") or isWord(t, "mut")) and p.peekAt(1).tag == .ident and p.peekAt(2).tag == .eq) {
|
||||
const unchecked_borrow = isWord(p.peekAt(1), "unchecked") and p.peekAt(2).tag == .ident and p.peekAt(3).tag == .eq;
|
||||
if ((isWord(t, "ref") or isWord(t, "mut")) and ((p.peekAt(1).tag == .ident and p.peekAt(2).tag == .eq) or unchecked_borrow)) {
|
||||
_ = p.next();
|
||||
if (unchecked_borrow) _ = p.next();
|
||||
const name = try p.ident("a name for the borrow");
|
||||
_ = try p.expect(.eq, "`=`");
|
||||
const place = try p.expr();
|
||||
_ = try p.expect(.semicolon, "`;`");
|
||||
return .{ .span = p.span(start), .kind = .{ .borrow = .{ .mutable = isWord(t, "mut"), .name = name, .place = place } } };
|
||||
return .{ .span = p.span(start), .kind = .{ .borrow = .{ .mutable = isWord(t, "mut"), .unchecked = unchecked_borrow, .name = name, .place = place } } };
|
||||
}
|
||||
if (isWord(t, "var")) {
|
||||
_ = p.next();
|
||||
@@ -608,7 +627,7 @@ const Parser = struct {
|
||||
if (std.mem.eql(u8, name, "make") and p.peek().tag == .lt and e.kind.field.e.kind == .name and std.mem.eql(u8, e.kind.field.e.kind.name, "channel")) {
|
||||
_ = p.next();
|
||||
const ty = try p.typeExpr();
|
||||
_ = try p.expect(.gt, "`>`");
|
||||
try p.closeAngle();
|
||||
const args = try p.callArgs();
|
||||
const callee = try p.box(ast.Expr, e);
|
||||
e = .{ .span = p.span(start), .kind = .{ .call = .{ .callee = callee, .type_arg = ty, .args = args } } };
|
||||
|
||||
Reference in new issue
Block a user