diff options
-rw-r--r-- | compiler/options.nim | 1 | ||||
-rw-r--r-- | compiler/vm.nim | 11 |
2 files changed, 6 insertions, 6 deletions
diff --git a/compiler/options.nim b/compiler/options.nim index 6cfaad9fb..04444f7c9 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -163,6 +163,7 @@ type globalOptions*: TGlobalOptions m*: MsgConfig evalTemplateCounter*: int + evalMacroCounter*: int exitcode*: int8 cmd*: TCommands # the command selectedGC*: TGCMode # the selected GC diff --git a/compiler/vm.nim b/compiler/vm.nim index e5613718f..8ae8523cf 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1748,13 +1748,12 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) = # to prevent endless recursion in macro instantiation const evalMacroLimit = 1000 -var evalMacroCounter: int proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph; n, nOrig: PNode, sym: PSym): PNode = # XXX globalError() is ugly here, but I don't know a better solution for now - inc(evalMacroCounter) - if evalMacroCounter > evalMacroLimit: + inc(g.config.evalMacroCounter) + if g.config.evalMacroCounter > evalMacroLimit: globalError(g.config, n.info, "macro instantiation too nested") # 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: tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ) else: - dec(evalMacroCounter) + dec(g.config.evalMacroCounter) c.callsite = nil localError(c.config, n.info, "expected " & $gp.len & " generic parameter(s)") elif gp[i].sym.typ.kind in {tyStatic, tyTypeDesc}: - dec(evalMacroCounter) + dec(g.config.evalMacroCounter) c.callsite = nil globalError(c.config, n.info, "static[T] or typedesc nor supported for .immediate macros") # temporary storage: @@ -1808,5 +1807,5 @@ proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph; result = rawExecute(c, start, tos).regToNode if result.info.line < 0: result.info = n.info if cyclicTree(result): globalError(c.config, n.info, "macro produced a cyclic tree") - dec(evalMacroCounter) + dec(g.config.evalMacroCounter) c.callsite = nil |