vm.nim: evalMacroCounter is not a global variable anymore

This commit is contained in:
Andreas Rumpf 2018-05-28 13:57:16 +02:00
commit 5d45e630c5
2 changed files with 6 additions and 6 deletions

View file

@ -163,6 +163,7 @@ type
globalOptions*: TGlobalOptions globalOptions*: TGlobalOptions
m*: MsgConfig m*: MsgConfig
evalTemplateCounter*: int evalTemplateCounter*: int
evalMacroCounter*: int
exitcode*: int8 exitcode*: int8
cmd*: TCommands # the command cmd*: TCommands # the command
selectedGC*: TGCMode # the selected GC selectedGC*: TGCMode # the selected GC

View file

@ -1748,13 +1748,12 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
# to prevent endless recursion in macro instantiation # to prevent endless recursion in macro instantiation
const evalMacroLimit = 1000 const evalMacroLimit = 1000
var evalMacroCounter: int
proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph; proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph;
n, nOrig: PNode, sym: PSym): PNode = n, nOrig: PNode, sym: PSym): PNode =
# XXX globalError() is ugly here, but I don't know a better solution for now # XXX globalError() is ugly here, but I don't know a better solution for now
inc(evalMacroCounter) inc(g.config.evalMacroCounter)
if evalMacroCounter > evalMacroLimit: if g.config.evalMacroCounter > evalMacroLimit:
globalError(g.config, n.info, "macro instantiation too nested") globalError(g.config, n.info, "macro instantiation too nested")
# immediate macros can bypass any type and arity checking so we check the # immediate macros can bypass any type and arity checking so we check the
@ -1795,12 +1794,12 @@ proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph;
if idx < n.len: if idx < n.len:
tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ) tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ)
else: else:
dec(evalMacroCounter) dec(g.config.evalMacroCounter)
c.callsite = nil c.callsite = nil
localError(c.config, n.info, "expected " & $gp.len & localError(c.config, n.info, "expected " & $gp.len &
" generic parameter(s)") " generic parameter(s)")
elif gp[i].sym.typ.kind in {tyStatic, tyTypeDesc}: elif gp[i].sym.typ.kind in {tyStatic, tyTypeDesc}:
dec(evalMacroCounter) dec(g.config.evalMacroCounter)
c.callsite = nil c.callsite = nil
globalError(c.config, n.info, "static[T] or typedesc nor supported for .immediate macros") globalError(c.config, n.info, "static[T] or typedesc nor supported for .immediate macros")
# temporary storage: # temporary storage:
@ -1808,5 +1807,5 @@ proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph;
result = rawExecute(c, start, tos).regToNode result = rawExecute(c, start, tos).regToNode
if result.info.line < 0: result.info = n.info if result.info.line < 0: result.info = n.info
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(evalMacroCounter) dec(g.config.evalMacroCounter)
c.callsite = nil c.callsite = nil