parent
2a59f499e9
commit
059a16b34d
2 changed files with 19 additions and 2 deletions
|
|
@ -70,3 +70,21 @@ macro makeProc(): typed =
|
|||
makeProc()
|
||||
|
||||
someProc()
|
||||
|
||||
# bug #12193
|
||||
import macros, strutils
|
||||
|
||||
macro gen(T: typedesc): untyped =
|
||||
let typeSym = getTypeImpl(T)[1]
|
||||
let param = genSym(nskParam, "s")
|
||||
let value = nnkBracketExpr.newTree(param, newIntLitNode(0))
|
||||
result = newProc(
|
||||
name = ident"pack",
|
||||
params = [typeSym,
|
||||
newIdentDefs(param, nnkBracketExpr.newTree(ident"seq", ident"string"))],
|
||||
body = newStmtList(newCall(typeSym, newCall(bindSym"parseInt", value))),
|
||||
procType = nnkTemplateDef)
|
||||
echo repr result
|
||||
|
||||
gen(int)
|
||||
let i = pack(@["2"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue