Added expandMacros macro
This commit is contained in:
parent
15f7094fde
commit
235fc29834
1 changed files with 24 additions and 0 deletions
|
|
@ -890,6 +890,30 @@ proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} =
|
||||||
if n.kind == nnkIntLit: n.intVal != 0
|
if n.kind == nnkIntLit: n.intVal != 0
|
||||||
else: n == bindSym"true" # hacky solution for now
|
else: n == bindSym"true" # hacky solution for now
|
||||||
|
|
||||||
|
macro expandMacros*(body: stmt): untyped =
|
||||||
|
## Expands one level of macro - useful for debugging.
|
||||||
|
## Can be used to inspect what happens when a macro call is expanded,
|
||||||
|
## without altering its result.
|
||||||
|
##
|
||||||
|
## For instance,
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## import future, macros
|
||||||
|
##
|
||||||
|
## let
|
||||||
|
## x = 10
|
||||||
|
## y = 20
|
||||||
|
## expandMacros:
|
||||||
|
## dump(x + y)
|
||||||
|
##
|
||||||
|
## will actually dump `x + y`, but at the same time will print at
|
||||||
|
## compile time the expansion of the ``dump`` macro, which in this
|
||||||
|
## case is ``debugEcho ["x + y", " = ", x + y]``.
|
||||||
|
template inner(x: untyped): untyped = x
|
||||||
|
|
||||||
|
result = getAst(inner(body))
|
||||||
|
echo result.toStrLit
|
||||||
|
|
||||||
when not defined(booting):
|
when not defined(booting):
|
||||||
template emit*(e: static[string]): untyped {.deprecated.} =
|
template emit*(e: static[string]): untyped {.deprecated.} =
|
||||||
## accepts a single string argument and treats it as nim code
|
## accepts a single string argument and treats it as nim code
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue