-
Notifications
You must be signed in to change notification settings - Fork 132
MultiValue expression implemented to support opcodes that return multiple values #196
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
8 commits
Select commit
Hold shift + click to select a range
94a482b
Optimization added for repeated int constants under 2**7 w/ tests
algoidurovic e0795fc
fixed type problem and formatted
algoidurovic bb1eb20
Expanded test and added comment for clarification
algoidurovic 2c89bdc
add multivalue expr and change maybevalue to derive from multivalue
algoidurovic cd2d60a
Merge branch 'master' of https://github.com/algorand/pyteal into mult…
algoidurovic 160c312
updated tests and formatting
algoidurovic a39d783
reorder output slots to reflect stack ordering
algoidurovic 84a98e0
add additional assertion in MaybeValue test to enforce slot ordering
algoidurovic 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from typing import Callable, List, Union, TYPE_CHECKING | ||
|
|
||
| from ..types import TealType | ||
| from ..ir import TealOp, Op, TealBlock | ||
| from .expr import Expr | ||
| from .leafexpr import LeafExpr | ||
| from .scratch import ScratchSlot | ||
| from .seq import Seq | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..compiler import CompileOptions | ||
|
|
||
|
|
||
| class MultiValue(LeafExpr): | ||
| """Represents an operation that returns more than one value""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| op: Op, | ||
| types: List[TealType], | ||
| *, | ||
| immediate_args: List[Union[int, str]] = None, | ||
| args: List[Expr] = None | ||
| ): | ||
| """Create a new MultiValue. | ||
| Args: | ||
| op: The operation that returns values. | ||
| types: The types of the returned values. | ||
| immediate_args (optional): Immediate arguments for the op. Defaults to None. | ||
| args (optional): Stack arguments for the op. Defaults to None. | ||
| """ | ||
| super().__init__() | ||
| self.op = op | ||
| self.types = types | ||
| self.immediate_args = immediate_args if immediate_args is not None else [] | ||
| self.args = args if args is not None else [] | ||
|
|
||
| self.output_slots = [ScratchSlot() for _ in self.types] | ||
|
|
||
| def outputReducer(self, reducer: Callable[..., Expr]) -> Expr: | ||
michaeldiamant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| input = [slot.load(self.types[i]) for i, slot in enumerate(self.output_slots)] | ||
| return Seq(self, reducer(*input)) | ||
|
|
||
| def __str__(self): | ||
| ret_str = "(({}".format(self.op) | ||
| for a in self.immediate_args: | ||
| ret_str += " " + a.__str__() | ||
|
|
||
| for a in self.args: | ||
| ret_str += " " + a.__str__() | ||
| ret_str += ") " | ||
|
|
||
| ret_str += " ".join([slot.store().__str__() for slot in self.output_slots]) | ||
| ret_str += ")" | ||
|
|
||
| return ret_str | ||
|
|
||
| def __teal__(self, options: "CompileOptions"): | ||
| tealOp = TealOp(self, self.op, *self.immediate_args) | ||
| callStart, callEnd = TealBlock.FromOp(options, tealOp, *self.args) | ||
|
|
||
| curEnd = callEnd | ||
| # the list is reversed in order to preserve the ordering of the opcode's returned | ||
| # values. ie the output to stack [A, B, C] should correspond to C->output_slots[2] | ||
| # B->output_slots[1], and A->output_slots[0]. | ||
| for slot in reversed(self.output_slots): | ||
michaeldiamant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| store = slot.store() | ||
| storeStart, storeEnd = store.__teal__(options) | ||
| curEnd.setNextBlock(storeStart) | ||
| curEnd = storeEnd | ||
|
|
||
| return callStart, curEnd | ||
|
|
||
| def type_of(self): | ||
| return TealType.none | ||
|
|
||
|
|
||
| MultiValue.__module__ = "pyteal" | ||
Oops, something went wrong.
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.