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 for stores and loads opcodes functionality #159

Closed
algoanne opened this issue Jan 14, 2022 · 2 comments
Closed

Support for stores and loads opcodes functionality #159

algoanne opened this issue Jan 14, 2022 · 2 comments
Assignees

Comments

@algoanne
Copy link

algoanne commented Jan 14, 2022

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.

@algoanne algoanne changed the title Support for stores opcode functionality Support for stores and loads opcodes functionality Jan 14, 2022
@jasonpaulos
Copy link
Contributor

jasonpaulos commented Jan 20, 2022

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)
def addAndPlaceSumInFirstArg(a: ScratchVar, b: Expr):
    return a.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
)

@jasonpaulos
Copy link
Contributor

Closed by #198, related issue is #200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants