Skip to content

Commit e1e988d

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent f2f1d31 commit e1e988d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

eth/vm/rstack.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@
1616
ValidationError,
1717
)
1818

19-
19+
import collections.UserList as rstack
2020
"""
2121
This module simply implements for the return stack the exact same design used for the data stack.
2222
As this stack must simply push_int or pop1_int any time a subroutine is accessed or left, only those two functions are provided.
2323
For the same reason, the class RStack doesn't inherit from the abc StackAPI, as it would require to implement all the abstract methods defined.
2424
"""
2525

26-
27-
def _busted_type(item_type: type, value: Union[int, bytes]) -> ValidationError:
28-
return ValidationError(
29-
"Stack must always be bytes or int, "
30-
f"got {item_type!r} type, val {value!r}"
31-
)
32-
3326
class RStack():
3427
"""
3528
VM Return Stack
@@ -39,10 +32,10 @@ class RStack():
3932

4033
def __init__(self) -> None:
4134
values: List[int]
42-
self.values = values
43-
self._append = values.append
44-
self._pop_typed = values.pop
45-
self.__len__ = values.__len__
35+
self.values = rstack.data
36+
self._append = rstack.data.append
37+
self._pop_typed = rstack.data.pop
38+
self.__len__ = rstack.data.__len__
4639

4740
def push_int(self) -> int:
4841
if len(self.values) > 1023:
@@ -66,5 +59,8 @@ def pop1_int(self) -> int:
6659
elif item_type is bytes:
6760
return big_endian_to_int(popped) # type: ignore
6861
else:
69-
raise _busted_type(item_type, popped)
62+
raise ValidationError(
63+
"Stack must always be bytes or int, "
64+
f"got {item_type!r} type, val {value!r}"
65+
)
7066

0 commit comments

Comments
 (0)