Skip to content

Commit e166ab0

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent 8e8703a commit e166ab0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

eth/vm/logic/flow.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from eth.vm.computation import BaseComputation
88
from eth.vm.opcode_values import (
99
JUMPDEST,
10+
BEGINSUB,
1011
)
1112

1213

@@ -57,3 +58,40 @@ def gas(computation: BaseComputation) -> None:
5758
gas_remaining = computation.get_gas_remaining()
5859

5960
computation.stack_push_int(gas_remaining)
61+
62+
63+
def beginsub(computation: BaseComputation) -> None:
64+
#TODO: raise OOG exception
65+
pass
66+
67+
68+
def jumpsub(computation: BaseComputation) -> None:
69+
sub_loc = computation.stack_pop1_int()
70+
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
82+
83+
if computation.rstack.length >= 1023:
84+
#TODO: abort execution
85+
pass
86+
87+
computation.rstack_push_int(temp + 1)
88+
89+
90+
def returnsub(computation: BaseComputation) -> None:
91+
92+
if computation.rstack.length == 0:
93+
#TODO: abort execution
94+
pass
95+
96+
computation.code.program_counter = computation.rstack_pop1_int()
97+

0 commit comments

Comments
 (0)