Skip to content

Commit

Permalink
[WIP] Implement subroutine opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Peppece committed Oct 12, 2020
1 parent f2f1d31 commit e1e988d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions eth/vm/rstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@
ValidationError,
)


import collections.UserList as rstack
"""
This module simply implements for the return stack the exact same design used for the data stack.
As this stack must simply push_int or pop1_int any time a subroutine is accessed or left, only those two functions are provided.
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.
"""


def _busted_type(item_type: type, value: Union[int, bytes]) -> ValidationError:
return ValidationError(
"Stack must always be bytes or int, "
f"got {item_type!r} type, val {value!r}"
)

class RStack():
"""
VM Return Stack
Expand All @@ -39,10 +32,10 @@ class RStack():

def __init__(self) -> None:
values: List[int]
self.values = values
self._append = values.append
self._pop_typed = values.pop
self.__len__ = values.__len__
self.values = rstack.data
self._append = rstack.data.append
self._pop_typed = rstack.data.pop
self.__len__ = rstack.data.__len__

def push_int(self) -> int:
if len(self.values) > 1023:
Expand All @@ -66,5 +59,8 @@ def pop1_int(self) -> int:
elif item_type is bytes:
return big_endian_to_int(popped) # type: ignore
else:
raise _busted_type(item_type, popped)
raise ValidationError(
"Stack must always be bytes or int, "
f"got {item_type!r} type, val {value!r}"
)

0 comments on commit e1e988d

Please sign in to comment.