evm: generate more specialized functions (#2390)
Nicer name in profiler and avoids a few range checks
This commit is contained in:
parent
86877004e6
commit
1a96b4a97c
|
@ -60,7 +60,7 @@ template read*(c: CodeStream, size: int): openArray[byte] =
|
|||
c.pc = c.bytes.len
|
||||
c.bytes.toOpenArray(0, -1)
|
||||
|
||||
proc readVmWord*(c: var CodeStream, n: int): UInt256 =
|
||||
proc readVmWord*(c: var CodeStream, n: static int): UInt256 =
|
||||
## Reads `n` bytes from the code stream and pads
|
||||
## the remaining bytes with zeros.
|
||||
let result_bytes = cast[ptr array[32, byte]](addr result)
|
||||
|
|
|
@ -19,7 +19,7 @@ import
|
|||
|
||||
type
|
||||
OphNumToTextFn* = proc(n: int): string
|
||||
OpHanldlerImplFn* = proc(k: var VmCtx; n: int): EvmResultVoid
|
||||
# OpHanldlerImplFn* = proc(k: var VmCtx; n: static int): EvmResultVoid
|
||||
|
||||
const
|
||||
recForkSet = "VmOpAllForks"
|
||||
|
@ -45,7 +45,7 @@ proc asText(id, name: string): NimNode {.compileTime.} =
|
|||
macro genOphHandlers*(runHandler: static[OphNumToTextFn];
|
||||
itemInfo: static[OphNumToTextFn];
|
||||
inxList: static[openArray[int]];
|
||||
body: static[OpHanldlerImplFn]): untyped =
|
||||
body: untyped): untyped =
|
||||
## Generate the equivalent of
|
||||
## ::
|
||||
## const <runHandler>: VmOpFn = proc (k: var VmCtx) =
|
||||
|
@ -63,7 +63,7 @@ macro genOphHandlers*(runHandler: static[OphNumToTextFn];
|
|||
|
||||
# => push##Op: VmOpFn = proc (k: var VmCtx) = ...
|
||||
result.add quote do:
|
||||
const `fnName`: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
|
||||
proc `fnName`(k: var VmCtx): EvmResultVoid =
|
||||
`comment`
|
||||
`body`(k,`n`)
|
||||
# echo ">>>", result.repr
|
||||
|
|
|
@ -49,8 +49,8 @@ proc fnInfo(n: int): string {.compileTime.} =
|
|||
"Append log record with " & $n & " " & blurb
|
||||
|
||||
|
||||
proc logImpl(c: Computation, opcode: Op, topicCount: int): EvmResultVoid =
|
||||
doAssert(topicCount in 0 .. 4)
|
||||
proc logImpl(c: Computation, opcode: Op, topicCount: static int): EvmResultVoid =
|
||||
static: doAssert(topicCount in 0 .. 4)
|
||||
? checkInStaticContext(c)
|
||||
let (memStartPosition, size) = ? c.stack.popInt(2)
|
||||
let (memPos, len) = (memStartPosition.cleanMemRef, size.cleanMemRef)
|
||||
|
@ -96,7 +96,7 @@ const
|
|||
# Private, op handlers implementation
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc wrapperFn(k: var VmCtx; n: int): EvmResultVoid =
|
||||
proc wrapperFn(k: var VmCtx; n: static int): EvmResultVoid =
|
||||
logImpl(k.cpt, logOpArg[n], n)
|
||||
|
||||
genOphHandlers fnName, fnInfo, inxRange, wrapperFn
|
||||
|
|
|
@ -40,7 +40,7 @@ proc fnInfo(n: int): string {.compileTime.} =
|
|||
"Push " & blurb & " on the stack"
|
||||
|
||||
|
||||
proc pushImpl(k: var VmCtx; n: int): EvmResultVoid =
|
||||
proc pushImpl(k: var VmCtx; n: static int): EvmResultVoid =
|
||||
k.cpt.stack.push k.cpt.code.readVmWord(n)
|
||||
|
||||
const
|
||||
|
|
|
@ -41,7 +41,7 @@ proc fnInfo(n: int): string {.compileTime.} =
|
|||
"Exchange first and " & blurb & " stack items"
|
||||
|
||||
|
||||
func swapImpl(k: var VmCtx; n: int): EvmResultVoid =
|
||||
func swapImpl(k: var VmCtx; n: static int): EvmResultVoid =
|
||||
k.cpt.stack.swap(n)
|
||||
|
||||
const
|
||||
|
|
Loading…
Reference in New Issue