* add vm value preparation proc * small optimization
This commit is contained in:
parent
12fc1dfb2c
commit
99a4fed96b
2 changed files with 32 additions and 3 deletions
|
|
@ -2031,12 +2031,29 @@ proc evalStaticStmt*(module: PSym; g: ModuleGraph; e: PNode, prc: PSym) =
|
||||||
proc setupCompileTimeVar*(module: PSym; g: ModuleGraph; n: PNode) =
|
proc setupCompileTimeVar*(module: PSym; g: ModuleGraph; n: PNode) =
|
||||||
discard evalConstExprAux(module, g, nil, n, emStaticStmt)
|
discard evalConstExprAux(module, g, nil, n, emStaticStmt)
|
||||||
|
|
||||||
|
proc prepareVMValue(arg: PNode): PNode =
|
||||||
|
## strip nkExprColonExpr from tuple values recurively. That is how
|
||||||
|
## they are expected to be stored in the VM.
|
||||||
|
|
||||||
|
# Early abort without copy. No transformation takes place.
|
||||||
|
if arg.kind in nkLiterals:
|
||||||
|
return arg
|
||||||
|
|
||||||
|
result = copyNode(arg)
|
||||||
|
if arg.kind == nkTupleConstr:
|
||||||
|
for child in arg:
|
||||||
|
if child.kind == nkExprColonExpr:
|
||||||
|
result.add prepareVMValue(child[1])
|
||||||
|
else:
|
||||||
|
result.add prepareVMValue(child)
|
||||||
|
else:
|
||||||
|
for child in arg:
|
||||||
|
result.add prepareVMValue(child)
|
||||||
|
|
||||||
proc setupMacroParam(x: PNode, typ: PType): TFullReg =
|
proc setupMacroParam(x: PNode, typ: PType): TFullReg =
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tyStatic:
|
of tyStatic:
|
||||||
putIntoReg(result, x)
|
putIntoReg(result, prepareVMValue(x))
|
||||||
#of tyTypeDesc:
|
|
||||||
# putIntoReg(result, x)
|
|
||||||
else:
|
else:
|
||||||
result.kind = rkNode
|
result.kind = rkNode
|
||||||
var n = x
|
var n = x
|
||||||
|
|
|
||||||
|
|
@ -49,3 +49,15 @@ myEnums = enumerators2()
|
||||||
echo myEnums
|
echo myEnums
|
||||||
myEnums = enumerators3()
|
myEnums = enumerators3()
|
||||||
echo myEnums
|
echo myEnums
|
||||||
|
|
||||||
|
#10751
|
||||||
|
|
||||||
|
type Tuple = tuple
|
||||||
|
a: string
|
||||||
|
b: int
|
||||||
|
|
||||||
|
macro foo(t: static Tuple): untyped =
|
||||||
|
doAssert t.a == "foo"
|
||||||
|
doAssert t.b == 12345
|
||||||
|
|
||||||
|
foo((a: "foo", b: 12345))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue