move exception handler to executeOpcodes

This commit is contained in:
andri lim 2019-04-04 15:26:12 +07:00
parent 039256de6a
commit fb97d8d0ce
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 21 additions and 22 deletions

View File

@ -231,25 +231,14 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
# Wrap the case statement in while true + computed goto # Wrap the case statement in while true + computed goto
result = quote do: result = quote do:
try: if `computation`.tracingEnabled:
let fork = `computation`.getFork `computation`.prepareTracer()
if `computation`.execPrecompiles(fork): `computation`.instr = `computation`.code.next()
computation.nextProc() while true:
return {.computedGoto.}
# TODO lots of macro magic here to unravel, with chronicles...
if `computation`.tracingEnabled: # `computation`.logger.log($`computation`.stack & "\n\n", fgGreen)
`computation`.prepareTracer() `result`
`computation`.instr = `computation`.code.next()
while true:
{.computedGoto.}
# TODO lots of macro magic here to unravel, with chronicles...
# `computation`.logger.log($`computation`.stack & "\n\n", fgGreen)
`result`
except:
let msg = getCurrentExceptionMsg()
let errorMsg = "Opcode Dispatch Error msg=" & msg & ", depth=" & $computation.msg.depth
`computation`.setError(errorMsg, true)
computation.nextProc()
macro genFrontierDispatch(computation: BaseComputation): untyped = macro genFrontierDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(FrontierOpDispatch, computation) result = opTableToCaseStmt(FrontierOpDispatch, computation)
@ -263,10 +252,8 @@ proc frontierVM(computation: BaseComputation) =
proc homesteadVM(computation: BaseComputation) = proc homesteadVM(computation: BaseComputation) =
genHomesteadDispatch(computation) genHomesteadDispatch(computation)
proc executeOpcodes(computation: BaseComputation) = proc selectVM(computation: BaseComputation, fork: Fork) =
# TODO: Optimise getting fork and updating opCodeExec only when necessary # TODO: Optimise getting fork and updating opCodeExec only when necessary
let fork = computation.getFork
case fork case fork
of FkFrontier..FkThawing: of FkFrontier..FkThawing:
computation.frontierVM() computation.frontierVM()
@ -274,3 +261,15 @@ proc executeOpcodes(computation: BaseComputation) =
computation.homesteadVM() computation.homesteadVM()
else: else:
raise newException(VMError, "Unknown or not implemented fork: " & $fork) raise newException(VMError, "Unknown or not implemented fork: " & $fork)
proc executeOpcodes(computation: BaseComputation) =
try:
let fork = computation.getFork
if `computation`.execPrecompiles(fork):
computation.nextProc()
return
computation.selectVM(fork)
except:
let msg = getCurrentExceptionMsg()
computation.setError(&"Opcode Dispatch Error msg={msg}, depth={computation.msg.depth}", true)
computation.nextProc()