diff options
author | Araq <rumpf_a@web.de> | 2014-03-24 08:43:57 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-24 08:43:57 +0100 |
commit | ee1192679ebdfa58d812576c3a959656e9ebe097 (patch) | |
tree | 622165177fefe68b063ad36136d3adc97fd26628 /compiler/vmdef.nim | |
parent | e855f6c0735d4dec8b34084e439c6c215f12b155 (diff) | |
download | Nim-ee1192679ebdfa58d812576c3a959656e9ebe097.tar.gz |
VM: endless loop prevention
Diffstat (limited to 'compiler/vmdef.nim')
-rw-r--r-- | compiler/vmdef.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 7725d79b8..90ff8e29f 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -16,6 +16,9 @@ const byteExcess* = 128 # we use excess-K for immediates wordExcess* = 32768 + MaxLoopIterations* = 500_000 # max iterations of all loops + + type TRegister* = range[0..255] TDest* = range[-1 .. 255] @@ -110,6 +113,7 @@ type opcTJmp, # jump Bx if A != 0 opcFJmp, # jump Bx if A == 0 opcJmp, # jump Bx + opcJmpBack, # jump Bx; resulting from a while loop opcBranch, # branch for 'case' opcTry, opcExcept, @@ -182,6 +186,7 @@ type mode*: TEvalMode features*: TSandboxFlags traceActive*: bool + loopIterations*: int TPosition* = distinct int @@ -190,7 +195,7 @@ type proc newCtx*(module: PSym): PCtx = PCtx(code: @[], debug: @[], globals: newNode(nkStmtListExpr), constants: newNode(nkStmtList), types: @[], - prc: PProc(blocks: @[]), module: module) + prc: PProc(blocks: @[]), module: module, loopIterations: MaxLoopIterations) proc refresh*(c: PCtx, module: PSym) = c.module = module |