I'm trying to write a helper macro that takes in an untyped argument and converts it directly into the appropriate NimNode. what I've ended up doing is
var nimNodes{.compiletime.} = seq[NimNode]
var nimNodeIndex{.compiletime.} = 0
macro toNimNode(x: untyped):int =
nimNodes.add(x)
result = newLit(nimNodeIndex)
inc nimNodeIndex
and then using the returned index as a fake pointer. This is the kludgiest of kludges; is there a cleaner way that I'm not seeing?
Motivating example: building a compiletime Table[string,NimNode] or Table[NimTypeKind,NimNode] for another macro to use.
untyped are automatically converted to NimNode.
For your final use-case, look into the code of Synthesis:
https://github.com/mratsim/Synthesis/blob/09bef6df/synthesis/factory.nim#L79-L111