feat: in/out 参数 — out 关键字引用传递
fn swap(out x: i64, out y: i64) 声明 out 参数,codegen 层面 函数签名变为 T* 指针,调用点自动传 &variable 地址。 in 是默认行为(值传递),无需显式标注。 Token → Parser → Sema → Codegen 全流水线: - TOK_OUT + "out" 关键字注册 - AST parameter.is_out 字段 - parse_function 解析 out 前缀 - Sema: out 参数注册为 SYM_VARIABLE+is_mut(可赋值) - Codegen: LLVM 函数签名使用 T*,调用点传 alloca Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -74,7 +74,7 @@ struct AstNode {
|
||||
const char** type_params; size_t type_param_count;
|
||||
TypeKind* multi_ret_types; const char** multi_ret_snames; size_t multi_ret_count; } function;
|
||||
// AST_PARAMETER (也用作结构体字段: name + type)
|
||||
struct { const char* name; TypeKind type; const char* struct_type_name; } parameter;
|
||||
struct { const char* name; TypeKind type; const char* struct_type_name; bool is_out; } parameter;
|
||||
// AST_BLOCK
|
||||
struct { struct AstNode** stmts; size_t stmt_count; } block;
|
||||
// AST_LET_STMT
|
||||
@@ -150,7 +150,7 @@ AstNode* ast_make_function(void* alloc, const char* name, AstNode** params, size
|
||||
TypeKind ret, const char* ret_struct_name, AstNode* body,
|
||||
bool is_pub, const char** type_params, size_t tp_count,
|
||||
SourceLoc loc);
|
||||
AstNode* ast_make_parameter(void* alloc, const char* name, TypeKind type, const char* struct_type_name, SourceLoc loc);
|
||||
AstNode* ast_make_parameter(void* alloc, const char* name, TypeKind type, const char* struct_type_name, bool is_out, SourceLoc loc);
|
||||
AstNode* ast_make_block(void* alloc, AstNode** stmts, size_t count, SourceLoc loc);
|
||||
AstNode* ast_make_let(void* alloc, const char* name, TypeKind annot_type, bool has_type_annot,
|
||||
bool is_mut, AstNode* init, const char* struct_type_name,
|
||||
|
||||
Reference in New Issue
Block a user