VM: allow overriding MaxLoopIterations without rebuilding nim (#13233)

This commit is contained in:
Timothee Cour 2020-01-23 01:53:30 -08:00 • committed by Andreas Rumpf
commit b462baed65
6 changed files with 13 additions and 10 deletions

View file

@ -486,11 +486,11 @@ proc compile(c: PCtx, s: PSym): int =
template handleJmpBack() {.dirty.} =
if c.loopIterations <= 0:
if allowInfiniteLoops in c.features:
c.loopIterations = MaxLoopIterations
c.loopIterations = c.config.maxLoopIterationsVM
else:
msgWriteln(c.config, "stack trace: (most recent call last)")
stackTraceAux(c, tos, pc)
globalError(c.config, c.debug[pc], errTooManyIterations)
globalError(c.config, c.debug[pc], errTooManyIterations % $c.config.maxLoopIterationsVM)
dec(c.loopIterations)
proc recSetFlagIsRef(arg: PNode) =
@ -513,8 +513,7 @@ const
errConstantDivisionByZero = "division by zero"
errIllegalConvFromXtoY = "illegal conversion from '$1' to '$2'"
errTooManyIterations = "interpretation requires too many iterations; " &
"if you are sure this is not a bug in your code edit " &
"compiler/vmdef.MaxLoopIterations and rebuild the compiler"
"if you are sure this is not a bug in your code, compile with `--maxLoopIterationsVM:number` (current value: $1)"
errFieldXNotFound = "node lacks field: "
proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =