parent
326a333c8b
commit
6e01be34ef
3 changed files with 38 additions and 1 deletions
|
|
@ -2102,8 +2102,9 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph;
|
||||||
|
|
||||||
setupGlobalCtx(module, g)
|
setupGlobalCtx(module, g)
|
||||||
var c = PCtx g.vm
|
var c = PCtx g.vm
|
||||||
|
let oldMode = c.mode
|
||||||
|
c.mode = emStaticStmt
|
||||||
c.comesFromHeuristic.line = 0'u16
|
c.comesFromHeuristic.line = 0'u16
|
||||||
|
|
||||||
c.callsite = nOrig
|
c.callsite = nOrig
|
||||||
let start = genProc(c, sym)
|
let start = genProc(c, sym)
|
||||||
|
|
||||||
|
|
@ -2142,3 +2143,4 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph;
|
||||||
if cyclicTree(result): globalError(c.config, n.info, "macro produced a cyclic tree")
|
if cyclicTree(result): globalError(c.config, n.info, "macro produced a cyclic tree")
|
||||||
dec(g.config.evalMacroCounter)
|
dec(g.config.evalMacroCounter)
|
||||||
c.callsite = nil
|
c.callsite = nil
|
||||||
|
c.mode = oldMode
|
||||||
|
|
|
||||||
22
tests/tools/tnimscriptwithmacro.nims
Normal file
22
tests/tools/tnimscriptwithmacro.nims
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim e $file"
|
||||||
|
output: '''
|
||||||
|
foobar
|
||||||
|
nothing
|
||||||
|
hallo
|
||||||
|
"""
|
||||||
|
|
||||||
|
# this test ensures that the mode is resetted correctly to repr
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
macro foobar(): void =
|
||||||
|
result = newCall(bindSym"echo", newLit("nothing"))
|
||||||
|
|
||||||
|
echo "foobar"
|
||||||
|
|
||||||
|
let x = 123
|
||||||
|
|
||||||
|
foobar()
|
||||||
|
|
||||||
|
exec "echo hallo"
|
||||||
13
tests/vm/tgloballetfrommacro.nim
Normal file
13
tests/vm/tgloballetfrommacro.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot evaluate at compile time: BUILTIN_NAMES"
|
||||||
|
line: 11
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sets
|
||||||
|
|
||||||
|
let BUILTIN_NAMES = toSet(["int8", "int16", "int32", "int64"])
|
||||||
|
|
||||||
|
macro test*(): bool =
|
||||||
|
echo "int64" notin BUILTIN_NAMES
|
||||||
|
|
||||||
|
echo test()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue