From 067acaea678494e57d466ee2f13fc49adb6654bf Mon Sep 17 00:00:00 2001 From: Fergal Walsh Date: Fri, 27 Jan 2023 14:52:14 +0000 Subject: [PATCH 1/2] Support the method pseudo op --- tealish/expression_nodes.py | 2 ++ tealish/langspec.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tealish/expression_nodes.py b/tealish/expression_nodes.py index 22f2e92..b882cb5 100644 --- a/tealish/expression_nodes.py +++ b/tealish/expression_nodes.py @@ -228,6 +228,8 @@ def process_op_call(self, op: Op) -> None: immediates[i] = x.name elif isinstance(x, Integer): immediates[i] = x.value + elif isinstance(x, Bytes): + immediates[i] = f'"{x.value}"' self.immediate_args = " ".join(map(str, immediates)) returns = op.returns_types[::-1] self.type = returns[0] if len(returns) == 1 else returns diff --git a/tealish/langspec.py b/tealish/langspec.py index d15b847..f54b5e9 100644 --- a/tealish/langspec.py +++ b/tealish/langspec.py @@ -8,6 +8,19 @@ abc = "ABCDEFGHIJK" +# Hopefully these will eventually be added to langspec.json. Including here until then. +# Note: Other pseudo ops like addr and base32 are not included here because their syntax isn't parseable by Tealish currently. +# e.g addr(RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU) is not parseable because the address isn't quoted. +pseudo_ops = [ + { + "Name": "method", + "Opcode": "method", + "Size": 2, + "Args": [], + "Returns": ["B"], + }, +] + _opcode_type_map = { ".": AVMType.any, @@ -119,7 +132,9 @@ class LangSpec: def __init__(self, spec: Dict[str, Any]) -> None: self.is_packaged = False self.spec = spec - self.ops: Dict[str, Op] = {op["Name"]: Op(op) for op in spec["Ops"]} + self.ops: Dict[str, Op] = { + op["Name"]: Op(op) for op in (spec["Ops"] + pseudo_ops) + } self.fields: Dict[str, Any] = { "Global": self.ops["global"].arg_enum_dict, From 795714b4a6bd2fe98f41602de535dd39d7e57ddd Mon Sep 17 00:00:00 2001 From: Fergal Walsh Date: Fri, 24 Mar 2023 10:28:08 +0000 Subject: [PATCH 2/2] Add tests for method pseudo-op --- tests/test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test.py b/tests/test.py index 64c7528..fe1cad0 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1237,6 +1237,26 @@ def test_pass_int_field_assignment(self): ) +class TestPseudoOp(unittest.TestCase): + def test_pass_method_void(self): + teal = compile_expression_min('method("name(uint64,uint64)")') + self.assertListEqual(teal, ['method "name(uint64,uint64)"']) + + def test_pass_method_return(self): + teal = compile_expression_min('method("name(uint64,uint64)uint64")') + self.assertListEqual(teal, ['method "name(uint64,uint64)uint64"']) + + @expectedFailure + def test_pass_method_const(self): + teal = compile_min( + [ + 'const bytes SIG = "name(uint64,uint64)"', + "log(method(SIG))", + ] + ) + self.assertListEqual(teal, ['method "name(uint64,uint64)"', "log"]) + + class TestEverythingProgram(unittest.TestCase): maxDiff = None