summary refs log tree commit diff stats
path: root/lib/core/macros.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-04-20 20:40:10 +0200
committerAraq <rumpf_a@web.de>2015-04-20 20:40:10 +0200
commit43eae0c11326df868c802e9b9f12c3be3d835fd9 (patch)
tree75355fce62986e78958425eeaeded13c42c630d6 /lib/core/macros.nim
parent2b4e233510ed45c924507110e19cc94f1d849125 (diff)
downloadNim-43eae0c11326df868c802e9b9f12c3be3d835fd9.tar.gz
macros: added bool literal support
Diffstat (limited to 'lib/core/macros.nim')
-rw-r--r--lib/core/macros.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index 777d991d4..35f0f61c1 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -164,6 +164,7 @@ proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.}
   ## returns the `kind` of the node `n`.
 
 proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
+proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} = n.intVal != 0
 proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
 proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.}
 proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.}
@@ -397,6 +398,11 @@ proc newLit*(i: BiggestInt): NimNode {.compileTime.} =
   result = newNimNode(nnkIntLit)
   result.intVal = i
 
+proc newLit*(b: bool): NimNode {.compileTime.} =
+  ## produces a new boolean literal node.
+  result = newNimNode(nnkIntLit)
+  result.intVal = ord(b)
+
 proc newLit*(f: BiggestFloat): NimNode {.compileTime.} =
   ## produces a new float literal node.
   result = newNimNode(nnkFloatLit)