feat: trait 接口系统 — trait Show { fn method } + extend Trait Struct { }

This commit is contained in:
2026-06-06 16:41:21 +08:00
parent 9169796b77
commit b3b3d285f9
9 changed files with 126 additions and 12 deletions
+4
View File
@@ -32,6 +32,7 @@ typedef enum {
AST_METHOD_CALL, // receiver.method(args)
AST_MOD_DECL, // mod foo;
AST_USE_DECL, // use foo::bar;
AST_TRAIT_DECL, // trait Name { fn ... }
} AstKind;
typedef enum {
@@ -127,6 +128,8 @@ struct AstNode {
struct { const char* name; struct AstNode* ast; } mod_decl;
// AST_USE_DECL
struct { const char* path; const char* item; } use_decl;
// AST_TRAIT_DECL
struct { const char* name; struct AstNode** methods; size_t method_count; } trait_decl;
} as;
};
@@ -175,5 +178,6 @@ AstNode* ast_make_impl_block(void* alloc, const char* struct_name, AstNode** met
AstNode* ast_make_method_call(void* alloc, AstNode* receiver, const char* method, AstNode** args, const char** arg_names, size_t count, SourceLoc loc);
AstNode* ast_make_mod_decl(void* alloc, const char* name, AstNode* sub_ast, SourceLoc loc);
AstNode* ast_make_use_decl(void* alloc, const char* path, const char* item, SourceLoc loc);
AstNode* ast_make_trait_decl(void* alloc, const char* name, AstNode** methods, size_t count, SourceLoc loc);
#endif