Last active
June 28, 2024 18:22
-
-
Save geekrelief/19e05cfdea62c1812b3cbe4ae7d201b1 to your computer and use it in GitHub Desktop.
A Nim debugEcho with file, line number, and callsite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/macros | |
# calls debugEcho with the lineInfo | |
macro here*(x: varargs[typed, `$`]):untyped {.noSideEffect.} = | |
{.cast(noSideEffect), warning[Deprecated]:off.}: # callsite is deprecated, there's no alternative: https://github.com/nim-lang/RFCs/issues/387 | |
result = newTree(nnkCommand, ident "debugEcho") | |
result.add newStrLitNode("--- " & x[0].lineInfo & " ---\n") | |
result.add newStrLitNode(" " & callsite().toStrLit().strVal & " -> \n") | |
for c in x: | |
result.add c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment