From 13cd54a382aa4185b5ff8ce6f50bf9bc6e759ab9 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 22 Apr 2019 16:26:59 +0700 Subject: [PATCH] implement byzantium opcode dispatch --- nimbus/vm/interpreter_dispatch.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index b1e9f41fd..a24530904 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -196,6 +196,12 @@ proc genSpuriousJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compile 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 = let instr = quote do: `computation`.instr @@ -263,6 +269,9 @@ macro genTangerineDispatch(computation: BaseComputation): untyped = macro genSpuriousDispatch(computation: BaseComputation): untyped = result = opTableToCaseStmt(SpuriousOpDispatch, computation) +macro genByzantiumDispatch(computation: BaseComputation): untyped = + result = opTableToCaseStmt(ByzantiumOpDispatch, computation) + proc frontierVM(computation: BaseComputation) = genFrontierDispatch(computation) @@ -275,6 +284,9 @@ proc tangerineVM(computation: BaseComputation) = proc spuriousVM(computation: BaseComputation) {.gcsafe.} = genSpuriousDispatch(computation) +proc byzantiumVM(computation: BaseComputation) {.gcsafe.} = + genByzantiumDispatch(computation) + proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} = # TODO: Optimise getting fork and updating opCodeExec only when necessary case fork @@ -286,6 +298,8 @@ proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} = computation.tangerineVM() of FkSpurious: computation.spuriousVM() + of FKByzantium: + computation.byzantiumVM() else: raise newException(VMError, "Unknown or not implemented fork: " & $fork)