This commit is contained in:
agra
2026-03-05 16:20:36 +02:00
parent 22bc2439ce
commit f9dda972d2
36 changed files with 1063 additions and 7 deletions

View File

@@ -1220,6 +1220,24 @@ pub const Parser = struct {
return_type = try self.parseTypeExpr();
}
// Optional calling convention: callconv(.c)
var call_conv: ast.CallingConvention = .default;
if (self.current.tag == .kw_callconv) {
self.advance();
try self.expect(.l_paren);
try self.expect(.dot);
if (self.current.tag != .identifier)
return self.fail("expected calling convention name after '.'");
const cc_name = self.tokenSlice(self.current);
if (std.mem.eql(u8, cc_name, "c")) {
call_conv = .c;
} else {
return self.fail("unknown calling convention");
}
self.advance();
try self.expect(.r_paren);
}
// Body: block `{ ... }`, arrow `=> expr;`, #builtin, #compiler, or #foreign marker
var is_arrow = false;
const body = if (self.current.tag == .hash_builtin) blk: {
@@ -1273,6 +1291,7 @@ pub const Parser = struct {
.body = body,
.type_params = type_params,
.is_arrow = is_arrow,
.call_conv = call_conv,
} });
}
@@ -2333,6 +2352,24 @@ pub const Parser = struct {
return_type = try self.parseTypeExpr();
}
// Optional calling convention: callconv(.c)
var call_conv: ast.CallingConvention = .default;
if (self.current.tag == .kw_callconv) {
self.advance();
try self.expect(.l_paren);
try self.expect(.dot);
if (self.current.tag != .identifier)
return self.fail("expected calling convention name after '.'");
const cc_name = self.tokenSlice(self.current);
if (std.mem.eql(u8, cc_name, "c")) {
call_conv = .c;
} else {
return self.fail("unknown calling convention");
}
self.advance();
try self.expect(.r_paren);
}
// Two body forms:
// (params) => expr — expression lambda
// (params) { stmts } — block-body lambda
@@ -2348,6 +2385,7 @@ pub const Parser = struct {
.return_type = return_type,
.body = body,
.type_params = type_params,
.call_conv = call_conv,
} });
}
@@ -2365,7 +2403,7 @@ pub const Parser = struct {
fn isFunctionDef(self: *Parser) bool {
const tag = self.peekPastParens() orelse return false;
return tag == .l_brace or tag == .arrow or tag == .hash_builtin or tag == .hash_compiler or tag == .hash_foreign or tag == .fat_arrow;
return tag == .l_brace or tag == .arrow or tag == .hash_builtin or tag == .hash_compiler or tag == .hash_foreign or tag == .fat_arrow or tag == .kw_callconv;
}
fn isAssignOp(self: *const Parser) bool {