fixes nested gensym'ed parameters; fixes #9476
This commit is contained in:
parent
7a0191ac7e
commit
e874705971
9 changed files with 82 additions and 23 deletions
|
|
@ -70,3 +70,43 @@ proc genericProc(x: any) =
|
|||
|
||||
concreteProc(7) # This works
|
||||
genericProc(7) # This doesn't compile
|
||||
|
||||
import tables
|
||||
|
||||
# bug #9476
|
||||
proc getTypeInfo*(T: typedesc): pointer =
|
||||
var dummy: T
|
||||
getTypeInfo(dummy)
|
||||
|
||||
|
||||
macro implementUnary(op: untyped): untyped =
|
||||
result = newStmtList()
|
||||
|
||||
template defineTable(tableSymbol) =
|
||||
var tableSymbol = initTable[pointer, pointer]()
|
||||
let tableSymbol = genSym(nskVar, "registeredProcs")
|
||||
result.add(getAst(defineTable(tableSymbol)))
|
||||
|
||||
template defineRegisterInstantiation(tableSym, regTemplSym, instSym, op) =
|
||||
template regTemplSym*(T: typedesc) =
|
||||
let ti = getTypeInfo(T)
|
||||
|
||||
proc instSym(xOrig: int): int {.gensym, cdecl.} =
|
||||
let x {.inject.} = xOrig
|
||||
op
|
||||
|
||||
tableSym[ti] = cast[pointer](instSym)
|
||||
|
||||
let regTemplSymbol = ident("registerInstantiation")
|
||||
let instSymbol = ident("instantiation")
|
||||
result.add(getAst(defineRegisterInstantiation(
|
||||
tableSymbol, regTemplSymbol, instSymbol, op
|
||||
)))
|
||||
|
||||
echo result.repr
|
||||
|
||||
|
||||
implementUnary(): x*x
|
||||
|
||||
registerInstantiation(int)
|
||||
registerInstantiation(float)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue