feat: defer 延迟执行 — defer { stmts; } 在 return 前按 LIFO 执行

Token(73): +TOK_DEFER, AST(28): +AST_DEFER_STMT, 新增 38_defer.l
parser: defer { ... } 块 + defer expr; 表达式两种形式
codegen: defer 栈压入 block, emit_deferred() 在 return 前 LIFO 发射

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 13:51:10 +08:00
parent e60021b684
commit 0088347576
10 changed files with 62 additions and 6 deletions
+6
View File
@@ -103,6 +103,12 @@ AstNode* ast_make_expr_stmt(void* alloc, AstNode* expr, SourceLoc loc) {
return n;
}
AstNode* ast_make_defer_stmt(void* alloc, AstNode* body, SourceLoc loc) {
NEW(alloc, AST_DEFER_STMT);
n->as.defer_stmt.body = body;
return n;
}
AstNode* ast_make_binary(void* alloc, BinaryOp op, AstNode* left, AstNode* right, SourceLoc loc) {
NEW(alloc, AST_BINARY_EXPR);
n->as.binary.op = op; n->as.binary.left = left; n->as.binary.right = right;