diff options
author | Araq <rumpf_a@web.de> | 2014-02-03 17:35:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-02-03 17:35:03 +0100 |
commit | 99352c1e4c4889b3b1050ee496818fe25ca7d171 (patch) | |
tree | 968e70f5aefb214cb9ee9a9eef6debbcce38baf4 /lib/core | |
parent | c30f6cfcf11cf5e61d708db476d7a6fcb62aab23 (diff) | |
download | Nim-99352c1e4c4889b3b1050ee496818fe25ca7d171.tar.gz |
macro tests almost green
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/macros.nim | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 3b36e31e0..585ccf869 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -294,19 +294,6 @@ proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst".} ## if not `ex`: ## echo `info` & ": Check failed: " & `expString` -when not defined(booting): - template emit*(e: static[string]): stmt = - ## accepts a single string argument and treats it as nimrod code - ## that should be inserted verbatim in the program - ## Example: - ## - ## .. code-block:: nimrod - ## emit("echo " & '"' & "hello world".toUpper & '"') - ## - macro payload: stmt {.gensym.} = - result = e.parseStmt - payload() - proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} = ## checks that `n` is of kind `k`. If this is not the case, ## compilation aborts with an error message. This is useful for writing @@ -421,7 +408,8 @@ proc lispRepr*(n: PNimrodNode): string {.compileTime.} = of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal) of nnkIdent: add(result, "!\"" & $n.ident & '"') - of nnkSym, nnkNone: assert false + of nnkSym: add(result, $n.symbol) + of nnkNone: assert false else: add(result, lispRepr(n[0])) for j in 1..n.len-1: @@ -745,3 +733,15 @@ proc addIdentIfAbsent*(dest: PNimrodNode, ident: string) {.compiletime.} = else: discard dest.add(ident(ident)) +when not defined(booting): + template emit*(e: static[string]): stmt = + ## accepts a single string argument and treats it as nimrod code + ## that should be inserted verbatim in the program + ## Example: + ## + ## .. code-block:: nimrod + ## emit("echo " & '"' & "hello world".toUpper & '"') + ## + macro payload: stmt {.gensym.} = + result = parseStmt(e) + payload() |