From d3cada5bd6dec9342909a4d1638c352b098a1007 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 4 Aug 2018 23:46:46 +0100 Subject: [PATCH] Change rules for how `context` and `defer` interact --- src/ir.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 535dcc73f..c59be047f 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -92,6 +92,7 @@ enum irDeferKind { struct irDefer { irDeferKind kind; isize scope_index; + isize context_stack_count; irBlock * block; union { Ast *stmt; @@ -115,7 +116,7 @@ struct irDebugLocation { struct irContextData { irValue *value; - i32 scope_index; + isize scope_index; }; struct irProcedure { @@ -1264,6 +1265,7 @@ void ir_start_block(irProcedure *proc, irBlock *block) { irDefer ir_add_defer_node(irProcedure *proc, isize scope_index, Ast *stmt) { irDefer d = {irDefer_Node}; d.scope_index = scope_index; + d.context_stack_count = proc->context_stack.count; d.block = proc->curr_block; d.stmt = stmt; array_add(&proc->defer_stmts, d); @@ -1750,6 +1752,10 @@ void ir_emit_defer_stmts(irProcedure *proc, irDeferExitKind kind, irBlock *block isize i = count; while (i --> 0) { irDefer d = proc->defer_stmts[i]; + if (d.context_stack_count >= 0) { + proc->context_stack.count = d.context_stack_count; + } + if (kind == irDeferExit_Default) { if (proc->scope_index == d.scope_index && d.scope_index > 0) { // TODO(bill): Which is correct: > 0 or > 1?