You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context
The TEAL stores opcode stores a value from the stack to a scratch space with index from the stack. The loads opcde takes a value from the scratch space and puts it on the stack. These are already available in TEAL.
Note that store and load opcodes functionality already exist in PyTeal, so this story if just to add the stack usage part.
What are you looking for? stores and loads functionality should be made available in PyTeal.
(Optional) Design considerations
also, could be useful to add a new method to scratch var that returns the scratch ID.
how do we allocate a range of scratch slots.
The text was updated successfully, but these errors were encountered:
These opcodes can be used to implement "pass by reference" semantics to subroutines. Meaning instead of the actual value being passed as an argument, the value would be placed into a scratch slot by the caller and that slot's ID would be passed as the argument to the subroutine. Then the subroutine would use loads and stores to read and write to that slot.
Ideally this would be handled automatically by subroutines. Maybe if you use ScratchVar as the type of an argument in a subroutine, the compiler can work out the rest of the details necessary to make pass by reference work.
For example:
@Subroutine(TealType.none)defaddAndPlaceSumInFirstArg(a: ScratchVar, b: Expr):
returna.store(a.load() +b)
value=ScratchVar(TealType.uint64)
program=Seq(
value.store(1),
addAndPlaceSumInFirstArg(value, Int(100)),
Log(Itob(value.load())) # value should now be 101
)
Context
The TEAL
stores
opcode stores a value from the stack to a scratch space with index from the stack. Theloads
opcde takes a value from the scratch space and puts it on the stack. These are already available in TEAL.Note that
store
andload
opcodes functionality already exist in PyTeal, so this story if just to add the stack usage part.What are you looking for?
stores
andloads
functionality should be made available in PyTeal.(Optional) Design considerations
also, could be useful to add a new method to scratch var that returns the scratch ID.
how do we allocate a range of scratch slots.
The text was updated successfully, but these errors were encountered: