Skip to content

Commit

Permalink
Added a dump macro for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaferretti committed Sep 22, 2016
1 parent 723bc15 commit 15f7094
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/pure/future.nim
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,24 @@ macro `[]`*(lc: ListComprehension, comp, typ: untyped): untyped =
newIdentNode("@"),
newNimNode(nnkBracket))),
result))))


macro dump*(x: typed): untyped =
## Dumps the content of an expression, useful for debugging.
## It accepts any expression and prints a textual representation
## of the tree representing the expression - as it would appear in
## source code - together with the value of the expression.
##
## As an example,
##
## .. code-block:: nim
## let
## x = 10
## y = 20
## dump(x + y)
##
## will print ``x + y = 30``.
let s = x.toStrLit
let r = quote do:
debugEcho `s`, " = ", `x`
return r
13 changes: 13 additions & 0 deletions tests/macros/tdump.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
discard """
output: '''x = 10
x + y = 30
'''
"""

import future

let
x = 10
y = 20
dump x
dump(x + y)

0 comments on commit 15f7094

Please sign in to comment.