condtional multi-unwrap and guard clauses
This commit is contained in:
+12
-2
@@ -134,6 +134,11 @@ Local :: struct {
|
||||
parameter: bool,
|
||||
}
|
||||
|
||||
Conditional_Unwrap :: struct {
|
||||
expr: Expr_Id,
|
||||
local: Local_Id,
|
||||
}
|
||||
|
||||
Stmt_Kind :: enum u8 {
|
||||
Declaration,
|
||||
Assignment,
|
||||
@@ -155,13 +160,17 @@ Stmt :: struct {
|
||||
expr: Expr_Id,
|
||||
iterator_type: types.Type,
|
||||
pointer_capture: bool,
|
||||
// `If` statements use `expr` as the condition and `then_body`/`else_body` as
|
||||
// the branch statement lists.
|
||||
// Boolean `If` statements use `expr` as the condition. Conditional unwraps
|
||||
// use `unwraps` for the ordered optional expressions and capture locals, and
|
||||
// `guard` for the optional boolean checked after every unwrap succeeds.
|
||||
// Both forms use `then_body`/`else_body` as the branch statement lists.
|
||||
// `While` statements use `expr` as the condition, `then_body` as the loop
|
||||
// body, and `update` as the optional post-iteration statement.
|
||||
// `For` statements use `expr` as the iterable, `local` as the item capture,
|
||||
// `index_local` as the optional sequence index, and `iterator_type` as the
|
||||
// normalized many-item pointer type for sequence iteration.
|
||||
unwraps: []Conditional_Unwrap,
|
||||
guard: Expr_Id,
|
||||
then_body: []Stmt_Id,
|
||||
else_body: []Stmt_Id,
|
||||
update: Stmt_Id,
|
||||
@@ -232,6 +241,7 @@ destroy_module :: proc(module: ^Module) {
|
||||
delete(expr.args, module.allocator)
|
||||
}
|
||||
for statement in module.statements {
|
||||
delete(statement.unwraps, module.allocator)
|
||||
delete(statement.then_body, module.allocator)
|
||||
delete(statement.else_body, module.allocator)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user