From ed9708942c23448c3e3297e19a48230f827d58ec Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Wed, 6 Dec 2023 23:45:15 +0100 Subject: [PATCH] feat: trigger rebind on set attribute --- bolt/codegen.py | 14 ++-- bolt/contrib/sandbox.py | 34 ++++---- bolt/helpers.py | 50 +++++++++-- .../functions/attribute_rebind.mcfunction | 83 +++++++++++++++++++ tests/snapshots/bolt__parse_126__1.txt | 4 +- tests/snapshots/bolt__parse_127__1.txt | 4 +- tests/snapshots/bolt__parse_139__1.txt | 14 ++-- tests/snapshots/bolt__parse_140__1.txt | 4 +- tests/snapshots/bolt__parse_160__1.txt | 5 +- tests/snapshots/bolt__parse_162__1.txt | 5 +- tests/snapshots/bolt__parse_168__1.txt | 6 +- tests/snapshots/bolt__parse_192__1.txt | 4 +- tests/snapshots/bolt__parse_193__1.txt | 10 +-- tests/snapshots/bolt__parse_194__1.txt | 8 +- tests/snapshots/bolt__parse_207__1.txt | 4 +- tests/snapshots/bolt__parse_208__1.txt | 4 +- tests/snapshots/bolt__parse_209__1.txt | 4 +- tests/snapshots/bolt__parse_211__1.txt | 4 +- tests/snapshots/bolt__parse_245__1.txt | 8 +- tests/snapshots/bolt__parse_251__1.txt | 4 +- tests/snapshots/bolt__parse_255__1.txt | 4 +- tests/snapshots/bolt__parse_259__1.txt | 5 +- tests/snapshots/bolt__parse_275__1.txt | 4 +- tests/snapshots/bolt__parse_278__1.txt | 4 +- tests/snapshots/bolt__parse_65__1.txt | 4 +- tests/snapshots/bolt__parse_66__1.txt | 6 +- tests/snapshots/bolt__parse_67__1.txt | 4 +- tests/snapshots/bolt__parse_68__1.txt | 4 +- .../examples__build_bolt_basic__0.pack.md | 40 +++++++++ 29 files changed, 257 insertions(+), 91 deletions(-) create mode 100644 examples/bolt_basic/src/data/demo/functions/attribute_rebind.mcfunction diff --git a/bolt/codegen.py b/bolt/codegen.py index 335d586..cba409c 100644 --- a/bolt/codegen.py +++ b/bolt/codegen.py @@ -155,9 +155,10 @@ def children(self, nodes: Iterable[str]) -> str: """Emit children helper.""" return self.helper("children", f"[{', '.join(nodes)}]") - def get_attribute(self, obj: str, name: str) -> str: - """Emit get_attribute helper.""" - return self.helper("get_attribute", obj, repr(name)) + def get_attribute_handler(self, obj: str, name: str) -> str: + """Emit get_attribute_handler helper.""" + attribute_handler = self.helper("get_attribute_handler", obj) + return f'{attribute_handler}["{name}"]' def import_module(self, name: str) -> str: """Emit import_module helper.""" @@ -1025,7 +1026,7 @@ def from_import_statement( stmt = f"_bolt_from_import = {acc.import_module(module.path)}" acc.statement(stmt, lineno=node) for name in names: - rhs = acc.get_attribute("_bolt_from_import", name) + rhs = acc.get_attribute_handler("_bolt_from_import", name) acc.statement(f"{name} = {rhs}", lineno=node) return [] @@ -1303,7 +1304,7 @@ def attribute( acc: Accumulator, ) -> Generator[AstNode, Optional[List[str]], Optional[List[str]]]: value = yield from visit_single(node.value, required=True) - rhs = acc.get_attribute(value, node.name) + rhs = acc.get_attribute_handler(value, node.name) acc.statement(f"{value} = {rhs}", lineno=node) return [value] @@ -1389,7 +1390,8 @@ def target_attribute( acc: Accumulator, ) -> Generator[AstNode, Optional[List[str]], Optional[List[str]]]: value = yield from visit_single(node.value, required=True) - return [f"{value}.{node.name}"] + target = acc.get_attribute_handler(value, node.name) + return [target] @rule(AstTargetItem) def target_item( diff --git a/bolt/contrib/sandbox.py b/bolt/contrib/sandbox.py index 91b7237..21d7c18 100644 --- a/bolt/contrib/sandbox.py +++ b/bolt/contrib/sandbox.py @@ -3,7 +3,7 @@ __all__ = [ "Sandbox", - "SandboxedGetAttribute", + "SandboxedAttributeHandler", "SandboxedImportModule", "SecurityError", "public_attrs", @@ -184,11 +184,16 @@ def activate(self): if self.active: return self.active = True + self.runtime.builtins &= self.allowed_builtins + + get_attribute_handler = self.runtime.helpers["get_attribute_handler"] + self.runtime.helpers.update( - get_attribute=SandboxedGetAttribute( + get_attribute_handler=lambda obj: SandboxedAttributeHandler( # type: ignore + obj=obj, + handler=get_attribute_handler(obj), sandbox=self, - get_attribute=self.runtime.helpers["get_attribute"], ), import_module=SandboxedImportModule( sandbox=self, @@ -198,30 +203,31 @@ def activate(self): @dataclass -class SandboxedGetAttribute: - """Sandboxed get_attribute helper.""" +class SandboxedAttributeHandler: + """Sandboxed attribute handler helper.""" + obj: Any + handler: Any sandbox: Sandbox - get_attribute: Callable[[Any, str], Any] @internal - def __call__(self, obj: Any, attr: str) -> Any: - if not hasattr(obj, attr): - return self.get_attribute(obj, attr) + def __getitem__(self, attr: str) -> Any: + if not hasattr(self.obj, attr): + return self.handler[attr] try: - if allowed := self.sandbox.allowed_obj_attrs.get(obj): + if allowed := self.sandbox.allowed_obj_attrs.get(self.obj): if attr in allowed: - return self.get_attribute(obj, attr) + return self.handler[attr] except TypeError: pass - for cls in type.mro(type(obj)): + for cls in type.mro(type(self.obj)): if allowed := self.sandbox.allowed_type_attrs.get(cls): if attr in allowed: - return self.get_attribute(obj, attr) + return self.handler[attr] - raise SecurityError(f"Access forbidden attribute {attr!r} of {type(obj)}.") + raise SecurityError(f"Access forbidden attribute {attr!r} of {type(self.obj)}.") @dataclass diff --git a/bolt/helpers.py b/bolt/helpers.py index 6843a0e..3033572 100644 --- a/bolt/helpers.py +++ b/bolt/helpers.py @@ -62,7 +62,7 @@ def get_bolt_helpers() -> Dict[str, Any]: "branch": BranchDriver, "get_dup": get_dup, "get_rebind": get_rebind, - "get_attribute": get_attribute, + "get_attribute_handler": AttributeHandler, "import_module": python_import_module, "macro_call": macro_call, "resolve_formatted_location": resolve_formatted_location, @@ -166,15 +166,47 @@ def get_rebind(obj: Any): return None -@internal -def get_attribute(obj: Any, attr: str): - try: - return getattr(obj, attr) - except AttributeError as exc: +@dataclass +class AttributeHandler: + obj: Any + item: bool = False + + @internal + def __getitem__(self, attr: str) -> Any: + try: + return getattr(self.obj, attr) + except AttributeError as exc: + try: + result = self.obj[attr] + self.item = True + return result + except (TypeError, LookupError): + raise exc from None + + @internal + def __setitem__(self, attr: str, value: Any): + try: + current = self.__getitem__(attr) + except AttributeError: + pass + else: + if func := getattr(type(current), "__rebind__", None): + value = func(current, value) + if self.item: + self.obj[attr] = value + else: + setattr(self.obj, attr, value) + + @internal + def __delitem__(self, attr: str): try: - return obj[attr] - except (TypeError, LookupError): - raise exc from None + self.__getitem__(attr) + except AttributeError: + pass + if self.item: + del self.obj[attr] + else: + delattr(self.obj, attr) @internal diff --git a/examples/bolt_basic/src/data/demo/functions/attribute_rebind.mcfunction b/examples/bolt_basic/src/data/demo/functions/attribute_rebind.mcfunction new file mode 100644 index 0000000..b1ee022 --- /dev/null +++ b/examples/bolt_basic/src/data/demo/functions/attribute_rebind.mcfunction @@ -0,0 +1,83 @@ +from dataclasses import dataclass + +@dataclass +class Var: + name: str + + def __add__(self, value): + result = Var(f"{self}_plus_{value}") + say f"{result} = {self} + {value}" + return result + + def __rebind__(self, value): + say f"{self.name} = {value}" + return self + + def __str__(self): + return self.name + +foo = Var("foo") +bar = Var("bar") +say f"{foo} {bar}" + +foo = 123 +foo += 456 +foo = bar + 789 +foo += bar + 999 + +del foo +del bar + +foo = 123 +bar = 456 +say f"{foo} {bar}" + +@dataclass +class A: + foo: Var + bar: Var + +a = A(Var("foo"), Var("bar")) +say a + +a.foo = 123 +a.foo += 456 +a.foo = a.bar + 789 +a.foo += a.bar + 999 + +del a.foo +del a.bar + +a.foo = 123 +a.bar = 456 +say a + +b = {ayy: Var("ayy"), yoo: Var("yoo")} +say b + +b.ayy = 123 +b.ayy += 456 +b.ayy = b.yoo + 789 +b.ayy += b.yoo + 999 + +del b.ayy +del b.yoo + +b["ayy"] = 123 +b["yoo"] = 456 +say b + +c = {ayy: Var("ayy"), yoo: Var("yoo")} +say c + +c["ayy"] = 123 +c["ayy"] += 456 +c["ayy"] = c["yoo"] + 789 +c["ayy"] += c["yoo"] + 999 + +del c.ayy +del c.yoo + +c["ayy"] = 123 +c["yoo"] = 456 +say c diff --git a/tests/snapshots/bolt__parse_126__1.txt b/tests/snapshots/bolt__parse_126__1.txt index 495ef83..524e81b 100644 --- a/tests/snapshots/bolt__parse_126__1.txt +++ b/tests/snapshots/bolt__parse_126__1.txt @@ -1,12 +1,12 @@ _bolt_lineno = [1, 8], [1, 2] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: math = _bolt_helper_import_module('math') _bolt_var0 = math - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'sin') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["sin"] _bolt_var1 = 1 _bolt_var0 = _bolt_var0(_bolt_var1) _bolt_var3 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var2)) diff --git a/tests/snapshots/bolt__parse_127__1.txt b/tests/snapshots/bolt__parse_127__1.txt index c1036ed..51caf60 100644 --- a/tests/snapshots/bolt__parse_127__1.txt +++ b/tests/snapshots/bolt__parse_127__1.txt @@ -1,12 +1,12 @@ _bolt_lineno = [1, 8], [1, 2] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: m = _bolt_helper_import_module('math') _bolt_var0 = m - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'sin') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["sin"] _bolt_var1 = 1 _bolt_var0 = _bolt_var0(_bolt_var1) _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 1a9becb..221114a 100644 --- a/tests/snapshots/bolt__parse_139__1.txt +++ b/tests/snapshots/bolt__parse_139__1.txt @@ -1,5 +1,5 @@ _bolt_lineno = [1, 15, 20, 28, 40], [1, 2, 3, 4, 6] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _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'] @@ -13,12 +13,12 @@ with _bolt_runtime.scope() as _bolt_var10: _bolt_var0 = _bolt_var0(_bolt_var1) for node in _bolt_var0: _bolt_var2 = node - _bolt_var2 = _bolt_helper_get_attribute(_bolt_var2, 'parent') + _bolt_var2 = _bolt_helper_get_attribute_handler(_bolt_var2)["parent"] _bolt_var2 = _bolt_helper_interpolate_resource_location(_bolt_var2, _bolt_refs[0]) with _bolt_runtime.push_nesting('append:function:name:commands', *_bolt_helper_children([_bolt_var2])): with _bolt_runtime.scope() as _bolt_var9: _bolt_var3 = node - _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'partition') + _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["partition"] _bolt_var4 = 5 _bolt_var3 = _bolt_var3(_bolt_var4) _bolt_var3_inverse = _bolt_helper_operator_not(_bolt_var3) @@ -26,24 +26,24 @@ with _bolt_runtime.scope() as _bolt_var10: if _bolt_condition: with _bolt_runtime.push_nesting('execute:subcommand'): _bolt_var5 = node - _bolt_var5 = _bolt_helper_get_attribute(_bolt_var5, 'range') + _bolt_var5 = _bolt_helper_get_attribute_handler(_bolt_var5)["range"] _bolt_var5 = _bolt_helper_interpolate_range(_bolt_var5, _bolt_refs[1]) with _bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_helper_children([_bolt_refs[2], _bolt_refs[3], _bolt_var5])): with _bolt_runtime.push_nesting('execute:run:subcommand'): _bolt_var6 = node - _bolt_var6 = _bolt_helper_get_attribute(_bolt_var6, 'children') + _bolt_var6 = _bolt_helper_get_attribute_handler(_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]))]))]))]))) with _bolt_helper_branch(_bolt_var3_inverse) as _bolt_condition: if _bolt_condition: with _bolt_runtime.push_nesting('execute:subcommand'): _bolt_var7 = node - _bolt_var7 = _bolt_helper_get_attribute(_bolt_var7, 'range') + _bolt_var7 = _bolt_helper_get_attribute_handler(_bolt_var7)["range"] _bolt_var7 = _bolt_helper_interpolate_range(_bolt_var7, _bolt_refs[9]) with _bolt_runtime.push_nesting('execute:if:score:target:targetObjective:matches:range:subcommand', *_bolt_helper_children([_bolt_refs[10], _bolt_refs[11], _bolt_var7])): with _bolt_runtime.push_nesting('execute:run:subcommand'): _bolt_var8 = node - _bolt_var8 = _bolt_helper_get_attribute(_bolt_var8, 'value') + _bolt_var8 = _bolt_helper_get_attribute_handler(_bolt_var8)["value"] _bolt_var8 = _bolt_helper_interpolate_message(_bolt_var8, _bolt_refs[12]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[16], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[15], arguments=_bolt_helper_children([*_bolt_helper_children([_bolt_refs[10], _bolt_refs[11], _bolt_var7]), _bolt_helper_replace(_bolt_refs[14], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[13], arguments=_bolt_helper_children([_bolt_var8]))]))]))]))) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[18], arguments=_bolt_helper_children([*_bolt_helper_children([_bolt_var2]), _bolt_helper_replace(_bolt_refs[17], commands=_bolt_helper_children(_bolt_var9))]))) diff --git a/tests/snapshots/bolt__parse_140__1.txt b/tests/snapshots/bolt__parse_140__1.txt index 8e47e10..35bbc08 100644 --- a/tests/snapshots/bolt__parse_140__1.txt +++ b/tests/snapshots/bolt__parse_140__1.txt @@ -1,11 +1,11 @@ _bolt_lineno = [1], [1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var3: _bolt_var0 = print _bolt_var1 = ctx - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'directory') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["directory"] _bolt_var2 = __name__ _bolt_var0 = _bolt_var0(_bolt_var1, _bolt_var2) _bolt_var4 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var3)) diff --git a/tests/snapshots/bolt__parse_160__1.txt b/tests/snapshots/bolt__parse_160__1.txt index d275538..c43d6ad 100644 --- a/tests/snapshots/bolt__parse_160__1.txt +++ b/tests/snapshots/bolt__parse_160__1.txt @@ -1,11 +1,12 @@ -_bolt_lineno = [1, 6], [1, 2] +_bolt_lineno = [1, 7], [1, 2] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: def f(): _bolt_var0 = {} _bolt_var1 = f - _bolt_var1.data = _bolt_var0 + _bolt_helper_get_attribute_handler(_bolt_var1)["data"] = _bolt_var0 _bolt_var1 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var0)) --- output = _bolt_var1 diff --git a/tests/snapshots/bolt__parse_162__1.txt b/tests/snapshots/bolt__parse_162__1.txt index 5b7eb8f..356a7f7 100644 --- a/tests/snapshots/bolt__parse_162__1.txt +++ b/tests/snapshots/bolt__parse_162__1.txt @@ -1,4 +1,5 @@ -_bolt_lineno = [1, 10], [1, 2] +_bolt_lineno = [1, 11], [1, 2] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var5: @@ -8,7 +9,7 @@ with _bolt_runtime.scope() as _bolt_var5: d = _bolt_var2 _bolt_var3 = 1 _bolt_var4 = d - _bolt_var4.foo += _bolt_var3 + _bolt_helper_get_attribute_handler(_bolt_var4)["foo"] += _bolt_var3 _bolt_var6 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var5)) --- output = _bolt_var6 diff --git a/tests/snapshots/bolt__parse_168__1.txt b/tests/snapshots/bolt__parse_168__1.txt index 8fd6ad1..17158b6 100644 --- a/tests/snapshots/bolt__parse_168__1.txt +++ b/tests/snapshots/bolt__parse_168__1.txt @@ -1,5 +1,5 @@ _bolt_lineno = [1, 13], [1, 2] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_interpolate_item_slot = _bolt_runtime.helpers['interpolate_item_slot'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] @@ -11,10 +11,10 @@ with _bolt_runtime.scope() as _bolt_var7: _bolt_var4 = {_bolt_var0: _bolt_var1, _bolt_var2: _bolt_var3} my_weapon = _bolt_var4 _bolt_var5 = my_weapon - _bolt_var5 = _bolt_helper_get_attribute(_bolt_var5, 'offhand') + _bolt_var5 = _bolt_helper_get_attribute_handler(_bolt_var5)["offhand"] _bolt_var5 = _bolt_helper_interpolate_item_slot(_bolt_var5, _bolt_refs[0]) _bolt_var6 = my_weapon - _bolt_var6 = _bolt_helper_get_attribute(_bolt_var6, 'mainhand') + _bolt_var6 = _bolt_helper_get_attribute_handler(_bolt_var6)["mainhand"] _bolt_var6 = _bolt_helper_interpolate_item_slot(_bolt_var6, _bolt_refs[2]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[4], arguments=_bolt_helper_children([_bolt_refs[1], _bolt_var5, _bolt_refs[3], _bolt_var6]))) _bolt_var8 = _bolt_helper_replace(_bolt_refs[5], commands=_bolt_helper_children(_bolt_var7)) diff --git a/tests/snapshots/bolt__parse_192__1.txt b/tests/snapshots/bolt__parse_192__1.txt index 1a27871..efcb235 100644 --- a/tests/snapshots/bolt__parse_192__1.txt +++ b/tests/snapshots/bolt__parse_192__1.txt @@ -3,7 +3,7 @@ _bolt_helper_interpolate_message = _bolt_runtime.helpers['interpolate_message'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] with _bolt_runtime.scope() as _bolt_var5: _bolt_var0 = 0 math = _bolt_var0 @@ -16,7 +16,7 @@ with _bolt_runtime.scope() as _bolt_var5: _bolt_var2 = wat _bolt_var2 = _bolt_var2() _bolt_var3 = math - _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'ceil') + _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["ceil"] _bolt_var4 = 0.1 _bolt_var3 = _bolt_var3(_bolt_var4) _bolt_var3 = _bolt_helper_interpolate_message(_bolt_var3, _bolt_refs[2]) diff --git a/tests/snapshots/bolt__parse_193__1.txt b/tests/snapshots/bolt__parse_193__1.txt index 809fd75..4d759f2 100644 --- a/tests/snapshots/bolt__parse_193__1.txt +++ b/tests/snapshots/bolt__parse_193__1.txt @@ -1,8 +1,8 @@ _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_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _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_interpolate_numeric = _bolt_runtime.helpers['interpolate_numeric'] @@ -11,7 +11,7 @@ with _bolt_runtime.scope() as _bolt_var16: def init_global_score(self, name): _bolt_var0 = name _bolt_var1 = self - _bolt_var1.name = _bolt_var0 + _bolt_helper_get_attribute_handler(_bolt_var1)["name"] = _bolt_var0 def rebind_global_score(self, rhs): _bolt_var0 = isinstance _bolt_var1 = rhs @@ -21,16 +21,16 @@ with _bolt_runtime.scope() as _bolt_var16: with _bolt_helper_branch(_bolt_var0) as _bolt_condition: if _bolt_condition: _bolt_var3 = self - _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'name') + _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["name"] _bolt_var3 = _bolt_helper_interpolate_entity(_bolt_var3, _bolt_refs[0]) _bolt_var4 = rhs - _bolt_var4 = _bolt_helper_get_attribute(_bolt_var4, 'name') + _bolt_var4 = _bolt_helper_get_attribute_handler(_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]]))) 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') + _bolt_var5 = _bolt_helper_get_attribute_handler(_bolt_var5)["name"] _bolt_var5 = _bolt_helper_interpolate_entity(_bolt_var5, _bolt_refs[6]) _bolt_var6 = rhs _bolt_var6 = _bolt_helper_interpolate_numeric(_bolt_var6, _bolt_refs[7]) diff --git a/tests/snapshots/bolt__parse_194__1.txt b/tests/snapshots/bolt__parse_194__1.txt index 2ecd153..618854e 100644 --- a/tests/snapshots/bolt__parse_194__1.txt +++ b/tests/snapshots/bolt__parse_194__1.txt @@ -2,7 +2,7 @@ _bolt_lineno = [1, 14, 16, 20, 23, 26, 29, 34, 39], [1, 3, 4, 5, 6, 8, 9, 10, 11 _bolt_helper_missing = _bolt_runtime.helpers['missing'] _bolt_helper_get_rebind = _bolt_runtime.helpers['get_rebind'] _bolt_helper_children = _bolt_runtime.helpers['children'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_interpolate_message = _bolt_runtime.helpers['interpolate_message'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var5: @@ -27,19 +27,19 @@ with _bolt_runtime.scope() as _bolt_var5: _bolt_var0 = _bolt_var0() counter = _bolt_var0 _bolt_var1 = counter - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'incr') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["incr"] _bolt_var1 = _bolt_var1() _bolt_var1 = _bolt_helper_interpolate_message(_bolt_var1, _bolt_refs[0]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[1], arguments=_bolt_helper_children([_bolt_var1]))) _bolt_var2 = counter - _bolt_var2 = _bolt_helper_get_attribute(_bolt_var2, 'incr') + _bolt_var2 = _bolt_helper_get_attribute_handler(_bolt_var2)["incr"] _bolt_var2 = _bolt_var2() _bolt_var2 = _bolt_helper_interpolate_message(_bolt_var2, _bolt_refs[2]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[3], arguments=_bolt_helper_children([_bolt_var2]))) _bolt_var3 = Counter _bolt_var4 = 9 _bolt_var3 = _bolt_var3(_bolt_var4) - _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'incr') + _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["incr"] _bolt_var3 = _bolt_var3() _bolt_var3 = _bolt_helper_interpolate_message(_bolt_var3, _bolt_refs[4]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[5], arguments=_bolt_helper_children([_bolt_var3]))) diff --git a/tests/snapshots/bolt__parse_207__1.txt b/tests/snapshots/bolt__parse_207__1.txt index f0ec907..4e1e6a8 100644 --- a/tests/snapshots/bolt__parse_207__1.txt +++ b/tests/snapshots/bolt__parse_207__1.txt @@ -2,7 +2,7 @@ _bolt_lineno = [1, 11], [1, 2] _bolt_helper_interpolate_json = _bolt_runtime.helpers['interpolate_json'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] with _bolt_runtime.scope() as _bolt_var5: _bolt_var0 = 'color' _bolt_var1 = 'red' @@ -11,7 +11,7 @@ with _bolt_runtime.scope() as _bolt_var5: _bolt_var3 = red _bolt_var3 = _bolt_helper_interpolate_json({**_bolt_var3}, _bolt_refs[0]) _bolt_var4 = red - _bolt_var4 = _bolt_helper_get_attribute(_bolt_var4, 'color') + _bolt_var4 = _bolt_helper_get_attribute_handler(_bolt_var4)["color"] _bolt_var4 = _bolt_helper_interpolate_json([*_bolt_var4], _bolt_refs[4]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[7], arguments=_bolt_helper_children([_bolt_refs[6], _bolt_helper_replace(_bolt_refs[5], elements=_bolt_helper_children([_bolt_refs[3], _bolt_helper_replace(_bolt_refs[2], entries=_bolt_helper_children([_bolt_refs[1], *_bolt_var3])), *_bolt_var4]))]))) _bolt_var6 = _bolt_helper_replace(_bolt_refs[8], commands=_bolt_helper_children(_bolt_var5)) diff --git a/tests/snapshots/bolt__parse_208__1.txt b/tests/snapshots/bolt__parse_208__1.txt index b312658..f8ed9f2 100644 --- a/tests/snapshots/bolt__parse_208__1.txt +++ b/tests/snapshots/bolt__parse_208__1.txt @@ -1,11 +1,11 @@ _bolt_lineno = [1], [1] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: _bolt_from_import = _bolt_helper_import_module('PIL') - Image = _bolt_helper_get_attribute(_bolt_from_import, 'Image') + Image = _bolt_helper_get_attribute_handler(_bolt_from_import)["Image"] _bolt_var1 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var0)) --- output = _bolt_var1 diff --git a/tests/snapshots/bolt__parse_209__1.txt b/tests/snapshots/bolt__parse_209__1.txt index a97cade..92ddb32 100644 --- a/tests/snapshots/bolt__parse_209__1.txt +++ b/tests/snapshots/bolt__parse_209__1.txt @@ -1,11 +1,11 @@ _bolt_lineno = [1], [1] _bolt_helper_import_module = _bolt_runtime.helpers['import_module'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: _bolt_from_import = _bolt_helper_import_module('PIL.Image') - Image = _bolt_helper_get_attribute(_bolt_from_import, 'Image') + Image = _bolt_helper_get_attribute_handler(_bolt_from_import)["Image"] _bolt_var1 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var0)) --- output = _bolt_var1 diff --git a/tests/snapshots/bolt__parse_211__1.txt b/tests/snapshots/bolt__parse_211__1.txt index 8f83f88..b2f18f4 100644 --- a/tests/snapshots/bolt__parse_211__1.txt +++ b/tests/snapshots/bolt__parse_211__1.txt @@ -1,5 +1,5 @@ _bolt_lineno = [1, 12], [1, 2] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_interpolate_json = _bolt_runtime.helpers['interpolate_json'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] @@ -10,7 +10,7 @@ with _bolt_runtime.scope() as _bolt_var3: with _bolt_var0 as _bolt_with0: f = _bolt_with0 _bolt_var2 = f - _bolt_var2 = _bolt_helper_get_attribute(_bolt_var2, 'readline') + _bolt_var2 = _bolt_helper_get_attribute_handler(_bolt_var2)["readline"] _bolt_var2 = _bolt_var2() _bolt_var2 = _bolt_helper_interpolate_json(_bolt_var2, _bolt_refs[0]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[2], arguments=_bolt_helper_children([_bolt_refs[1], _bolt_var2]))) diff --git a/tests/snapshots/bolt__parse_245__1.txt b/tests/snapshots/bolt__parse_245__1.txt index 2875680..462ca45 100644 --- a/tests/snapshots/bolt__parse_245__1.txt +++ b/tests/snapshots/bolt__parse_245__1.txt @@ -1,22 +1,22 @@ _bolt_lineno = [1, 8, 14, 18], [1, 2, 3, 4] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_proc_macros = {} _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: def _bolt_macro0(stream): _bolt_var0 = stream - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'syntax') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["syntax"] _bolt_var1 = '\\d+' _bolt_var2 = '\\w+' _bolt_var0 = _bolt_var0(number=_bolt_var1, name=_bolt_var2) with _bolt_var0: _bolt_var3 = stream - _bolt_var3 = _bolt_helper_get_attribute(_bolt_var3, 'expect') + _bolt_var3 = _bolt_helper_get_attribute_handler(_bolt_var3)["expect"] _bolt_var4 = 'number' _bolt_var3 = _bolt_var3(_bolt_var4) _bolt_var5 = stream - _bolt_var5 = _bolt_helper_get_attribute(_bolt_var5, 'expect') + _bolt_var5 = _bolt_helper_get_attribute_handler(_bolt_var5)["expect"] _bolt_var6 = 'name' _bolt_var5 = _bolt_var5(_bolt_var6) _bolt_proc_macros['foo:proc_macro_overload3'] = _bolt_macro0 diff --git a/tests/snapshots/bolt__parse_251__1.txt b/tests/snapshots/bolt__parse_251__1.txt index 5ebbb9d..3f23ece 100644 --- a/tests/snapshots/bolt__parse_251__1.txt +++ b/tests/snapshots/bolt__parse_251__1.txt @@ -1,6 +1,6 @@ _bolt_lineno = [1, 8, 10], [1, 2, 3] _bolt_helper_children = _bolt_runtime.helpers['children'] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: class Foo: @@ -9,7 +9,7 @@ with _bolt_runtime.scope() as _bolt_var2: del _bolt_var0 _bolt_var0 = print _bolt_var1 = Foo - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'bar') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["bar"] _bolt_var0 = _bolt_var0(_bolt_var1) _bolt_var3 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var2)) --- diff --git a/tests/snapshots/bolt__parse_255__1.txt b/tests/snapshots/bolt__parse_255__1.txt index e6cbc4d..510c7c2 100644 --- a/tests/snapshots/bolt__parse_255__1.txt +++ b/tests/snapshots/bolt__parse_255__1.txt @@ -1,11 +1,11 @@ _bolt_lineno = [1, 7, 9, 10, 12, 13, 14], [1, 2, 3, 4, 3, 2, 1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var3: _bolt_var0 = print _bolt_var1 = str - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'upper') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["upper"] _bolt_var2 = str class Foo: pass diff --git a/tests/snapshots/bolt__parse_259__1.txt b/tests/snapshots/bolt__parse_259__1.txt index 12e96d2..2841c3b 100644 --- a/tests/snapshots/bolt__parse_259__1.txt +++ b/tests/snapshots/bolt__parse_259__1.txt @@ -1,4 +1,5 @@ -_bolt_lineno = [1, 7], [1, 3] +_bolt_lineno = [1, 8], [1, 3] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var0: @@ -6,7 +7,7 @@ with _bolt_runtime.scope() as _bolt_var0: def __init__(self, name): _bolt_var0 = name _bolt_var1 = self - _bolt_var1.name = _bolt_var0 + _bolt_helper_get_attribute_handler(_bolt_var1)["name"] = _bolt_var0 _bolt_var1 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var0)) --- output = _bolt_var1 diff --git a/tests/snapshots/bolt__parse_275__1.txt b/tests/snapshots/bolt__parse_275__1.txt index 5df2ff0..32f8fe0 100644 --- a/tests/snapshots/bolt__parse_275__1.txt +++ b/tests/snapshots/bolt__parse_275__1.txt @@ -1,5 +1,5 @@ _bolt_lineno = [1, 9], [1, 2] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_interpolate_word = _bolt_runtime.helpers['interpolate_word'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] _bolt_helper_children = _bolt_runtime.helpers['children'] @@ -7,7 +7,7 @@ with _bolt_runtime.scope() as _bolt_var2: _bolt_var0 = 42 hex = _bolt_var0 _bolt_var1 = hex - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'summon') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["summon"] _bolt_var1 = _bolt_helper_interpolate_word(_bolt_var1, _bolt_refs[0]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[4], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[3], fragments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[2], arguments=_bolt_helper_children([_bolt_helper_replace(_bolt_refs[1], value=_bolt_var1)]))]))]))) _bolt_var3 = _bolt_helper_replace(_bolt_refs[5], commands=_bolt_helper_children(_bolt_var2)) diff --git a/tests/snapshots/bolt__parse_278__1.txt b/tests/snapshots/bolt__parse_278__1.txt index 2421431..960eaa7 100644 --- a/tests/snapshots/bolt__parse_278__1.txt +++ b/tests/snapshots/bolt__parse_278__1.txt @@ -1,5 +1,5 @@ _bolt_lineno = [1, 9], [1, 2] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_interpolate_time = _bolt_runtime.helpers['interpolate_time'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] @@ -7,7 +7,7 @@ with _bolt_runtime.scope() as _bolt_var2: _bolt_var0 = 123 hex = _bolt_var0 _bolt_var1 = hex - _bolt_var1 = _bolt_helper_get_attribute(_bolt_var1, 'time') + _bolt_var1 = _bolt_helper_get_attribute_handler(_bolt_var1)["time"] _bolt_var1 = _bolt_helper_interpolate_time(_bolt_var1, _bolt_refs[0]) _bolt_runtime.commands.append(_bolt_helper_replace(_bolt_refs[1], arguments=_bolt_helper_children([_bolt_var1]))) _bolt_var3 = _bolt_helper_replace(_bolt_refs[2], commands=_bolt_helper_children(_bolt_var2)) diff --git a/tests/snapshots/bolt__parse_65__1.txt b/tests/snapshots/bolt__parse_65__1.txt index 7d65597..5948b2e 100644 --- a/tests/snapshots/bolt__parse_65__1.txt +++ b/tests/snapshots/bolt__parse_65__1.txt @@ -1,10 +1,10 @@ _bolt_lineno = [1], [1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var1: _bolt_var0 = 'foo' - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'bar') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["bar"] _bolt_var2 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var1)) --- output = _bolt_var2 diff --git a/tests/snapshots/bolt__parse_66__1.txt b/tests/snapshots/bolt__parse_66__1.txt index 436ad70..0d2507e 100644 --- a/tests/snapshots/bolt__parse_66__1.txt +++ b/tests/snapshots/bolt__parse_66__1.txt @@ -1,11 +1,11 @@ _bolt_lineno = [1], [1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var1: _bolt_var0 = 'foo' - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'bar') - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'baz') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["bar"] + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["baz"] _bolt_var2 = _bolt_helper_replace(_bolt_refs[0], commands=_bolt_helper_children(_bolt_var1)) --- output = _bolt_var2 diff --git a/tests/snapshots/bolt__parse_67__1.txt b/tests/snapshots/bolt__parse_67__1.txt index 83447d3..22b194b 100644 --- a/tests/snapshots/bolt__parse_67__1.txt +++ b/tests/snapshots/bolt__parse_67__1.txt @@ -1,10 +1,10 @@ _bolt_lineno = [1], [1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var2: _bolt_var0 = 'foo' - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'bar') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["bar"] _bolt_var0 = _bolt_var0() _bolt_var1 = 0 _bolt_var0 = _bolt_var0[_bolt_var1] diff --git a/tests/snapshots/bolt__parse_68__1.txt b/tests/snapshots/bolt__parse_68__1.txt index 13a7f5d..45bd202 100644 --- a/tests/snapshots/bolt__parse_68__1.txt +++ b/tests/snapshots/bolt__parse_68__1.txt @@ -1,10 +1,10 @@ _bolt_lineno = [1], [1] -_bolt_helper_get_attribute = _bolt_runtime.helpers['get_attribute'] +_bolt_helper_get_attribute_handler = _bolt_runtime.helpers['get_attribute_handler'] _bolt_helper_children = _bolt_runtime.helpers['children'] _bolt_helper_replace = _bolt_runtime.helpers['replace'] with _bolt_runtime.scope() as _bolt_var7: _bolt_var0 = 'foo' - _bolt_var0 = _bolt_helper_get_attribute(_bolt_var0, 'bar') + _bolt_var0 = _bolt_helper_get_attribute_handler(_bolt_var0)["bar"] _bolt_var0 = _bolt_var0() _bolt_var1 = 0 _bolt_var0 = _bolt_var0[_bolt_var1] diff --git a/tests/snapshots/examples__build_bolt_basic__0.pack.md b/tests/snapshots/examples__build_bolt_basic__0.pack.md index 39dcf7a..0828ec3 100644 --- a/tests/snapshots/examples__build_bolt_basic__0.pack.md +++ b/tests/snapshots/examples__build_bolt_basic__0.pack.md @@ -15,6 +15,46 @@ ### demo +`@function demo:attribute_rebind` + +```mcfunction +say foo bar +say foo = 123 +say foo_plus_456 = foo + 456 +say foo = foo_plus_456 +say bar_plus_789 = bar + 789 +say foo = bar_plus_789 +say bar_plus_999 = bar + 999 +say foo_plus_bar_plus_999 = foo + bar_plus_999 +say foo = foo_plus_bar_plus_999 +say 123 456 +say A(foo=Var(name='foo'), bar=Var(name='bar')) +say foo = 123 +say foo_plus_456 = foo + 456 +say foo = foo_plus_456 +say bar_plus_789 = bar + 789 +say foo = bar_plus_789 +say bar_plus_999 = bar + 999 +say foo_plus_bar_plus_999 = foo + bar_plus_999 +say foo = foo_plus_bar_plus_999 +say A(foo=123, bar=456) +say {'ayy': Var(name='ayy'), 'yoo': Var(name='yoo')} +say ayy = 123 +say ayy_plus_456 = ayy + 456 +say ayy = ayy_plus_456 +say yoo_plus_789 = yoo + 789 +say ayy = yoo_plus_789 +say yoo_plus_999 = yoo + 999 +say ayy_plus_yoo_plus_999 = ayy + yoo_plus_999 +say ayy = ayy_plus_yoo_plus_999 +say {'ayy': 123, 'yoo': 456} +say {'ayy': Var(name='ayy'), 'yoo': Var(name='yoo')} +say yoo_plus_789 = yoo + 789 +say yoo_plus_999 = yoo + 999 +say yoo_plus_789_plus_yoo_plus_999 = yoo_plus_789 + yoo_plus_999 +say {'ayy': 123, 'yoo': 456} +``` + `@function demo:foo` ```mcfunction