From d93140a587eb504bf99a3a5dac44dd7694edec70 Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Fri, 23 Feb 2024 02:07:44 +0100 Subject: [PATCH] feat: fuse with statements across if statements --- bolt/codegen.py | 66 +++++---- tests/snapshots/bolt__parse_132__1.txt | 24 +-- tests/snapshots/bolt__parse_133__1.txt | 30 ++-- tests/snapshots/bolt__parse_134__1.txt | 30 ++-- tests/snapshots/bolt__parse_135__1.txt | 36 ++--- tests/snapshots/bolt__parse_35__1.txt | 6 +- ...o_many_statically_nested_blocks__0.pack.md | 139 +++++++++--------- 7 files changed, 171 insertions(+), 160 deletions(-) diff --git a/bolt/codegen.py b/bolt/codegen.py index e2d0147..aca7c3a 100644 --- a/bolt/codegen.py +++ b/bolt/codegen.py @@ -277,7 +277,7 @@ def if_statement( branch = self.helper("branch", condition) self.statement("with", branch, "as", "_bolt_condition", lineno=lineno) with self.block(): - self.statement(f"if _bolt_condition") + self.statement("if", "_bolt_condition") with self.block(): yield self.condition_inverse = inverse @@ -304,7 +304,7 @@ def dup(self, target: str, *, lineno: Any = None) -> str: dup = self.make_variable() value = self.helper("get_dup", target) self.statement(f"{dup} = {value}", lineno=lineno) - self.statement(f"if {dup} is not None") + self.statement("if", f"{dup} is not None") with self.block(): self.statement(f"{target} = {dup}()") return dup @@ -314,13 +314,13 @@ def rebind(self, target: str, op: str, value: str, *, lineno: Any = None): rebind = self.helper("get_rebind", target) self.statement(f"_bolt_rebind = {rebind}", lineno=lineno) self.statement(f"{target} {op} {value}") - self.statement(f"if _bolt_rebind is not None") + self.statement("if", "_bolt_rebind is not None") with self.block(): self.statement(f"{target} = _bolt_rebind({target})") def rebind_dup(self, target: str, dup: str, value: str, *, lineno: Any = None): """Emit __rebind__() if target was __dup__().""" - self.statement(f"if {dup} is not None") + self.statement("if", f"{dup} is not None") with self.block(): self.rebind(target, "=", value, lineno=lineno) self.statement("else") @@ -345,7 +345,9 @@ class WithStatementFusion: @classmethod def finalize(cls, acc: Accumulator): with_statement_fusion = cls() - acc.statements = [with_statement_fusion.fuse(statement, acc) for statement in acc.statements] + acc.statements = [ + with_statement_fusion.fuse(statement, acc) for statement in acc.statements + ] def convert(self, statement: CodegenStatement, exit_stack: str) -> CodegenStatement: code = (f"{exit_stack}.enter_context({statement.code[1]})",) @@ -356,29 +358,31 @@ def convert(self, statement: CodegenStatement, exit_stack: str) -> CodegenStatem def fuse(self, statement: CodegenStatement, acc: Accumulator) -> CodegenStatement: children = [self.fuse(child, acc) for child in statement.children] - if statement.code[0] == "with" and children[-1].code[0] == "with": - nested_statement = children.pop() + if statement.code[0] != "with": + return replace(statement, children=children) - if nested_statement.code[1] == acc.helper("exit_stack"): - exit_stack = nested_statement.code[3] - code = nested_statement.code - else: - exit_stack = f"_bolt_fused_with_statement{self.counter}" - self.counter += 1 - code = ("with", acc.helper("exit_stack"), "as", exit_stack) - children.append(self.convert(nested_statement, exit_stack)) - - return replace( - statement, - code=code, - children=[ - self.convert(statement, exit_stack), - *children, - *nested_statement.children, - ], - ) + nested_children = children + while nested_children[-1].code[0] == "if": + nested_children = nested_children[-1].children + + if nested_children[-1].code[0] != "with": + return replace(statement, children=children) + + nested_statement = nested_children.pop() - return replace(statement, children=children) + if nested_statement.code[1] == acc.helper("exit_stack"): + exit_stack = nested_statement.code[3] + code = nested_statement.code + else: + exit_stack = f"_bolt_fused_with_statement{self.counter}" + self.counter += 1 + code = ("with", acc.helper("exit_stack"), "as", exit_stack) + nested_children.append(self.convert(nested_statement, exit_stack)) + + children.insert(0, self.convert(statement, exit_stack)) + nested_children.extend(nested_statement.children) + + return replace(statement, code=code, children=children) @dataclass @@ -711,7 +715,7 @@ def memo( acc.header[storage] = "None" if not acc.root_scope: acc.statement(f"global {storage}", lineno=node) - acc.statement(f"if {storage} is None") + acc.statement("if", f"{storage} is None") with acc.block(): acc.statement( f"{storage} = _bolt_runtime.memo.registry[__file__][{acc.make_ref(node)}, {file_index}]" @@ -723,7 +727,7 @@ def memo( invocation = f"_bolt_memo_invocation_{node.persistent_id.hex}" acc.statement(f"{invocation} = {storage}[({path}, {' '.join(keys)})]") - acc.statement(f"if {invocation}.cached") + acc.statement("if", f"{invocation}.cached") with acc.block(): acc.statement(f"_bolt_runtime.memo.restore(_bolt_runtime, {invocation})") if cached_identifiers: @@ -798,7 +802,7 @@ def function( for arg in signature.arguments: if isinstance(arg, AstFunctionSignatureArgument) and arg.default: - acc.statement(f"if {arg.name} is {acc.missing()}") + acc.statement("if", f"{arg.name} is {acc.missing()}") with acc.block(): value = yield from visit_single(arg.default, required=True) acc.statement(f"{arg.name} = {value}") @@ -1023,7 +1027,9 @@ def while_statement( with acc.block(): acc.statement("_bolt_runtime.commands.extend(_bolt_condition_commands)") - acc.statement("if not _bolt_loop_overridden", lineno=node.arguments[0]) + acc.statement( + "if", "not _bolt_loop_overridden", lineno=node.arguments[0] + ) with acc.block(): acc.statement(f"{condition} = bool({condition})") diff --git a/tests/snapshots/bolt__parse_132__1.txt b/tests/snapshots/bolt__parse_132__1.txt index d6566ec..71a71e4 100644 --- a/tests/snapshots/bolt__parse_132__1.txt +++ b/tests/snapshots/bolt__parse_132__1.txt @@ -18,19 +18,19 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var1_inverse)) + 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_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var2_inverse)) 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) - 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: - if _bolt_condition: - _bolt_runtime.commands.extend(_bolt_refs[3].commands) + _bolt_var3 = 4 + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var3)) + if _bolt_condition: + _bolt_runtime.commands.extend(_bolt_refs[3].commands) _bolt_var5 = _bolt_helper_replace(_bolt_refs[4], commands=_bolt_helper_children(_bolt_var4)) --- output = _bolt_var5 diff --git a/tests/snapshots/bolt__parse_133__1.txt b/tests/snapshots/bolt__parse_133__1.txt index 5171212..28274bf 100644 --- a/tests/snapshots/bolt__parse_133__1.txt +++ b/tests/snapshots/bolt__parse_133__1.txt @@ -1,34 +1,36 @@ -_bolt_lineno = [1, 12, 19, 26], [1, 3, 5, 7] +_bolt_lineno = [1, 13, 21, 28], [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'] +_bolt_helper_exit_stack = _bolt_runtime.helpers['exit_stack'] 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) - with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: + with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var0_inverse)) 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) - with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var1_inverse)) + 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_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var2_inverse)) 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) - 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: - if _bolt_condition: - _bolt_runtime.commands.extend(_bolt_refs[3].commands) + _bolt_var3 = 4 + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var3)) + if _bolt_condition: + _bolt_runtime.commands.extend(_bolt_refs[3].commands) _bolt_runtime.commands.append(_bolt_refs[4]) _bolt_var5 = _bolt_helper_replace(_bolt_refs[5], commands=_bolt_helper_children(_bolt_var4)) --- diff --git a/tests/snapshots/bolt__parse_134__1.txt b/tests/snapshots/bolt__parse_134__1.txt index 5ba1fff..29433c1 100644 --- a/tests/snapshots/bolt__parse_134__1.txt +++ b/tests/snapshots/bolt__parse_134__1.txt @@ -18,23 +18,23 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var1_inverse)) + 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_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var2_inverse)) 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) - with _bolt_helper_branch(_bolt_var2_inverse) as _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_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) - with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: - if _bolt_condition: - _bolt_runtime.commands.extend(_bolt_refs[4].commands) + _bolt_runtime.commands.extend(_bolt_refs[3].commands) + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var3_inverse)) + 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)) --- output = _bolt_var5 diff --git a/tests/snapshots/bolt__parse_135__1.txt b/tests/snapshots/bolt__parse_135__1.txt index c647694..3868794 100644 --- a/tests/snapshots/bolt__parse_135__1.txt +++ b/tests/snapshots/bolt__parse_135__1.txt @@ -1,38 +1,40 @@ -_bolt_lineno = [1, 12, 19, 26, 33], [1, 3, 5, 7, 9] +_bolt_lineno = [1, 13, 21, 28, 35], [1, 3, 5, 7, 9] _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'] +_bolt_helper_exit_stack = _bolt_runtime.helpers['exit_stack'] 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) - with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: + with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var0_inverse)) 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) - with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var1_inverse)) + 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_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var2_inverse)) if _bolt_condition: - _bolt_var2 = 3 - _bolt_var2_inverse = _bolt_helper_operator_not(_bolt_var2) - with _bolt_helper_branch(_bolt_var2) as _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[2].commands) - 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) - with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: - if _bolt_condition: - _bolt_runtime.commands.extend(_bolt_refs[4].commands) + _bolt_runtime.commands.extend(_bolt_refs[3].commands) + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var3_inverse)) + if _bolt_condition: + _bolt_runtime.commands.extend(_bolt_refs[4].commands) _bolt_runtime.commands.append(_bolt_refs[5]) _bolt_var5 = _bolt_helper_replace(_bolt_refs[6], commands=_bolt_helper_children(_bolt_var4)) --- diff --git a/tests/snapshots/bolt__parse_35__1.txt b/tests/snapshots/bolt__parse_35__1.txt index 9c43b88..0afa4cb 100644 --- a/tests/snapshots/bolt__parse_35__1.txt +++ b/tests/snapshots/bolt__parse_35__1.txt @@ -34,9 +34,9 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: with _bolt_helper_branch(_bolt_var1) as _bolt_condition: if _bolt_condition: _bolt_runtime.commands.extend(_bolt_refs[1].commands) - with _bolt_helper_branch(_bolt_var1_inverse) as _bolt_condition: - if _bolt_condition: - _bolt_runtime.commands.extend(_bolt_refs[2].commands) + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var1_inverse)) + 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)) --- output = _bolt_var6 diff --git a/tests/snapshots/examples__build_bolt_too_many_statically_nested_blocks__0.pack.md b/tests/snapshots/examples__build_bolt_too_many_statically_nested_blocks__0.pack.md index 3cd7df1..616d91f 100644 --- a/tests/snapshots/examples__build_bolt_too_many_statically_nested_blocks__0.pack.md +++ b/tests/snapshots/examples__build_bolt_too_many_statically_nested_blocks__0.pack.md @@ -18,7 +18,7 @@ `@function demo:foo` ```mcfunction -_bolt_lineno = [1, 15, 16, 17, 18, 23, 40, 48, 58, 68, 79, 85, 99, 106, 113, 126, 129, 135, 140, 149, 166, 174, 191, 197], [1, 3, 4, 5, 6, 29, 32, 34, 36, 38, 42, 45, 52, 53, 54, 67, 68, 72, 73, 74, 75, 79, 87, 88] +_bolt_lineno = [1, 15, 16, 17, 18, 23, 40, 48, 59, 69, 80, 86, 100, 107, 114, 127, 130, 136, 141, 150, 167, 175, 192, 198], [1, 3, 4, 5, 6, 29, 32, 34, 36, 38, 42, 45, 52, 53, 54, 67, 68, 72, 73, 74, 75, 79, 87, 88] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] _bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] @@ -30,8 +30,8 @@ _bolt_helper_interpolate_numeric = _bolt_runtime.helpers['interpolate_numeric'] _bolt_helper_interpolate_resource_location = _bolt_runtime.helpers['interpolate_resource_location'] _bolt_helper_interpolate_item_slot = _bolt_runtime.helpers['interpolate_item_slot'] _bolt_helper_exit_stack = _bolt_runtime.helpers['exit_stack'] -with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: - _bolt_var37 = _bolt_fused_with_statement8.enter_context(_bolt_runtime.scope()) +with _bolt_helper_exit_stack() as _bolt_fused_with_statement9: + _bolt_var37 = _bolt_fused_with_statement9.enter_context(_bolt_runtime.scope()) onEvent = _bolt_runtime.from_module_import('coc:modules/on', 'onEvent') PlayerDB = _bolt_runtime.from_module_import('coc:modules/playerdb', 'PlayerDB') ClassRegistry = _bolt_runtime.from_module_import('coc:modules/armory', 'ClassRegistry') @@ -65,7 +65,8 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: if _bolt_condition: _bolt_var2 = 'netherite_boots' return _bolt_var2 - with _bolt_helper_branch(_bolt_var0_inverse) as _bolt_condition: + with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var0_inverse)) if _bolt_condition: _bolt_var3 = slot _bolt_var4 = 101 @@ -75,32 +76,32 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: if _bolt_condition: _bolt_var5 = 'netherite_leggings' return _bolt_var5 - with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var3_inverse)) + if _bolt_condition: + _bolt_var6 = slot + _bolt_var7 = 102 + _bolt_var6 = _bolt_var6 == _bolt_var7 + _bolt_var6_inverse = _bolt_helper_operator_not(_bolt_var6) + with _bolt_helper_branch(_bolt_var6) as _bolt_condition: + if _bolt_condition: + _bolt_var8 = 'netherite_chestplate' + return _bolt_var8 + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var6_inverse)) if _bolt_condition: - _bolt_var6 = slot - _bolt_var7 = 102 - _bolt_var6 = _bolt_var6 == _bolt_var7 - _bolt_var6_inverse = _bolt_helper_operator_not(_bolt_var6) - with _bolt_helper_branch(_bolt_var6) as _bolt_condition: - if _bolt_condition: - _bolt_var8 = 'netherite_chestplate' - return _bolt_var8 - with _bolt_helper_branch(_bolt_var6_inverse) as _bolt_condition: - if _bolt_condition: - _bolt_var9 = slot - _bolt_var10 = 103 - _bolt_var9 = _bolt_var9 == _bolt_var10 - with _bolt_helper_branch(_bolt_var9) as _bolt_condition: - if _bolt_condition: - _bolt_var11 = 'netherite_helmet' - return _bolt_var11 + _bolt_var9 = slot + _bolt_var10 = 103 + _bolt_var9 = _bolt_var9 == _bolt_var10 + _bolt_condition = _bolt_fused_with_statement0.enter_context(_bolt_helper_branch(_bolt_var9)) + if _bolt_condition: + _bolt_var11 = 'netherite_helmet' + return _bolt_var11 _bolt_var12 = 'air' return _bolt_var12 _bolt_var0 = onEvent _bolt_var1 = 'inventory_changed' _bolt_var2 = 'demo:armory/detect' _bolt_var0 = _bolt_var0(_bolt_var1, _bolt_var2) - _bolt_fused_with_statement8.enter_context(_bolt_var0) + _bolt_fused_with_statement9.enter_context(_bolt_var0) _bolt_runtime.commands.append(_bolt_refs[1]) _bolt_var3 = PlayerDB _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["get"] @@ -109,39 +110,39 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["armory"] armory_data = _bolt_var3 _bolt_runtime.commands.append(_bolt_refs[130]) - with _bolt_helper_exit_stack() as _bolt_fused_with_statement7: - _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) - _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[125:128])) - _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) - _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[122:123])) - _bolt_var36 = _bolt_fused_with_statement7.enter_context(_bolt_runtime.scope()) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: + _bolt_fused_with_statement8.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement8.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[125:128])) + _bolt_fused_with_statement8.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement8.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[122:123])) + _bolt_var36 = _bolt_fused_with_statement8.enter_context(_bolt_runtime.scope()) _bolt_runtime.commands.extend(_bolt_refs[22:24]) _bolt_var4 = range _bolt_var5 = 9 _bolt_var4 = _bolt_var4(_bolt_var5) for slot in _bolt_var4: - with _bolt_helper_exit_stack() as _bolt_fused_with_statement0: - _bolt_fused_with_statement0.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) - _bolt_fused_with_statement0.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[17:20])) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement1: + _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[17:20])) _bolt_var6 = Byte _bolt_var7 = slot _bolt_var6 = _bolt_var6(_bolt_var7) _bolt_var6 = _bolt_helper_interpolate_nbt(_bolt_var6, _bolt_refs[2]) - _bolt_fused_with_statement0.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[9], _bolt_helper_replace(_bolt_refs[8], components=_bolt_helper_children([_bolt_refs[7], _bolt_helper_replace(_bolt_refs[6], index=_bolt_helper_replace(_bolt_refs[5], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[3], value=_bolt_var6), _bolt_refs[4]])))]))]))) - _bolt_fused_with_statement0.enter_context(_bolt_runtime.push_nesting('execute:commands')) - _bolt_var9 = _bolt_fused_with_statement0.enter_context(_bolt_runtime.scope()) + _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[9], _bolt_helper_replace(_bolt_refs[8], components=_bolt_helper_children([_bolt_refs[7], _bolt_helper_replace(_bolt_refs[6], index=_bolt_helper_replace(_bolt_refs[5], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[3], value=_bolt_var6), _bolt_refs[4]])))]))]))) + _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:commands')) + _bolt_var9 = _bolt_fused_with_statement1.enter_context(_bolt_runtime.scope()) _bolt_var8 = slot _bolt_var8 = _bolt_helper_interpolate_numeric(_bolt_var8, _bolt_refs[10]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[13], arguments=_bolt_helper_children([_bolt_refs[11], _bolt_refs[12], _bolt_var8]))) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[21], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[20], arguments=_bolt_helper_children([*_bolt_refs[17:20], _bolt_helper_replace(_bolt_refs[16], arguments=_bolt_helper_children([*_bolt_helper_children([_bolt_refs[9], _bolt_helper_replace(_bolt_refs[8], components=_bolt_helper_children([_bolt_refs[7], _bolt_helper_replace(_bolt_refs[6], index=_bolt_helper_replace(_bolt_refs[5], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[3], value=_bolt_var6), _bolt_refs[4]])))]))]), _bolt_helper_replace(_bolt_refs[15], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[14], commands=_bolt_helper_children(_bolt_var9))]))]))]))]))) _bolt_runtime.commands.append(_bolt_refs[84]) - with _bolt_helper_exit_stack() as _bolt_fused_with_statement3: - _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) - _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:unless:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[79:82])) - _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:unless:data:storage:source:path:subcommand', *_bolt_refs[76:78])) - _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) - _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[73:74])) - _bolt_var27 = _bolt_fused_with_statement3.enter_context(_bolt_runtime.scope()) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement4: + _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:unless:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[79:82])) + _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:unless:data:storage:source:path:subcommand', *_bolt_refs[76:78])) + _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[73:74])) + _bolt_var27 = _bolt_fused_with_statement4.enter_context(_bolt_runtime.scope()) _bolt_runtime.commands.extend(_bolt_refs[32:34]) _bolt_var10 = getReplaceSlots _bolt_var10 = _bolt_var10() @@ -155,23 +156,23 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: _bolt_var13 = getReplaceSlots _bolt_var13 = _bolt_var13() for slotNum, slotId in _bolt_var13: - with _bolt_helper_exit_stack() as _bolt_fused_with_statement2: - _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement3: + _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) _bolt_var14 = Byte _bolt_var15 = slotNum _bolt_var14 = _bolt_var14(_bolt_var15) _bolt_var14 = _bolt_helper_interpolate_nbt(_bolt_var14, _bolt_refs[34]) - _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[40], _bolt_helper_replace(_bolt_refs[39], components=_bolt_helper_children([_bolt_refs[38], _bolt_helper_replace(_bolt_refs[37], index=_bolt_helper_replace(_bolt_refs[36], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[35], value=_bolt_var14)])))]))]))) - _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:commands')) - _bolt_var25 = _bolt_fused_with_statement2.enter_context(_bolt_runtime.scope()) - with _bolt_helper_exit_stack() as _bolt_fused_with_statement1: - _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[40], _bolt_helper_replace(_bolt_refs[39], components=_bolt_helper_children([_bolt_refs[38], _bolt_helper_replace(_bolt_refs[37], index=_bolt_helper_replace(_bolt_refs[36], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[35], value=_bolt_var14)])))]))]))) + _bolt_fused_with_statement3.enter_context(_bolt_runtime.push_nesting('execute:commands')) + _bolt_var25 = _bolt_fused_with_statement3.enter_context(_bolt_runtime.scope()) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement2: + _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) _bolt_var16 = Byte _bolt_var17 = slotNum _bolt_var16 = _bolt_var16(_bolt_var17) _bolt_var16 = _bolt_helper_interpolate_nbt(_bolt_var16, _bolt_refs[41]) - _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:unless:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[48], _bolt_helper_replace(_bolt_refs[47], components=_bolt_helper_children([_bolt_refs[46], _bolt_helper_replace(_bolt_refs[45], index=_bolt_helper_replace(_bolt_refs[44], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[42], value=_bolt_var16), _bolt_refs[43]])))]))]))) - _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:unless:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[48], _bolt_helper_replace(_bolt_refs[47], components=_bolt_helper_children([_bolt_refs[46], _bolt_helper_replace(_bolt_refs[45], index=_bolt_helper_replace(_bolt_refs[44], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[42], value=_bolt_var16), _bolt_refs[43]])))]))]))) + _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) _bolt_var18 = 'demo:armory/equip/replace_' _bolt_var19 = slotId _bolt_var19 = _bolt_helper_get_attribute_handler(_bolt_var19)["split"] @@ -181,8 +182,8 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: _bolt_var19 = _bolt_var19[_bolt_var21] _bolt_var18 = _bolt_var18 + _bolt_var19 _bolt_var18 = _bolt_helper_interpolate_resource_location(_bolt_var18, _bolt_refs[49]) - _bolt_fused_with_statement1.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_helper_children([_bolt_var18]))) - _bolt_var24 = _bolt_fused_with_statement1.enter_context(_bolt_runtime.scope()) + _bolt_fused_with_statement2.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_helper_children([_bolt_var18]))) + _bolt_var24 = _bolt_fused_with_statement2.enter_context(_bolt_runtime.scope()) _bolt_var22 = Byte _bolt_var23 = slotNum _bolt_var22 = _bolt_var22(_bolt_var23) @@ -195,31 +196,31 @@ with _bolt_helper_exit_stack() as _bolt_fused_with_statement8: _bolt_var26 = _bolt_helper_get_attribute_handler(_bolt_var26)["set_gear"] _bolt_var26 = _bolt_var26() _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[83], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[82], arguments=_bolt_helper_children([*_bolt_refs[79:82], _bolt_helper_replace(_bolt_refs[78], arguments=_bolt_helper_children([*_bolt_refs[76:78], _bolt_helper_replace(_bolt_refs[75], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[74], arguments=_bolt_helper_children([*_bolt_refs[73:74], _bolt_helper_replace(_bolt_refs[72], commands=_bolt_helper_children(_bolt_var27))]))]))]))]))]))) - with _bolt_helper_exit_stack() as _bolt_fused_with_statement6: - _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) - _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[116:119])) - _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) - _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[113:114])) - _bolt_var35 = _bolt_fused_with_statement6.enter_context(_bolt_runtime.scope()) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement7: + _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[116:119])) + _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement7.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[113:114])) + _bolt_var35 = _bolt_fused_with_statement7.enter_context(_bolt_runtime.scope()) _bolt_runtime.commands.extend(_bolt_refs[109:112]) - with _bolt_helper_exit_stack() as _bolt_fused_with_statement5: - _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) - _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[104:107])) - _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) - _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[101:102])) - _bolt_var34 = _bolt_fused_with_statement5.enter_context(_bolt_runtime.scope()) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement6: + _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_refs[104:107])) + _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement6.enter_context(_bolt_runtime.push_nesting('function:name:commands', *_bolt_refs[101:102])) + _bolt_var34 = _bolt_fused_with_statement6.enter_context(_bolt_runtime.scope()) _bolt_var28 = range _bolt_var29 = 36 _bolt_var28 = _bolt_var28(_bolt_var29) for i in _bolt_var28: - with _bolt_helper_exit_stack() as _bolt_fused_with_statement4: - _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) + with _bolt_helper_exit_stack() as _bolt_fused_with_statement5: + _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:subcommand')) _bolt_var30 = Byte _bolt_var31 = i _bolt_var30 = _bolt_var30(_bolt_var31) _bolt_var30 = _bolt_helper_interpolate_nbt(_bolt_var30, _bolt_refs[85]) - _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[92], _bolt_helper_replace(_bolt_refs[91], components=_bolt_helper_children([_bolt_refs[90], _bolt_helper_replace(_bolt_refs[89], index=_bolt_helper_replace(_bolt_refs[88], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[86], value=_bolt_var30), _bolt_refs[87]])))]))]))) - _bolt_fused_with_statement4.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) + _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:if:data:storage:source:path:subcommand', *_bolt_helper_children([_bolt_refs[92], _bolt_helper_replace(_bolt_refs[91], components=_bolt_helper_children([_bolt_refs[90], _bolt_helper_replace(_bolt_refs[89], index=_bolt_helper_replace(_bolt_refs[88], entries=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[86], value=_bolt_var30), _bolt_refs[87]])))]))]))) + _bolt_fused_with_statement5.enter_context(_bolt_runtime.push_nesting('execute:run:subcommand')) _bolt_var32 = i _bolt_var33 = 'container.{}'.format(_bolt_var32) _bolt_var33 = _bolt_helper_interpolate_item_slot(_bolt_var33, _bolt_refs[93])