diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-08-14 01:51:25 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-08-14 01:51:25 +0200 |
commit | b3abcaf9e88b12aeb33809d462835bb84a156249 (patch) | |
tree | 60fb6390e17e57a388076108996c66921975d5b9 /compiler/vm.nim | |
parent | ad245dbd77eb8c4b49d4c7df7d7458184aff07cf (diff) | |
parent | fe124ceadc887f0ae4aa09e9af4fe96b91df670a (diff) | |
download | Nim-b3abcaf9e88b12aeb33809d462835bb84a156249.tar.gz |
Merge pull request #3177 from zah/generic-types-in-macros
Generic types in macros
Diffstat (limited to 'compiler/vm.nim')
-rw-r--r-- | compiler/vm.nim | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index e381af97f..b1d71d73b 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1467,12 +1467,20 @@ proc evalStaticStmt*(module: PSym, e: PNode, prc: PSym) = proc setupCompileTimeVar*(module: PSym, n: PNode) = discard evalConstExprAux(module, nil, n, emStaticStmt) -proc setupMacroParam(x: PNode): PNode = - result = x - if result.kind in {nkHiddenSubConv, nkHiddenStdConv}: result = result.sons[1] - result = canonValue(result) - result.flags.incl nfIsRef - result.typ = x.typ +proc setupMacroParam(x: PNode, typ: PType): TFullReg = + case typ.kind + of tyStatic: + putIntoReg(result, x) + of tyTypeDesc: + putIntoReg(result, x) + else: + result.kind = rkNode + var n = x + if n.kind in {nkHiddenSubConv, nkHiddenStdConv}: n = n.sons[1] + n = n.canonValue + n.flags.incl nfIsRef + n.typ = x.typ + result.node = n var evalMacroCounter: int @@ -1508,10 +1516,17 @@ proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode = # return value: tos.slots[0].kind = rkNode tos.slots[0].node = newNodeIT(nkEmpty, n.info, sym.typ.sons[0]) + # setup parameters: - for i in 1 .. < min(tos.slots.len, L): - tos.slots[i].kind = rkNode - tos.slots[i].node = setupMacroParam(n.sons[i]) + for i in 1.. <sym.typ.len: + tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i]) + + if sfImmediate notin sym.flags: + let gp = sym.ast[genericParamsPos] + for i in 0 .. <gp.len: + let idx = sym.typ.len + i + tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ) + # temporary storage: #for i in L .. <maxSlots: tos.slots[i] = newNode(nkEmpty) result = rawExecute(c, start, tos).regToNode |