Skip to content

Commit

Permalink
Merge branch 'feature/fp-subroutine' into feature/fp-local-var
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Dec 3, 2022
2 parents c5c7715 + 2285654 commit a73fcd3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Unreleased

# Added
* Added frame pointer support for subroutine arguments, replacing the previous usage of scratch. ([#562](https://github.com/algorand/pyteal/pull/562))

# Fixed
* Allowing the `MethodCall` and `ExecuteMethodCall` to be passed `None` as app_id argument in the case of an app create transaction ([#592](https://github.com/algorand/pyteal/pull/592))

# Changed
* Introducing `AbstractVar` to abstract value access: store, load, and stack type. ([#584](https://github.com/algorand/pyteal/pull/584))
* NOTE: a backwards incompatable change was imposed in this PR: previous ABI value's public member `stored_value` with type `ScratchVar`, is now changed to protected member `_stored_value` with type `AbstractVar`.

# 0.20.1

Expand Down
4 changes: 1 addition & 3 deletions pyteal/ast/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def __init__(
f"be greater than local allocations {len(local_stack_types)}."
)

if not all(
map(lambda t: t != TealType.none, arg_stack_types + local_stack_types)
):
if any(t == TealType.none for t in arg_stack_types + local_stack_types):
raise TealInternalError("Variables in frame memory layout must be typed.")

self.num_return_allocs: int = num_return_allocs
Expand Down
9 changes: 7 additions & 2 deletions pyteal/ast/subroutine_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from itertools import product
from typing import Callable, Literal, Optional, cast
from inspect import signature

import pytest
from dataclasses import dataclass
Expand Down Expand Up @@ -1326,6 +1327,11 @@ def mySubroutine_arg_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10):
assert len(declaration.body.args) == 2

assert isinstance(declaration.body.args[0], Proto)

proto_expr = declaration.body.args[0]
assert proto_expr.num_returns == int(return_type != pt.TealType.none)
assert proto_expr.num_args == len(signature(subr).parameters)

assert isinstance(declaration.body.args[1], type(return_value))

options_v8.setSubroutine(definition)
Expand All @@ -1335,8 +1341,7 @@ def mySubroutine_arg_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10):

actual, _ = declaration.__teal__(options_v8)
options_v8.setSubroutine(None)
with pt.TealComponent.Context.ExprEqualityContext():
assert actual == expected
assert actual == expected


def test_docstring_parsing_with_different_format():
Expand Down
7 changes: 7 additions & 0 deletions pyteal/compiler/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,13 @@ def approve_if_odd(condition_encoding: pt.abi.Uint32) -> pt.Expr:
clear_state=pt.OnCompleteAction.call_only(pt.Approve()),
)

with pytest.raises(pt.TealInputError) as e:
pt.Router("will-error", on_completion_actions).compile_program(
version=6, frame_pointers=True
)

assert "Try to use frame pointer with an insufficient version 6" in str(e)

_router_with_oc = pt.Router(
"ASimpleQuestionablyRobustContract", on_completion_actions
)
Expand Down

0 comments on commit a73fcd3

Please sign in to comment.