mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-27 04:26:07 +00:00
vm2: Remove toSymbolName
unnecessary symbol-text-symbol conversion
There's no need for macro `toSymbolName` to convert fork enum values to their presentation texts (logging etc) then re-parse them back to a fork enum value. `asFork` is already used in the same function and works without these steps, so use it consistently. Same applies to `op.toSymbolName` and `asOp`. This makes the code simpler, and removes a text pattern-matching requirement. The patch has been checked to confirm it doesn't change the compiled code. Motivation: The forks list will be removed from VM because it is used outside the VM as well. Doing so highlighted vm2's `toSymbolName`. It's not needed, and it's best if the VM doesn't constrain text strings used outside the VM Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
parent
8f9c593dac
commit
e2689792b0
@ -8,20 +8,11 @@
|
|||||||
# at your option. This file may not be copied, modified, or distributed except
|
# at your option. This file may not be copied, modified, or distributed except
|
||||||
# according to those terms.
|
# according to those terms.
|
||||||
|
|
||||||
## List of known Etheroum forks
|
## List of known Ethereum forks
|
||||||
## ============================
|
## ============================
|
||||||
##
|
##
|
||||||
## See `here <../../ex/vm/interpreter/forks_list.html>`_ for an
|
## See `here <../../ex/vm/interpreter/forks_list.html>`_ for an
|
||||||
## overview.
|
## overview.
|
||||||
##
|
|
||||||
## Assumptions on the naming of the fork list:
|
|
||||||
## * each symbol start with the prefix "Fk"
|
|
||||||
## * the first word of the prettified text representaion is the same
|
|
||||||
## text as the one following the "Fk" in the symbol name (irrespective
|
|
||||||
## of character case.)
|
|
||||||
|
|
||||||
import
|
|
||||||
strutils
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Fork* = enum
|
Fork* = enum
|
||||||
@ -35,9 +26,4 @@ type
|
|||||||
FkIstanbul = "istanbul"
|
FkIstanbul = "istanbul"
|
||||||
FkBerlin = "berlin"
|
FkBerlin = "berlin"
|
||||||
|
|
||||||
proc toSymbolName*(fork: Fork): string =
|
|
||||||
## Given a `fork` argument, print the symbol name so that it can be used
|
|
||||||
## in a macro statement.
|
|
||||||
"Fk" & ($fork).split(' ')[0]
|
|
||||||
|
|
||||||
# End
|
# End
|
||||||
|
@ -208,12 +208,6 @@ type
|
|||||||
SelfDestruct = 0xff ## Halt execution and register account for later
|
SelfDestruct = 0xff ## Halt execution and register account for later
|
||||||
## deletion.
|
## deletion.
|
||||||
|
|
||||||
|
|
||||||
proc toSymbolName*(op: Op): string =
|
|
||||||
## Given an `op` argument, print the symbol name so that it can be used
|
|
||||||
## in a macro statement.
|
|
||||||
$op
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Verify that Op is contiguous and sym names follow some standards
|
# Verify that Op is contiguous and sym names follow some standards
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -74,15 +74,13 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||||||
let branchOnOp = quote do: `opArg`
|
let branchOnOp = quote do: `opArg`
|
||||||
result = nnkCaseStmt.newTree(branchOnOp)
|
result = nnkCaseStmt.newTree(branchOnOp)
|
||||||
for op in Op:
|
for op in Op:
|
||||||
|
let asOp = quote do: Op(`op`)
|
||||||
|
|
||||||
# Inner case/switch => Fork
|
# Inner case/switch => Fork
|
||||||
let branchOnFork = quote do: `forkArg`
|
let branchOnFork = quote do: `forkArg`
|
||||||
var forkCaseSubExpr = nnkCaseStmt.newTree(branchOnFork)
|
var forkCaseSubExpr = nnkCaseStmt.newTree(branchOnFork)
|
||||||
for fork in Fork:
|
for fork in Fork:
|
||||||
|
let asFork = quote do: Fork(`fork`)
|
||||||
let
|
|
||||||
asFork = quote do: Fork(`fork`)
|
|
||||||
asOp = quote do: Op(`op`)
|
|
||||||
|
|
||||||
let branchStmt = block:
|
let branchStmt = block:
|
||||||
if op == Stop:
|
if op == Stop:
|
||||||
@ -95,9 +93,7 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||||||
quote do:
|
quote do:
|
||||||
handleOtherDirective(`asFork`,`asOp`,`k`)
|
handleOtherDirective(`asFork`,`asOp`,`k`)
|
||||||
|
|
||||||
forkCaseSubExpr.add nnkOfBranch.newTree(
|
forkCaseSubExpr.add nnkOfBranch.newTree(asFork, branchStmt)
|
||||||
newIdentNode(fork.toSymbolName),
|
|
||||||
branchStmt)
|
|
||||||
|
|
||||||
# Wrap innner case/switch into outer case/switch
|
# Wrap innner case/switch into outer case/switch
|
||||||
let branchStmt = block:
|
let branchStmt = block:
|
||||||
@ -115,9 +111,7 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||||||
quote do:
|
quote do:
|
||||||
`forkCaseSubExpr`
|
`forkCaseSubExpr`
|
||||||
|
|
||||||
result.add nnkOfBranch.newTree(
|
result.add nnkOfBranch.newTree(asOp, branchStmt)
|
||||||
newIdentNode(op.toSymbolName),
|
|
||||||
branchStmt)
|
|
||||||
|
|
||||||
when isChatty:
|
when isChatty:
|
||||||
echo ">>> ", result.repr
|
echo ">>> ", result.repr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user