From 4c5feff79456f3b18a1cb91cb652a123762cf32b Mon Sep 17 00:00:00 2001 From: StunxFS Date: Sat, 11 Nov 2023 20:57:04 -0400 Subject: [PATCH] Revert "Revert "fix(rivetc): fix inappropriate behavior of `defer` with `break`"" This reverts commit 2301950ba88021c0f5687a8ded9073eb7f448a3e. --- lib/rivet/src/ast/Stmt.ri | 2 +- rivetc/src/ast.py | 3 +-- rivetc/src/codegen/__init__.py | 1 - rivetc/src/parser.py | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/rivet/src/ast/Stmt.ri b/lib/rivet/src/ast/Stmt.ri index 14b135595..82da86a67 100644 --- a/lib/rivet/src/ast/Stmt.ri +++ b/lib/rivet/src/ast/Stmt.ri @@ -33,7 +33,7 @@ public enum Stmt { pos: token.Pos; }, Defer { - public enum Mode { + public enum Mode as uint8 { Normal, Error, Success diff --git a/rivetc/src/ast.py b/rivetc/src/ast.py index e70d90318..07f5a0b90 100644 --- a/rivetc/src/ast.py +++ b/rivetc/src/ast.py @@ -816,11 +816,10 @@ def __str__(self): return self.__repr__() class BranchExpr: - def __init__(self, op, pos, scope = None): + def __init__(self, op, pos): self.op = op self.pos = pos self.typ = None - self.scope = scope def __repr__(self): return str(self.op) diff --git a/rivetc/src/codegen/__init__.py b/rivetc/src/codegen/__init__.py index e3510a75f..d7a26dd50 100644 --- a/rivetc/src/codegen/__init__.py +++ b/rivetc/src/codegen/__init__.py @@ -2330,7 +2330,6 @@ def gen_expr(self, expr, custom_tmp = None): self.gen_expr(self.while_continue_expr) self.cur_fn.add_br(self.loop_entry_label) else: - self.gen_defer_stmts(scope = expr.scope) self.cur_fn.add_br(self.loop_exit_label) return ir.Skip() elif isinstance(expr, ast.ReturnExpr): diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index 869a9da40..e971a3122 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -827,7 +827,7 @@ def parse_primary_expr(self): op = self.tok.kind pos = self.tok.pos self.next() - expr = ast.BranchExpr(op, pos, self.scope) + expr = ast.BranchExpr(op, pos) elif self.accept(Kind.KwReturn): pos = self.prev_tok.pos has_expr = self.tok.kind not in (