implement byzantium opcode dispatch
This commit is contained in:
parent
29a226da1e
commit
13cd54a382
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue