ai: 实现mod语法 提供namespace框架

This commit is contained in:
zzy committed 2026-12-02 13:02:58 +08:00
1 parent e531aab2d3
commit 663adf6cae
11 files changed
+1001 -187

No files matched your search

+53 -42
View File
@@ -2113,20 +2113,9 @@ static void emit_aggregate_fns_body(spl_ast2ir_t *a, spl_ast_node_t *te) {
}
}
static void emit_container_reserve(spl_ast2ir_t *a, spl_ast_node_ref_t ref) {
spl_ast_node_t *n = spl_ast_node(a->ast, ref);
if (!n)
return;
if (n->kind == SPL_AST_TOP_LEVEL_BLOCK) {
if (n->top_level_block.block)
emit_container_reserve(a, n->top_level_block.block);
return;
}
if (n->kind != SPL_AST_CONTAINER_MEMBERS)
return;
for (usize i = 0; i < vec_size(n->container_members.declarations); ++i) {
spl_ast_node_ref_t dref = vec_at(n->container_members.declarations, i);
static void emit_decls_reserve(spl_ast2ir_t *a, spl_ast_node_ref_vec_t *decls) {
for (usize i = 0; i < vec_size(*decls); ++i) {
spl_ast_node_ref_t dref = vec_at(*decls, i);
spl_ast_node_t *d = spl_ast_node(a->ast, dref);
if (!d)
continue;
@@ -2143,8 +2132,55 @@ static void emit_container_reserve(spl_ast2ir_t *a, spl_ast_node_ref_t ref) {
emit_aggregate_fns_reserve(a, te);
break;
}
case SPL_AST_TOP_LEVEL_BLOCK:
emit_container_reserve(a, dref);
case SPL_AST_VAR_DECL:
case SPL_AST_CONST_DECL:
break;
case SPL_AST_MOD_DECL:
if (d->mod_decl.has_body)
emit_decls_reserve(a, &d->mod_decl.decls);
break;
default:
break;
}
}
}
static void emit_container_reserve(spl_ast2ir_t *a, spl_ast_node_ref_t ref) {
spl_ast_node_t *n = spl_ast_node(a->ast, ref);
if (!n)
return;
if (n->kind == SPL_AST_TOP_LEVEL_BLOCK) {
if (n->top_level_block.block)
emit_container_reserve(a, n->top_level_block.block);
return;
}
if (n->kind != SPL_AST_CONTAINER_MEMBERS)
return;
emit_decls_reserve(a, &n->container_members.declarations);
}
static void emit_decls_body(spl_ast2ir_t *a, spl_ast_node_ref_vec_t *decls) {
for (usize i = 0; i < vec_size(*decls); ++i) {
spl_ast_node_ref_t dref = vec_at(*decls, i);
spl_ast_node_t *d = spl_ast_node(a->ast, dref);
if (!d)
continue;
switch (d->kind) {
case SPL_AST_FN_DECL:
emit_fn_body(a, d);
break;
case SPL_AST_TYPE_DECL: {
spl_ast_node_t *tpat = spl_ast_node(a->ast, d->type_decl.pattern);
if (!tpat || tpat->kind != SPL_AST_PATTERN_IDENT)
break;
spl_ast_node_t *te = spl_ast_node(a->ast, d->type_decl.type_expr);
if (te && te->kind == SPL_AST_TYPE_AGGREGATE)
emit_aggregate_fns_body(a, te);
break;
}
case SPL_AST_MOD_DECL:
if (d->mod_decl.has_body)
emit_decls_body(a, &d->mod_decl.decls);
break;
default:
break;
@@ -2163,32 +2199,7 @@ static void emit_container_body(spl_ast2ir_t *a, spl_ast_node_ref_t ref) {
}
if (n->kind != SPL_AST_CONTAINER_MEMBERS)
return;
for (usize i = 0; i < vec_size(n->container_members.declarations); ++i) {
spl_ast_node_ref_t dref = vec_at(n->container_members.declarations, i);
spl_ast_node_t *d = spl_ast_node(a->ast, dref);
if (!d)
continue;
switch (d->kind) {
case SPL_AST_FN_DECL:
emit_fn_body(a, d);
break;
case SPL_AST_TYPE_DECL: {
spl_ast_node_t *tpat = spl_ast_node(a->ast, d->type_decl.pattern);
if (!tpat || tpat->kind != SPL_AST_PATTERN_IDENT)
break;
spl_ast_node_t *te = spl_ast_node(a->ast, d->type_decl.type_expr);
if (te && te->kind == SPL_AST_TYPE_AGGREGATE)
emit_aggregate_fns_body(a, te);
break;
}
case SPL_AST_TOP_LEVEL_BLOCK:
emit_container_body(a, dref);
break;
default:
break;
}
}
emit_decls_body(a, &n->container_members.declarations);
}
static spl_ir_node_ref_t emit_implicit_cast(spl_ast2ir_t *a, spl_ast_node_t *n, spl_type_id_t ft,