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
|
||||
# according to those terms.
|
||||
|
||||
## List of known Etheroum forks
|
||||
## List of known Ethereum forks
|
||||
## ============================
|
||||
##
|
||||
## See `here <../../ex/vm/interpreter/forks_list.html>`_ for an
|
||||
## 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
|
||||
Fork* = enum
|
||||
|
@ -35,9 +26,4 @@ type
|
|||
FkIstanbul = "istanbul"
|
||||
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
|
||||
|
|
|
@ -208,12 +208,6 @@ type
|
|||
SelfDestruct = 0xff ## Halt execution and register account for later
|
||||
## 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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -74,15 +74,13 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||
let branchOnOp = quote do: `opArg`
|
||||
result = nnkCaseStmt.newTree(branchOnOp)
|
||||
for op in Op:
|
||||
let asOp = quote do: Op(`op`)
|
||||
|
||||
# Inner case/switch => Fork
|
||||
let branchOnFork = quote do: `forkArg`
|
||||
var forkCaseSubExpr = nnkCaseStmt.newTree(branchOnFork)
|
||||
for fork in Fork:
|
||||
|
||||
let
|
||||
asFork = quote do: Fork(`fork`)
|
||||
asOp = quote do: Op(`op`)
|
||||
let asFork = quote do: Fork(`fork`)
|
||||
|
||||
let branchStmt = block:
|
||||
if op == Stop:
|
||||
|
@ -95,9 +93,7 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||
quote do:
|
||||
handleOtherDirective(`asFork`,`asOp`,`k`)
|
||||
|
||||
forkCaseSubExpr.add nnkOfBranch.newTree(
|
||||
newIdentNode(fork.toSymbolName),
|
||||
branchStmt)
|
||||
forkCaseSubExpr.add nnkOfBranch.newTree(asFork, branchStmt)
|
||||
|
||||
# Wrap innner case/switch into outer case/switch
|
||||
let branchStmt = block:
|
||||
|
@ -115,9 +111,7 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
|||
quote do:
|
||||
`forkCaseSubExpr`
|
||||
|
||||
result.add nnkOfBranch.newTree(
|
||||
newIdentNode(op.toSymbolName),
|
||||
branchStmt)
|
||||
result.add nnkOfBranch.newTree(asOp, branchStmt)
|
||||
|
||||
when isChatty:
|
||||
echo ">>> ", result.repr
|
||||
|
|
Loading…
Reference in New Issue