I am trying to write a macro for debug printing in Nim. Currently, this macro adds filenameand lineto the exit instantiationInfo().
import macros
macro debugPrint(msg: untyped): typed =
result = quote do:
let pos = instantiationInfo()
echo pos.filename, ":", pos.line, ": ", `msg`
proc hello() =
debugPrint "foo bar"
hello()
currently displays:
debug_print.nim:9: foo bar
I would like to add the name of the procedure (or iterator) of the place where the macro was called.
desired result:
debug_print.nim:9(proc hello): foo bar
How can I get the name of a procedure (or iterator) in Nim, for example __func__in C?
source
share