Skip to content

Instantly share code, notes, and snippets.

@geekrelief
Last active June 28, 2024 18:22
Show Gist options
  • Save geekrelief/19e05cfdea62c1812b3cbe4ae7d201b1 to your computer and use it in GitHub Desktop.
Save geekrelief/19e05cfdea62c1812b3cbe4ae7d201b1 to your computer and use it in GitHub Desktop.
A Nim debugEcho with file, line number, and callsite.
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