1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import macros, tables
var mapping {.compileTime.}: Table[string, NimNode]
macro register(a: static[string], b: typed): untyped =
mapping[a] = b
macro getPtr(a: static[string]): untyped =
result = mapping[a]
proc foo() =
iterator it() {.closure.} =
discard
proc getIterPtr(): pointer {.nimcall.} =
rawProc(it)
register("foo", getIterPtr())
discard getIterPtr() # Comment either this to make it work
foo() # or this
proc bar() =
iterator it() {.closure.} =
discard getPtr("foo") # Or this
discard
proc getIterPtr(): pointer {.nimcall.} =
rawProc(it)
register("bar", getIterPtr())
discard getIterPtr()
bar()
|