-
Notifications
You must be signed in to change notification settings - Fork 132
method pseudo-op support for ABI methods
#153
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a363756
update method, need some improvements
ahangsu 4286afc
cleanup
ahangsu f5467e1
update method impl and test
ahangsu a111aa0
update subroutine, support replacing labels with method sig
ahangsu f54013e
minor
ahangsu 091dafe
change teal comments to method signatures if subroutine is specified …
ahangsu 003771c
refmt
ahangsu 45e6414
fix method gen-code
ahangsu e743eba
minor
ahangsu 4b0397d
fmt...
ahangsu 9c1825a
update optimization for constants assemble
ahangsu 20505c9
rename methodSignature to nameStr
ahangsu 9f7ec76
minor, change subroutine definition name mechanism
ahangsu 9539089
per review
ahangsu 3327bd5
minor rename in constants
ahangsu c027311
per review
ahangsu cbbf13e
house cleaning
ahangsu 7856987
per review
ahangsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from typing import TYPE_CHECKING | ||
| from pyteal.errors import TealInputError | ||
|
|
||
| from pyteal.types import TealType | ||
|
|
||
| from ..types import TealType | ||
| from ..ir import TealOp, Op, TealBlock | ||
| from .leafexpr import LeafExpr | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..compiler import CompileOptions | ||
|
|
||
|
|
||
| class MethodSignature(LeafExpr): | ||
| """An expression that represents an ABI method selector""" | ||
|
|
||
| def __init__(self, methodName: str) -> None: | ||
| """Create a new method selector for ABI method call. | ||
|
|
||
| Args: | ||
| methodName: A string containing a valid ABI method signature | ||
| """ | ||
| super().__init__() | ||
| if type(methodName) is not str: | ||
| raise TealInputError( | ||
| "invalid input type {} to Method".format(type(methodName)) | ||
| ) | ||
| elif len(methodName) == 0: | ||
| raise TealInputError("invalid input empty string to Method") | ||
| self.methodName = methodName | ||
|
|
||
| def __teal__(self, options: "CompileOptions"): | ||
| op = TealOp(self, Op.method_signature, '"{}"'.format(self.methodName)) | ||
| return TealBlock.FromOp(options, op) | ||
|
|
||
| def __str__(self) -> str: | ||
| return "(method: {})".format(self.methodName) | ||
|
|
||
| def type_of(self) -> TealType: | ||
| return TealType.bytes | ||
|
|
||
|
|
||
| MethodSignature.__module__ = "pyteal" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import pytest | ||
|
|
||
| from pyteal.ast.methodsig import MethodSignature | ||
|
|
||
| from .. import * | ||
|
|
||
|
|
||
| def test_method(): | ||
| expr = MethodSignature("add(uint64,uint64)uint64") | ||
| assert expr.type_of() == TealType.bytes | ||
|
|
||
| expected = TealSimpleBlock( | ||
| [TealOp(expr, Op.method_signature, '"add(uint64,uint64)uint64"')] | ||
| ) | ||
| actual, _ = expr.__teal__(CompileOptions()) | ||
| assert expected == actual | ||
|
|
||
|
|
||
| def test_method_invalid(): | ||
| with pytest.raises(TealInputError): | ||
| MethodSignature(114514) | ||
|
|
||
| with pytest.raises(TealInputError): | ||
| MethodSignature(['"m0()void"', '"m1()uint64"']) | ||
|
|
||
| with pytest.raises(TealInputError): | ||
| MethodSignature("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.