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 Sep 19, 2020
1 parent e377e53 commit 3960dce
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions eth/vm/logic/flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from eth.exceptions import (
InvalidJumpDestination,
InvalidInstruction,
OutOfGas,
Halt,
)

Expand Down Expand Up @@ -61,33 +62,29 @@ def gas(computation: BaseComputation) -> None:


def beginsub(computation: BaseComputation) -> None:
#TODO: raise OOG exception
pass
raise OutOfGas


def jumpsub(computation: BaseComputation) -> None:
sub_loc = computation.stack_pop1_int()

temp = computation.code.program_counter
computation.code.program_counter = sub_loc

next_opcode = computation.code.peek()

if next_opcode != BEGINSUB:
#TODO: abort execution
pass

else:
computation.code.program_counter += 1
if computation.code.is_valid_opcode(sub_loc):

computation.rstack_push_int(temp + 1)
sub_op = computation.code(sub_loc)

if sub_op == BEGINSUB:
temp = computation.code.program_counter
computation.code.program_counter = sub_loc + 1
computation.rstack_push_int(temp + 1)


def returnsub(computation: BaseComputation) -> None:

if computation.rstack.length == 0:
#TODO: abort execution
try:
ret_loc = computation.rstack_pop1_int()
except InsufficientStack:
pass


computation.code.program_counter = computation.rstack_pop1_int()
computation.code.program_counter = ret_loc

0 comments on commit 3960dce

Please sign in to comment.