implement byzantium opcode dispatch

This commit is contained in:
andri lim 2019-04-22 16:26:59 +07:00
parent 29a226da1e
commit 13cd54a382
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 14 additions and 0 deletions

View File

@ -196,6 +196,12 @@ proc genSpuriousJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compile
let SpuriousOpDispatch {.compileTime.}: array[Op, NimNode] = genSpuriousJumpTable(TangerineOpDispatch) let SpuriousOpDispatch {.compileTime.}: array[Op, NimNode] = genSpuriousJumpTable(TangerineOpDispatch)
proc genByzantiumJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} =
result = ops
result[Revert] = newIdentNode "revert"
let ByzantiumOpDispatch {.compileTime.}: array[Op, NimNode] = genByzantiumJumpTable(SpuriousOpDispatch)
proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNode = proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNode =
let instr = quote do: `computation`.instr let instr = quote do: `computation`.instr
@ -263,6 +269,9 @@ macro genTangerineDispatch(computation: BaseComputation): untyped =
macro genSpuriousDispatch(computation: BaseComputation): untyped = macro genSpuriousDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(SpuriousOpDispatch, computation) result = opTableToCaseStmt(SpuriousOpDispatch, computation)
macro genByzantiumDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(ByzantiumOpDispatch, computation)
proc frontierVM(computation: BaseComputation) = proc frontierVM(computation: BaseComputation) =
genFrontierDispatch(computation) genFrontierDispatch(computation)
@ -275,6 +284,9 @@ proc tangerineVM(computation: BaseComputation) =
proc spuriousVM(computation: BaseComputation) {.gcsafe.} = proc spuriousVM(computation: BaseComputation) {.gcsafe.} =
genSpuriousDispatch(computation) genSpuriousDispatch(computation)
proc byzantiumVM(computation: BaseComputation) {.gcsafe.} =
genByzantiumDispatch(computation)
proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} = proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} =
# TODO: Optimise getting fork and updating opCodeExec only when necessary # TODO: Optimise getting fork and updating opCodeExec only when necessary
case fork case fork
@ -286,6 +298,8 @@ proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} =
computation.tangerineVM() computation.tangerineVM()
of FkSpurious: of FkSpurious:
computation.spuriousVM() computation.spuriousVM()
of FKByzantium:
computation.byzantiumVM()
else: else:
raise newException(VMError, "Unknown or not implemented fork: " & $fork) raise newException(VMError, "Unknown or not implemented fork: " & $fork)