From 83975543154f03b7803c1cb86a27e9c99e445b50 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 6 Sep 2019 07:23:59 +0200 Subject: [PATCH] fixes #12125 (#12131) * fixes #12125 --- compiler/scriptconfig.nim | 49 ++++++++++++++----- compiler/vm.nim | 23 +++++---- compiler/vmops.nim | 10 +++- ...t.nim => disabled_ttemplate_highlight.nim} | 0 4 files changed, 60 insertions(+), 22 deletions(-) rename nimsuggest/tests/{ttemplate_highlight.nim => disabled_ttemplate_highlight.nim} (100%) diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 9878cf597..2aca43b2b 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -62,9 +62,15 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; cbos listDirs: listDirs(a, {pcDir}) cbos removeDir: - os.removeDir getString(a, 0) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.removeDir getString(a, 0) cbos removeFile: - os.removeFile getString(a, 0) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.removeFile getString(a, 0) cbos createDir: os.createDir getString(a, 0) @@ -76,20 +82,35 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; cbos getCurrentDir: setResult(a, os.getCurrentDir()) cbos moveFile: - os.moveFile(getString(a, 0), getString(a, 1)) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.moveFile(getString(a, 0), getString(a, 1)) cbos moveDir: - os.moveDir(getString(a, 0), getString(a, 1)) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.moveDir(getString(a, 0), getString(a, 1)) cbos copyFile: - os.copyFile(getString(a, 0), getString(a, 1)) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.copyFile(getString(a, 0), getString(a, 1)) cbos copyDir: - os.copyDir(getString(a, 0), getString(a, 1)) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + os.copyDir(getString(a, 0), getString(a, 1)) cbos getLastModificationTime: setResult(a, getLastModificationTime(getString(a, 0)).toUnix) cbos findExe: setResult(a, os.findExe(getString(a, 0))) cbos rawExec: - setResult(a, osproc.execCmd getString(a, 0)) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + setResult(a, osproc.execCmd getString(a, 0)) cbconf getEnv: setResult(a, os.getEnv(a.getString 0, a.getString 1)) @@ -164,11 +185,17 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; cbconf cppDefine: options.cppDefine(conf, a.getString(0)) cbexc stdinReadLine, EOFError: - setResult(a, "") - setResult(a, stdin.readLine()) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + setResult(a, "") + setResult(a, stdin.readLine()) cbexc stdinReadAll, EOFError: - setResult(a, "") - setResult(a, stdin.readAll()) + if defined(nimsuggest) or graph.config.cmd == cmdCheck: + discard + else: + setResult(a, "") + setResult(a, stdin.readAll()) proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile; freshDefines=true; conf: ConfigRef) = diff --git a/compiler/vm.nim b/compiler/vm.nim index 072a1826b..f98eb9fcf 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1549,17 +1549,20 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = regs[ra].node.strVal = opSlurp(regs[rb].node.strVal, c.debug[pc], c.module, c.config) of opcGorge: - when defined(nimcore): - decodeBC(rkNode) - inc pc - let rd = c.code[pc].regA - - createStr regs[ra] - regs[ra].node.strVal = opGorge(regs[rb].node.strVal, - regs[rc].node.strVal, regs[rd].node.strVal, - c.debug[pc], c.config)[0] + if defined(nimsuggest) or c.config.cmd == cmdCheck: + discard "don't run staticExec for 'nim suggest'" else: - globalError(c.config, c.debug[pc], "VM is not built with 'gorge' support") + when defined(nimcore): + decodeBC(rkNode) + inc pc + let rd = c.code[pc].regA + + createStr regs[ra] + regs[ra].node.strVal = opGorge(regs[rb].node.strVal, + regs[rc].node.strVal, regs[rd].node.strVal, + c.debug[pc], c.config)[0] + else: + globalError(c.config, c.debug[pc], "VM is not built with 'gorge' support") of opcNError, opcNWarning, opcNHint: decodeB(rkNode) let a = regs[ra].node diff --git a/compiler/vmops.nim b/compiler/vmops.nim index b0325b5b0..fe3c2516b 100644 --- a/compiler/vmops.nim +++ b/compiler/vmops.nim @@ -77,6 +77,14 @@ template wrap2svoid(op, modop) {.dirty.} = op(getString(a, 0), getString(a, 1)) modop op +template wrapDangerous(op, modop) {.dirty.} = + proc `op Wrapper`(a: VmArgs) {.nimcall.} = + if defined(nimsuggest) or c.config.cmd == cmdCheck: + discard + else: + op(getString(a, 0), getString(a, 1)) + modop op + proc getCurrentExceptionMsgWrapper(a: VmArgs) {.nimcall.} = setResult(a, if a.currentException.isNil: "" else: a.currentException.sons[3].skipColon.strVal) @@ -133,7 +141,7 @@ proc registerAdditionalOps*(c: PCtx) = wrap2svoid(putEnv, osop) wrap1s(dirExists, osop) wrap1s(fileExists, osop) - wrap2svoid(writeFile, ioop) + wrapDangerous(writeFile, ioop) wrap1s(readFile, ioop) wrap2si(readLines, ioop) systemop getCurrentExceptionMsg diff --git a/nimsuggest/tests/ttemplate_highlight.nim b/nimsuggest/tests/disabled_ttemplate_highlight.nim similarity index 100% rename from nimsuggest/tests/ttemplate_highlight.nim rename to nimsuggest/tests/disabled_ttemplate_highlight.nim