Skip to content

Commit

Permalink
[WIP] Implement simple subroutine opcodes]
Browse files Browse the repository at this point in the history
  • Loading branch information
Peppece committed Jul 12, 2020
1 parent bb54ca2 commit b903b91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions eth/vm/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ def stack_push_int(self) -> Callable[[int], None]:
@cached_property
def stack_push_bytes(self) -> Callable[[bytes], None]:
return self._stack.push_bytes

#
# Return Stack Management
#
@cached_property
def rstack_push_int(self) -> Callable[[int], None]:
return self._rstack.push_int

@cached_property
def rstack_pop1_int(self) -> Callable[[int]], None]:
return self._rstack.pop1_int

#
# Computation result
Expand Down
16 changes: 8 additions & 8 deletions eth/vm/rstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
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 @@ -46,7 +53,7 @@ def push_int(self) -> int:
self._append((int, value))


def pop1_int(self) -> int:
def pop1_int(self) -> int:
#
# Note: This function is optimized for speed over readability.
#
Expand All @@ -61,10 +68,3 @@ def pop1_int(self) -> int:
else:
raise _busted_type(item_type, popped)

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}"
)


0 comments on commit b903b91

Please sign in to comment.