aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-04 23:46:46 +0100
committergingerBill <bill@gingerbill.org>2018-08-04 23:46:46 +0100
commitd3cada5bd6dec9342909a4d1638c352b098a1007 (patch)
tree53d140fd09bffddeba59259266ac4a3263584cd4
parentcdbf831a7a6d9bc36e3cf76d525c44af88dc0a53 (diff)
Change rules for how `context` and `defer` interact
-rw-r--r--src/ir.cpp8
1 files changed, 7 insertions, 1 deletions
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?