Skip to content

Commit

Permalink
Add docs for TealBlock methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Feb 25, 2022
1 parent 8303aff commit a91ec45
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pyteal/ir/tealblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ def NormalizeBlocks(cls, start: "TealBlock") -> "TealBlock":

@classmethod
def GetReferencedScratchSlots(cls, start: "TealBlock") -> List["ScratchSlot"]:
"""Get all scratch slot references for the graph starting at this TealBlock.
Returns:
A list of ScratchSlots where each element represents a reference to that slot by a
TealOp in the graph. The order of the list is consistent, and there may be duplicate
ScratchSlots in the list if the same slot is referenced multiple times.
"""
slots: List[ScratchSlot] = []

for block in TealBlock.Iterate(start):
Expand All @@ -242,6 +249,20 @@ def GetReferencedScratchSlots(cls, start: "TealBlock") -> List["ScratchSlot"]:
def MatchScratchSlotReferences(
cls, actual: List["ScratchSlot"], expected: List["ScratchSlot"]
) -> bool:
"""Determine if there is a mapping between the actual and expected lists of ScratchSlots.
A mapping is defined as follows:
* The actual and expected lists must have the same length.
* For every ScratchSlot referenced by either list:
* If the slot appears in both lists, it must appear the exact same number of times and at
the exact same indexes in both lists.
* If the slot appears only in one list, for each of its appearances in that list, there
must be a ScratchSlot in the other list that appears the exact same number of times
and at the exact same indexes.
Returns:
True if and only if a mapping as described above exists between actual and expected.
"""
if len(actual) != len(expected):
return False

Expand Down

0 comments on commit a91ec45

Please sign in to comment.