feat: let mut + 赋值语句 — while 循环可修改变量
- lexer: 新增 TOK_MUT 关键字 - ast: AST_ASSIGN_STMT 节点 + let_stmt.is_mut 标志 - parser: ‘let mut’ 前缀识别 + ‘ident = expr;’ 赋值语句 - sema: Symbol.is_mut 可变性检查(不可变变量赋值报错) - codegen: AST_ASSIGN_STMT → store 指令 - 新增集成测试 06_mut_while.l(while 循环 + 计数器) 基于 Codex 分析报告 P0 建议。
This commit is contained in:
+8
-2
@@ -35,10 +35,16 @@ AstNode* ast_make_block(void* alloc, AstNode** stmts, size_t count, int line, in
|
||||
return n;
|
||||
}
|
||||
|
||||
AstNode* ast_make_let(void* alloc, const char* name, TypeKind annot_type, bool has_type_annot, AstNode* init, int line, int col) {
|
||||
AstNode* ast_make_let(void* alloc, const char* name, TypeKind annot_type, bool has_type_annot, bool is_mut, AstNode* init, int line, int col) {
|
||||
NEW(alloc, AST_LET_STMT);
|
||||
n->as.let_stmt.name = name; n->as.let_stmt.annot_type = annot_type;
|
||||
n->as.let_stmt.has_type_annot = has_type_annot; n->as.let_stmt.init = init;
|
||||
n->as.let_stmt.has_type_annot = has_type_annot; n->as.let_stmt.is_mut = is_mut; n->as.let_stmt.init = init;
|
||||
return n;
|
||||
}
|
||||
|
||||
AstNode* ast_make_assign(void* alloc, const char* name, AstNode* value, int line, int col) {
|
||||
NEW(alloc, AST_ASSIGN_STMT);
|
||||
n->as.assign_stmt.name = name; n->as.assign_stmt.value = value;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user