Skip to content

Commit 48d115f

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent a88733b commit 48d115f

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

eth/abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,13 +1593,13 @@ def stack_dup(self, position: int) -> None:
15931593
#
15941594
# Return Stack Managemement
15951595
#
1596-
@abstract_method
1596+
@abstractmethod
15971597
def rstack_push_int(self) -> Callable[[int], None]:
15981598
"""
15991599
Push integer onto the return stack.
16001600
"""
16011601

1602-
@abstract_method
1602+
@abstractmethod
16031603
def rstack_pop1_int(self) -> Callable[[int], None]:
16041604
"""
16051605
Pop integer off the return stack and return it.

eth/vm/rstack.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
validate_stack_int,
1212
)
1313

14-
from eth.utils import (
14+
from eth_utils import (
1515
big_endian_to_int,
1616
ValidationError,
1717
)
1818

19-
import collections.UserList as rstack
2019
"""
2120
This module simply implements for the return stack the exact same design used for the data stack.
2221
As this stack must simply push_int or pop1_int any time a subroutine is accessed or left, only those two functions are provided.
@@ -28,14 +27,14 @@ class RStack():
2827
VM Return Stack
2928
"""
3029

31-
__slots__ = ['values', '_append', '_pop_int', '__len__']
30+
__slots__ = ['values', '_append', '_pop_typed', '__len__']
3231

3332
def __init__(self) -> None:
34-
values: List[int]
35-
self.values = rstack.data
36-
self._append = rstack.data.append
37-
self._pop_typed = rstack.data.pop
38-
self.__len__ = rstack.data.__len__
33+
values: List[int] = []
34+
self.values = values
35+
self._append = values.append
36+
self._pop_typed = values.pop
37+
self.__len__ = values.__len__
3938

4039
def push_int(self) -> int:
4140
if len(self.values) > 1023:
@@ -49,18 +48,3 @@ def push_int(self) -> int:
4948
def pop1_int(self) -> int:
5049
#
5150
# Note: This function is optimized for speed over readability.
52-
#
53-
if not self.values:
54-
raise InsufficientStack("Wanted 1 stack item as int, had none")
55-
else:
56-
item_type, popped = self._pop_typed()
57-
if item_type is int:
58-
return popped # type: ignore
59-
elif item_type is bytes:
60-
return big_endian_to_int(popped) # type: ignore
61-
else:
62-
raise ValidationError(
63-
"Stack must always be bytes or int, "
64-
f"got {item_type!r} type, val {value!r}"
65-
)
66-

0 commit comments

Comments
 (0)