From 15f7094fde2a5677b6566dfa1a883237cac676ec Mon Sep 17 00:00:00 2001 From: Andrea Ferretti Date: Thu, 22 Sep 2016 12:07:36 +0200 Subject: Added a dump macro for debugging --- lib/pure/future.nim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/pure') 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 -- cgit 1.4.1-2-gfad0