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
+6 -2
View File
@@ -431,8 +431,12 @@ static LLVMValueRef codegen_expr(CgCtx* ctx, AstNode* node) {
case AST_METHOD_CALL: {
const char* struct_name = node->as.method_call.receiver->type.struct_name;
char mangled[256];
snprintf(mangled, sizeof(mangled), "%s$%s", struct_name,
node->as.method_call.method_name);
// 若 method_name 已含 $trait 方法,sema 已设置全限定名),直接用
if (strchr(node->as.method_call.method_name, '$'))
snprintf(mangled, sizeof(mangled), "%s", node->as.method_call.method_name);
else
snprintf(mangled, sizeof(mangled), "%s$%s", struct_name,
node->as.method_call.method_name);
LLVMValueRef fn = find_fn(ctx, mangled);
if (!fn) return NULL;
// 参数列表: [receiver, 用户参数...]