fixes #3046
This commit is contained in:
parent
2d196442fa
commit
60ac5e3e76
2 changed files with 22 additions and 2 deletions
|
|
@ -164,7 +164,7 @@ proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.}
|
||||||
## returns the `kind` of the node `n`.
|
## returns the `kind` of the node `n`.
|
||||||
|
|
||||||
proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
|
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 floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
|
||||||
proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.}
|
proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.}
|
||||||
proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.}
|
proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.}
|
||||||
|
|
@ -833,6 +833,10 @@ proc addIdentIfAbsent*(dest: NimNode, ident: string) {.compiletime.} =
|
||||||
else: discard
|
else: discard
|
||||||
dest.add(ident(ident))
|
dest.add(ident(ident))
|
||||||
|
|
||||||
|
proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} =
|
||||||
|
if n.kind == nnkIntLit: n.intVal != 0
|
||||||
|
else: n == bindSym"true" # hacky solution for now
|
||||||
|
|
||||||
when not defined(booting):
|
when not defined(booting):
|
||||||
template emit*(e: static[string]): stmt =
|
template emit*(e: static[string]): stmt =
|
||||||
## accepts a single string argument and treats it as nim code
|
## accepts a single string argument and treats it as nim code
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@ TTaa
|
||||||
TTaa
|
TTaa
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
nil'''
|
nil
|
||||||
|
42
|
||||||
|
false
|
||||||
|
true'''
|
||||||
|
|
||||||
output: '''test
|
output: '''test
|
||||||
2'''
|
2'''
|
||||||
|
|
@ -88,3 +91,16 @@ proc calc(): array[1, int] =
|
||||||
|
|
||||||
const c = calc()
|
const c = calc()
|
||||||
echo c[0]
|
echo c[0]
|
||||||
|
|
||||||
|
|
||||||
|
# bug #3046
|
||||||
|
|
||||||
|
macro sampleMacroInt(i: int): stmt =
|
||||||
|
echo i.intVal
|
||||||
|
|
||||||
|
macro sampleMacroBool(b: bool): stmt =
|
||||||
|
echo b.boolVal
|
||||||
|
|
||||||
|
sampleMacroInt(42)
|
||||||
|
sampleMacroBool(false)
|
||||||
|
sampleMacroBool(system.true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue