diff options
author | Andrea Ferretti <ferrettiandrea@gmail.com> | 2016-09-22 12:07:36 +0200 |
---|---|---|
committer | Andrea Ferretti <ferrettiandrea@gmail.com> | 2016-09-22 12:07:36 +0200 |
commit | 15f7094fde2a5677b6566dfa1a883237cac676ec (patch) | |
tree | 75fbb6fc9759a0433c9f6ca84c0077279c940ebe /lib/pure | |
parent | 723bc158cea494d3479573819f3e86ce0667409e (diff) | |
download | Nim-15f7094fde2a5677b6566dfa1a883237cac676ec.tar.gz |
Added a dump macro for debugging
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/future.nim | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/pure/future.nim b/lib/pure/future.nim index 67975cfcb..2a6d29933 100644 --- a/lib/pure/future.nim +++ b/lib/pure/future.nim @@ -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 \ No newline at end of file |