This commit is contained in:
Zahary Karadjov 2012-10-04 17:24:42 +03:00
commit f28b7be6a3
2 changed files with 4 additions and 7 deletions

View file

@ -234,16 +234,14 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst".}
## macro FooMacro() = ## macro FooMacro() =
## var ast = getAst(BarTemplate()) ## var ast = getAst(BarTemplate())
template emit*(s: expr): stmt = template emit*(e: expr[string]): stmt =
## accepts a single string argument and treats it as nimrod code ## accepts a single string argument and treats it as nimrod code
## that should be inserted verbatim in the program ## that should be inserted verbatim in the program
## Example: ## Example:
## ##
## emit("echo " & '"' & "hello world".toUpper & '"') ## emit("echo " & '"' & "hello world".toUpper & '"')
## ##
block: eval: result = e.parseStmt
const evaluated = s
eval: result = evaluated.parseStmt
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} = proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
## checks that `n` is of kind `k`. If this is not the case, ## checks that `n` is of kind `k`. If this is not the case,

View file

@ -2349,8 +2349,7 @@ template eval*(blk: stmt): stmt =
## executes a block of code at compile time just as if it was a macro ## executes a block of code at compile time just as if it was a macro
## optionally, the block can return an AST tree that will replace the ## optionally, the block can return an AST tree that will replace the
## eval expression ## eval expression
block: macro payload: stmt {.gensym.} = blk
macro payload(x: stmt): stmt = blk
payload() payload()
proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} = proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} =