vtables, protocol
This commit is contained in:
28
src/ast.zig
28
src/ast.zig
@@ -64,6 +64,7 @@ pub const Node = struct {
|
||||
break_expr: void,
|
||||
continue_expr: void,
|
||||
undef_literal: void,
|
||||
inferred_type: void,
|
||||
builtin_expr: void,
|
||||
foreign_expr: ForeignExpr,
|
||||
library_decl: LibraryDecl,
|
||||
@@ -73,6 +74,8 @@ pub const Node = struct {
|
||||
tuple_literal: TupleLiteral,
|
||||
ufcs_alias: UfcsAlias,
|
||||
c_import_decl: CImportDecl,
|
||||
protocol_decl: ProtocolDecl,
|
||||
impl_block: ImplBlock,
|
||||
|
||||
pub fn declName(self: Data) ?[]const u8 {
|
||||
return switch (self) {
|
||||
@@ -85,6 +88,7 @@ pub const Node = struct {
|
||||
.namespace_decl => |d| d.name,
|
||||
.ufcs_alias => |d| d.name,
|
||||
.c_import_decl => |d| d.name,
|
||||
.protocol_decl => |d| d.name,
|
||||
else => null,
|
||||
};
|
||||
}
|
||||
@@ -274,6 +278,7 @@ pub const UnionDecl = struct {
|
||||
pub const StructTypeParam = struct {
|
||||
name: []const u8, // e.g. "N" or "T" (without $)
|
||||
constraint: *Node, // type_expr: "u32" for value param, "Type" for type param
|
||||
protocol_constraints: []const []const u8 = &.{}, // e.g. ["Eq", "Hashable"] for $T/Eq/Hashable
|
||||
};
|
||||
|
||||
pub const UsingEntry = struct {
|
||||
@@ -288,6 +293,7 @@ pub const StructDecl = struct {
|
||||
field_defaults: []const ?*Node, // default value per field, null if none
|
||||
type_params: []const StructTypeParam = &.{},
|
||||
using_entries: []const UsingEntry = &.{},
|
||||
methods: []const *Node = &.{}, // fn_decl nodes for struct methods
|
||||
};
|
||||
|
||||
pub const StructFieldInit = struct {
|
||||
@@ -311,6 +317,7 @@ pub const Lambda = struct {
|
||||
pub const TypeExpr = struct {
|
||||
name: []const u8,
|
||||
is_generic: bool = false,
|
||||
protocol_constraints: []const []const u8 = &.{}, // e.g. ["Eq", "Hashable"] for $T/Eq/Hashable
|
||||
};
|
||||
|
||||
pub const DeferStmt = struct {
|
||||
@@ -465,3 +472,24 @@ pub const CImportDecl = struct {
|
||||
name: ?[]const u8 = null,
|
||||
bitcode_paths: []const []const u8 = &.{}, // populated during import resolution
|
||||
};
|
||||
|
||||
pub const ProtocolMethodDecl = struct {
|
||||
name: []const u8,
|
||||
params: []const *Node, // type_expr nodes for parameter types (excluding implicit self)
|
||||
param_names: []const []const u8, // parameter names (excluding implicit self)
|
||||
return_type: ?*Node, // null = void return
|
||||
default_body: ?*Node, // null = required method, non-null = default implementation
|
||||
};
|
||||
|
||||
pub const ProtocolDecl = struct {
|
||||
name: []const u8,
|
||||
methods: []const ProtocolMethodDecl,
|
||||
is_inline: bool = false, // #inline — embedded fn ptrs instead of vtable pointer
|
||||
};
|
||||
|
||||
pub const ImplBlock = struct {
|
||||
protocol_name: []const u8,
|
||||
target_type: []const u8,
|
||||
target_type_params: []const StructTypeParam = &.{}, // for `impl P for List($T)`
|
||||
methods: []const *Node, // fn_decl nodes
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user