feat: 模块系统 mod + pub — 多文件编译支持

This commit is contained in:
2026-06-06 16:09:30 +08:00
parent e02cc7b1d6
commit fa734b8a23
9 changed files with 197 additions and 22 deletions
+17 -1
View File
@@ -30,12 +30,14 @@ AstNode* ast_make_program(void* alloc, AstNode** fns, size_t fn_count,
}
AstNode* ast_make_function(void* alloc, const char* name, AstNode** params, size_t pcount,
TypeKind ret, const char* ret_struct_name, AstNode* body, SourceLoc loc) {
TypeKind ret, const char* ret_struct_name, AstNode* body,
bool is_pub, SourceLoc loc) {
NEW(alloc, AST_FUNCTION);
n->as.function.name = name; n->as.function.params = params;
n->as.function.param_count = pcount; n->as.function.return_type = ret;
n->as.function.return_struct_type_name = ret_struct_name;
n->as.function.body = body;
n->as.function.is_pub = is_pub;
return n;
}
@@ -255,3 +257,17 @@ AstNode* ast_make_method_call(void* alloc, AstNode* receiver, const char* method
n->as.method_call.arg_count = count;
return n;
}
AstNode* ast_make_mod_decl(void* alloc, const char* name, AstNode* sub_ast, SourceLoc loc) {
NEW(alloc, AST_MOD_DECL);
n->as.mod_decl.name = name;
n->as.mod_decl.ast = sub_ast;
return n;
}
AstNode* ast_make_use_decl(void* alloc, const char* path, const char* item, SourceLoc loc) {
NEW(alloc, AST_USE_DECL);
n->as.use_decl.path = path;
n->as.use_decl.item = item;
return n;
}