mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
* fix #20891 Illegal capture error of env its self * fix innerClosure too earlier, make condition shorter
29 lines
650 B
Nim
29 lines
650 B
Nim
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()
|