diff --git a/bolt/codegen.py b/bolt/codegen.py index 4bd4a79..1e16525 100644 --- a/bolt/codegen.py +++ b/bolt/codegen.py @@ -104,7 +104,9 @@ class Accumulator: header: Dict[str, str] = field(default_factory=dict) root_scope: bool = True - last_condition: str = "_bolt_error_last_condition" + current_siblings: Tuple[AstNode, ...] = () + current_sibling_index: int = 0 + condition_inverse: Optional[str] = None def get_source(self) -> str: """Return the source code.""" @@ -240,7 +242,7 @@ def function(self, name: str, *args: str, return_type: str = ""): self.root_scope = previous_root @contextmanager - def if_statement(self, condition: str): + def if_statement(self, condition: str, inverse: Optional[str] = None): """Emit if statement.""" branch = self.helper("branch", condition) self.statement(f"with {branch} as _bolt_condition:") @@ -248,14 +250,14 @@ def if_statement(self, condition: str): self.statement(f"if _bolt_condition:") with self.block(): yield - self.last_condition = condition + self.condition_inverse = inverse @contextmanager def else_statement(self): """Emit else statement.""" - negated_value = self.helper("operator_not", self.last_condition) - self.statement(f"{self.last_condition} = {negated_value}") - with self.if_statement(self.last_condition): + if not self.condition_inverse: + raise ValueError("Condition inverse unavailable.") + with self.if_statement(self.condition_inverse): yield def enclose(self, code: str, from_index: int): @@ -362,7 +364,13 @@ def visit_multiple( collector: Optional[ChildrenCollector] = None index = len(acc.lines) + previous_siblings = acc.current_siblings + previous_sibling_index = acc.current_sibling_index + acc.current_siblings = children + for i, child in enumerate(children): + acc.current_sibling_index = i + result = yield child if result is None: continue @@ -378,6 +386,9 @@ def visit_multiple( current_count = i + 1 index = len(acc.lines) + acc.current_siblings = previous_siblings + acc.current_sibling_index = previous_sibling_index + if collector: collector.add_static(*children[current_count:]) return collector.flush() @@ -838,7 +849,19 @@ def if_statement( acc: Accumulator, ) -> Generator[AstNode, Optional[List[str]], Optional[List[str]]]: condition = yield from visit_single(node.arguments[0], required=True) - with acc.if_statement(condition): + inverse = None + + else_index = acc.current_sibling_index + 1 + if ( + else_index < len(acc.current_siblings) + and isinstance(else_node := acc.current_siblings[else_index], AstCommand) + and else_node.identifier == "else:body" + ): + inverse = f"{condition}_inverse" + value = acc.helper("operator_not", condition) + acc.statement(f"{inverse} = {value}", lineno=node.arguments[0]) + + with acc.if_statement(condition, inverse): yield from visit_body(cast(AstRoot, node.arguments[1]), acc) return [] diff --git a/tests/snapshots/bolt__parse_130__1.txt b/tests/snapshots/bolt__parse_130__1.txt index 6e0567d..2920fb6 100644 --- a/tests/snapshots/bolt__parse_130__1.txt +++ b/tests/snapshots/bolt__parse_130__1.txt @@ -1,6 +1,6 @@ -_bolt_lineno = [1], [1] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] +_bolt_lineno = [1, 13], [1, 2] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: @@ -10,11 +10,11 @@ with _bolt_runtime.scope() as _bolt_var2: with _bolt_runtime.push_nesting('execute:commands'): with _bolt_runtime.scope() as _bolt_var1: _bolt_var0 = True + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[10], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[9], arguments=_bolt_helper_children([*_bolt_refs[6:9], _bolt_helper_replace(_bolt_refs[5], arguments=_bolt_helper_children([*_bolt_refs[4:5], _bolt_helper_replace(_bolt_refs[3], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[2], commands=_bolt_helper_children(_bolt_var1))]))]))]))]))) diff --git a/tests/snapshots/bolt__parse_132__1.txt b/tests/snapshots/bolt__parse_132__1.txt index 307ea3d..1c475db 100644 --- a/tests/snapshots/bolt__parse_132__1.txt +++ b/tests/snapshots/bolt__parse_132__1.txt @@ -1,29 +1,29 @@ -_bolt_lineno = [1], [1] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] +_bolt_lineno = [1, 15, 22], [1, 3, 5] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var4: _bolt_var0 = 1 + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var1 = 2 + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_var2 = 3 + _bolt_var2_inverse = _bolt_helper_operator_not(_bolt_var2) with _bolt_helper_branch(_bolt_var2) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[2].commands) - _bolt_var2 = _bolt_helper_operator_not(_bolt_var2) - with _bolt_helper_branch(_bolt_var2) as _bolt_condition: + with _bolt_helper_branch(_bolt_var2_inverse) as _bolt_condition: if _bolt_condition: _bolt_var3 = 4 with _bolt_helper_branch(_bolt_var3) as _bolt_condition: diff --git a/tests/snapshots/bolt__parse_133__1.txt b/tests/snapshots/bolt__parse_133__1.txt index 76557fe..10192b5 100644 --- a/tests/snapshots/bolt__parse_133__1.txt +++ b/tests/snapshots/bolt__parse_133__1.txt @@ -1,29 +1,29 @@ -_bolt_lineno = [1], [1] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] +_bolt_lineno = [1, 15, 22], [1, 3, 5] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var4: _bolt_var0 = 1 + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var1 = 2 + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_var2 = 3 + _bolt_var2_inverse = _bolt_helper_operator_not(_bolt_var2) with _bolt_helper_branch(_bolt_var2) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[2].commands) - _bolt_var2 = _bolt_helper_operator_not(_bolt_var2) - with _bolt_helper_branch(_bolt_var2) as _bolt_condition: + with _bolt_helper_branch(_bolt_var2_inverse) as _bolt_condition: if _bolt_condition: _bolt_var3 = 4 with _bolt_helper_branch(_bolt_var3) as _bolt_condition: diff --git a/tests/snapshots/bolt__parse_134__1.txt b/tests/snapshots/bolt__parse_134__1.txt index 4196e64..a0943bd 100644 --- a/tests/snapshots/bolt__parse_134__1.txt +++ b/tests/snapshots/bolt__parse_134__1.txt @@ -1,36 +1,36 @@ -_bolt_lineno = [1], [1] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] +_bolt_lineno = [1, 15, 22, 29], [1, 3, 5, 7] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var4: _bolt_var0 = 1 + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var1 = 2 + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_var2 = 3 + _bolt_var2_inverse = _bolt_helper_operator_not(_bolt_var2) with _bolt_helper_branch(_bolt_var2) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[2].commands) - _bolt_var2 = _bolt_helper_operator_not(_bolt_var2) - with _bolt_helper_branch(_bolt_var2) as _bolt_condition: + with _bolt_helper_branch(_bolt_var2_inverse) as _bolt_condition: if _bolt_condition: _bolt_var3 = 4 + _bolt_var3_inverse = _bolt_helper_operator_not(_bolt_var3) with _bolt_helper_branch(_bolt_var3) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[3].commands) - _bolt_var3 = _bolt_helper_operator_not(_bolt_var3) - with _bolt_helper_branch(_bolt_var3) as _bolt_condition: + with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[4].commands) _bolt_var5 = _bolt_helper_replace(_bolt_refs[5], commands=_bolt_helper_children(_bolt_var4)) diff --git a/tests/snapshots/bolt__parse_135__1.txt b/tests/snapshots/bolt__parse_135__1.txt index 8eaf35b..16d597e 100644 --- a/tests/snapshots/bolt__parse_135__1.txt +++ b/tests/snapshots/bolt__parse_135__1.txt @@ -1,36 +1,36 @@ -_bolt_lineno = [1], [1] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] +_bolt_lineno = [1, 15, 22, 29], [1, 3, 5, 7] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var4: _bolt_var0 = 1 + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var1 = 2 + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_var2 = 3 + _bolt_var2_inverse = _bolt_helper_operator_not(_bolt_var2) with _bolt_helper_branch(_bolt_var2) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[2].commands) - _bolt_var2 = _bolt_helper_operator_not(_bolt_var2) - with _bolt_helper_branch(_bolt_var2) as _bolt_condition: + with _bolt_helper_branch(_bolt_var2_inverse) as _bolt_condition: if _bolt_condition: _bolt_var3 = 4 + _bolt_var3_inverse = _bolt_helper_operator_not(_bolt_var3) with _bolt_helper_branch(_bolt_var3) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[3].commands) - _bolt_var3 = _bolt_helper_operator_not(_bolt_var3) - with _bolt_helper_branch(_bolt_var3) as _bolt_condition: + with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[4].commands) _bolt_runtime.commands.append(_bolt_refs[5]) diff --git a/tests/snapshots/bolt__parse_138__1.txt b/tests/snapshots/bolt__parse_138__1.txt index 9d34b89..f589827 100644 --- a/tests/snapshots/bolt__parse_138__1.txt +++ b/tests/snapshots/bolt__parse_138__1.txt @@ -1,7 +1,7 @@ -_bolt_lineno = [1], [1] +_bolt_lineno = [1, 12], [1, 2] +_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] -_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: while True: @@ -9,11 +9,11 @@ with _bolt_runtime.scope() as _bolt_var2: if not _bolt_var0: break _bolt_var1 = 'hello' + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: pass - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: break _bolt_var3 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var2)) diff --git a/tests/snapshots/bolt__parse_139__1.txt b/tests/snapshots/bolt__parse_139__1.txt index e414aa3..1a9becb 100644 --- a/tests/snapshots/bolt__parse_139__1.txt +++ b/tests/snapshots/bolt__parse_139__1.txt @@ -1,11 +1,11 @@ -_bolt_lineno = [1, 15, 20, 27, 40], [1, 2, 3, 4, 6] +_bolt_lineno = [1, 15, 20, 28, 40], [1, 2, 3, 4, 6] _bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] _bolt_helper_interpolate_resource_location = _bolt_runtime.helpers['interpolate_resource_location'] _bolt_helper_children = _bolt_runtime.helpers['children'] +_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_interpolate_range = _bolt_runtime.helpers['interpolate_range'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] -_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_interpolate_message = _bolt_runtime.helpers['interpolate_message'] with _bolt_runtime.scope() as _bolt_var10: _bolt_var0 = generate_tree @@ -21,6 +21,7 @@ with _bolt_runtime.scope() as _bolt_var10: _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'partition') _bolt_var4 = 5 _bolt_var3 = _bolt_var3(_bolt_var4) + _bolt_var3_inverse = _bolt_helper_operator_not(_bolt_var3) with _bolt_helper_branch(_bolt_var3) as _bolt_condition: if _bolt_condition: with _bolt_runtime.push_nesting('execute:subcommand'): @@ -33,8 +34,7 @@ with _bolt_runtime.scope() as _bolt_var10: _bolt_var6 = _bolt_helper_get_attribute(_bolt_var6, 'children') _bolt_var6 = _bolt_helper_interpolate_resource_location(_bolt_var6, _bolt_refs[4]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[8], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[7], arguments=_bolt_helper_children([*_bolt_helper_children([_bolt_refs[2], _bolt_refs[3], _bolt_var5]), _bolt_helper_replace(_bolt_refs[6], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[5], arguments=_bolt_helper_children([_bolt_var6]))]))]))]))) - _bolt_var3 = _bolt_helper_operator_not(_bolt_var3) - with _bolt_helper_branch(_bolt_var3) as _bolt_condition: + with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: if _bolt_condition: with _bolt_runtime.push_nesting('execute:subcommand'): _bolt_var7 = node diff --git a/tests/snapshots/bolt__parse_193__1.txt b/tests/snapshots/bolt__parse_193__1.txt index aa79a35..809fd75 100644 --- a/tests/snapshots/bolt__parse_193__1.txt +++ b/tests/snapshots/bolt__parse_193__1.txt @@ -1,10 +1,10 @@ -_bolt_lineno = [1, 12, 16, 22, 32, 38, 40, 50, 55, 60, 64, 69, 73], [1, 2, 5, 6, 8, 9, 11, 13, 14, 15, 17, 18, 19] +_bolt_lineno = [1, 12, 16, 23, 32, 38, 40, 50, 55, 60, 64, 69, 73], [1, 2, 5, 6, 8, 9, 11, 13, 14, 15, 17, 18, 19] _bolt_helper_children = _bolt_runtime.helpers['children'] +_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] _bolt_helper_interpolate_entity = _bolt_runtime.helpers['interpolate_entity'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] -_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_interpolate_numeric = _bolt_runtime.helpers['interpolate_numeric'] _bolt_helper_get_rebind = _bolt_runtime.helpers['get_rebind'] with _bolt_runtime.scope() as _bolt_var16: @@ -17,6 +17,7 @@ with _bolt_runtime.scope() as _bolt_var16: _bolt_var1 = rhs _bolt_var2 = GlobalScore _bolt_var0 = _bolt_var0(_bolt_var1, _bolt_var2) + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_var3 = self @@ -26,8 +27,7 @@ with _bolt_runtime.scope() as _bolt_var16: _bolt_var4 = _bolt_helper_get_attribute(_bolt_var4, 'name') _bolt_var4 = _bolt_helper_interpolate_entity(_bolt_var4, _bolt_refs[1]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[5], arguments=_bolt_helper_children([_bolt_var3, _bolt_refs[2], _bolt_refs[3], _bolt_var4, _bolt_refs[4]]))) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var5 = self _bolt_var5 = _bolt_helper_get_attribute(_bolt_var5, 'name') diff --git a/tests/snapshots/bolt__parse_196__1.txt b/tests/snapshots/bolt__parse_196__1.txt index bf8ed69..a08afaf 100644 --- a/tests/snapshots/bolt__parse_196__1.txt +++ b/tests/snapshots/bolt__parse_196__1.txt @@ -1,17 +1,17 @@ -_bolt_lineno = [1, 8, 12, 17, 18], [1, 2, 3, 5, 6] +_bolt_lineno = [1, 8, 13, 17, 18], [1, 2, 3, 5, 6] +_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_children = _bolt_runtime.helpers['children'] -_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: def foo(value): _bolt_var0 = value + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_var1 = 1 result = _bolt_var1 - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var2 = 0 result = _bolt_var2 diff --git a/tests/snapshots/bolt__parse_197__1.txt b/tests/snapshots/bolt__parse_197__1.txt index 76ddff7..1903387 100644 --- a/tests/snapshots/bolt__parse_197__1.txt +++ b/tests/snapshots/bolt__parse_197__1.txt @@ -1,14 +1,15 @@ -_bolt_lineno = [1, 10, 11, 15, 23, 27], [1, 2, 3, 4, 6, 7] +_bolt_lineno = [1, 10, 11, 16, 23, 27], [1, 2, 3, 4, 6, 7] +_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_get_rebind = _bolt_runtime.helpers['get_rebind'] _bolt_helper_children = _bolt_runtime.helpers['children'] -_bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: def foo(value): _bolt_var0 = 'init' result = _bolt_var0 _bolt_var1 = value + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_var2 = 1 @@ -16,8 +17,7 @@ with _bolt_runtime.scope() as _bolt_var0: result = _bolt_var2 if _bolt_rebind is not None: result = _bolt_rebind(result) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_var3 = 0 _bolt_rebind = _bolt_helper_get_rebind(result) diff --git a/tests/snapshots/bolt__parse_35__1.txt b/tests/snapshots/bolt__parse_35__1.txt index 37751f3..90d99b9 100644 --- a/tests/snapshots/bolt__parse_35__1.txt +++ b/tests/snapshots/bolt__parse_35__1.txt @@ -1,17 +1,17 @@ _bolt_lineno = [1, 17], [1, 3] -_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_operator_not = _bolt_runtime.helpers['operator_not'] +_bolt_helper_branch = _bolt_runtime.helpers['branch'] _bolt_helper_get_dup = _bolt_runtime.helpers['get_dup'] _bolt_helper_get_rebind = _bolt_runtime.helpers['get_rebind'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var5: _bolt_var0 = True + _bolt_var0_inverse = _bolt_helper_operator_not(_bolt_var0) with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[0].commands) - _bolt_var0 = _bolt_helper_operator_not(_bolt_var0) - with _bolt_helper_branch(_bolt_var0) as _bolt_condition: + with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: if _bolt_condition: _bolt_var1 = True _bolt_var2 = _bolt_helper_operator_not(_bolt_var1) @@ -28,11 +28,11 @@ with _bolt_runtime.scope() as _bolt_var5: _bolt_var1 = _bolt_rebind(_bolt_var1) else: _bolt_var1 = _bolt_var4 + _bolt_var1_inverse = _bolt_helper_operator_not(_bolt_var1) with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - _bolt_var1 = _bolt_helper_operator_not(_bolt_var1) - with _bolt_helper_branch(_bolt_var1) as _bolt_condition: + with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[2].commands) _bolt_var6 = _bolt_helper_replace(_bolt_refs[3], commands=_bolt_helper_children(_bolt_var5))