summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-10-04 17:24:42 +0300
committerZahary Karadjov <zahary@gmail.com>2012-10-04 17:24:42 +0300
commitf28b7be6a37d566df64cb944c1687e014be8d083 (patch)
tree04a62e99fd0b9df0e038d0dea6bd31ae4ff4f788
parentd9d82fb0af8688e7c847bb7b0c3b2e38f7c8a735 (diff)
downloadNim-f28b7be6a37d566df64cb944c1687e014be8d083.tar.gz
fixes #120
-rwxr-xr-xlib/core/macros.nim6
-rwxr-xr-xlib/system.nim5
2 files changed, 4 insertions, 7 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index c30474b70..be6aecab5 100755
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -234,16 +234,14 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst".}
   ##   macro FooMacro() =
   ##     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
   ## that should be inserted verbatim in the program
   ## Example:
   ##
   ##   emit("echo " & '"' & "hello world".toUpper & '"')
   ##
-  block:
-    const evaluated = s
-    eval: result = evaluated.parseStmt
+  eval: result = e.parseStmt
 
 proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
   ## checks that `n` is of kind `k`. If this is not the case,
diff --git a/lib/system.nim b/lib/system.nim
index 99f1e621a..9d7652c94 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2349,9 +2349,8 @@ template eval*(blk: stmt): stmt =
   ## 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 
   ## eval expression
-  block:
-    macro payload(x: stmt): stmt = blk
-    payload()
+  macro payload: stmt {.gensym.} = blk
+  payload()
 
 proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} = 
   ## inserts `item` into `x` at position `i`.