Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the 'method' pseudo op #50

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tealish/expression_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,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
Expand Down
17 changes: 16 additions & 1 deletion tealish/langspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -187,7 +200,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,
Expand Down
20 changes: 20 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,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

Expand Down