condtional multi-unwrap and guard clauses

This commit is contained in:
2026-06-22 20:37:37 +02:00
parent 27f42dd253
commit 663f4dc658
9 changed files with 567 additions and 96 deletions
+8 -3
View File
@@ -136,14 +136,18 @@ Stmt :: struct {
pointer_capture: bool,
target: Expr_Id,
expr: Expr_Id,
// `If` statements use `expr` as the condition, `body` as the then-block, and
// `else_body` as the else-block. An `else if` chain is represented as an
// `else_body` holding a single nested `If` statement.
// `If` statements use `expr` as the condition, `captures` as optional
// unwrap binding names, `guard` as the optional post-unwrap boolean
// condition, `body` as the then-block, and `else_body` as the else-block.
// An `else if` chain is represented as an `else_body` holding a single
// nested `If` statement.
// `While` statements use `expr` as the condition, `body` as the loop body,
// and `update` as the optional post-iteration statement.
// `For` statements use `expr` as the iterable, `name` as the item capture,
// `index_name` as the optional index capture, and `pointer_capture` to
// distinguish `|@item|` from copy capture.
captures: []symbol.Id,
guard: Expr_Id,
body: []Stmt_Id,
else_body: []Stmt_Id,
update: Stmt_Id,
@@ -263,6 +267,7 @@ destroy_module :: proc(module: ^Module) {
delete(expr.args, module.allocator)
}
for statement in module.statements {
delete(statement.captures, module.allocator)
delete(statement.body, module.allocator)
delete(statement.else_body, module.allocator)
}