Skip to content

Commit 3960dce

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent e377e53 commit 3960dce

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

eth/vm/logic/flow.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from eth.exceptions import (
22
InvalidJumpDestination,
33
InvalidInstruction,
4+
OutOfGas,
45
Halt,
56
)
67

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

6263

6364
def beginsub(computation: BaseComputation) -> None:
64-
#TODO: raise OOG exception
65-
pass
65+
raise OutOfGas
6666

6767

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

71-
temp = computation.code.program_counter
72-
computation.code.program_counter = sub_loc
73-
74-
next_opcode = computation.code.peek()
75-
76-
if next_opcode != BEGINSUB:
77-
#TODO: abort execution
78-
pass
79-
80-
else:
81-
computation.code.program_counter += 1
71+
if computation.code.is_valid_opcode(sub_loc):
8272

83-
computation.rstack_push_int(temp + 1)
73+
sub_op = computation.code(sub_loc)
74+
75+
if sub_op == BEGINSUB:
76+
temp = computation.code.program_counter
77+
computation.code.program_counter = sub_loc + 1
78+
computation.rstack_push_int(temp + 1)
8479

8580

8681
def returnsub(computation: BaseComputation) -> None:
8782

88-
if computation.rstack.length == 0:
89-
#TODO: abort execution
83+
try:
84+
ret_loc = computation.rstack_pop1_int()
85+
except InsufficientStack:
9086
pass
87+
9188

92-
computation.code.program_counter = computation.rstack_pop1_int()
89+
computation.code.program_counter = ret_loc
9390

0 commit comments

Comments
 (0)