interpreter dispatch simplification

This commit is contained in:
andri lim 2019-03-19 22:16:21 +07:00
parent 5fc93838d8
commit b73a1238e0
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 11 additions and 15 deletions

View File

@ -17,7 +17,7 @@ logScope:
topics = "vm opcode"
func invalidInstruction*(computation: var BaseComputation) {.inline.} =
raise newException(ValueError, "Invalid instruction, received an opcode not implemented in the current fork.")
raise newException(InvalidInstruction, "Invalid instruction, received an opcode not implemented in the current fork.")
let FrontierOpDispatch {.compileTime.}: array[Op, NimNode] = block:
fill_enum_table_holes(Op, newIdentNode("invalidInstruction")):
@ -256,24 +256,20 @@ proc homesteadVM(computation: var BaseComputation) =
if not computation.execPrecompiles:
genHomesteadDispatch(computation)
proc updateOpcodeExec*(computation: var BaseComputation, fork: Fork) =
case fork
of FkFrontier..FkThawing:
computation.opCodeExec = frontierVM
computation.frontierVM()
of FkHomestead..FkSpurious:
computation.opCodeExec = homesteadVM
computation.homesteadVM()
else:
raise newException(VMError, "Unknown or not implemented fork: " & $fork)
proc executeOpcodes*(computation: var BaseComputation) =
# TODO: Optimise getting fork and updating opCodeExec only when necessary
let fork = computation.getFork
try:
computation.updateOpcodeExec(fork)
case fork
of FkFrontier..FkThawing:
computation.opCodeExec = frontierVM
computation.frontierVM()
of FkHomestead..FkSpurious:
computation.opCodeExec = homesteadVM
computation.homesteadVM()
else:
raise newException(VMError, "Unknown or not implemented fork: " & $fork)
except VMError:
computation.error = Error(info: getCurrentExceptionMsg())
debug "VM Error executeOpcodes() failed", error = getCurrentExceptionMsg()
except EVMError:
debug "EVM Error executeOpcodes() failed", error = getCurrentExceptionMsg()