refactoring complete: explicit ident cache

This commit is contained in:
Araq 2016-10-31 19:47:20 +01:00
commit 29db0d8585
16 changed files with 94 additions and 93 deletions

View file

@ -1174,7 +1174,7 @@ proc newModule(module: PSym): BModule =
if (sfDeadCodeElim in module.flags): if (sfDeadCodeElim in module.flags):
internalError("added pending module twice: " & module.filename) internalError("added pending module twice: " & module.filename)
proc myOpen(module: PSym): PPassContext = proc myOpen(module: PSym; cache: IdentCache): PPassContext =
result = newModule(module) result = newModule(module)
if optGenIndex in gGlobalOptions and generatedHeader == nil: if optGenIndex in gGlobalOptions and generatedHeader == nil:
let f = if headerFile.len > 0: headerFile else: gProjectFull let f = if headerFile.len > 0: headerFile else: gProjectFull

View file

@ -46,7 +46,7 @@ proc generateDot(project: string) =
rope(changeFileExt(extractFilename(project), "")), gDotGraph], rope(changeFileExt(extractFilename(project), "")), gDotGraph],
changeFileExt(project, "dot")) changeFileExt(project, "dot"))
proc myOpen(module: PSym): PPassContext = proc myOpen(module: PSym; cache: IdentCache): PPassContext =
var g: PGen var g: PGen
new(g) new(g)
g.module = module g.module = module

View file

@ -49,7 +49,7 @@ proc processNodeJson(c: PPassContext, n: PNode): PNode =
var g = PGen(c) var g = PGen(c)
generateJson(g.doc, n) generateJson(g.doc, n)
proc myOpen(module: PSym): PPassContext = proc myOpen(module: PSym; cache: IdentCache): PPassContext =
var g: PGen var g: PGen
new(g) new(g)
g.module = module g.module = module

View file

@ -83,10 +83,6 @@ proc isLetLocation(m: PNode, isApprox: bool): bool =
proc interestingCaseExpr*(m: PNode): bool = isLetLocation(m, true) proc interestingCaseExpr*(m: PNode): bool = isLetLocation(m, true)
let
opNot* = createMagic("not", mNot)
opContains* = createMagic("contains", mInSet)
let let
opLe = createMagic("<=", mLeI) opLe = createMagic("<=", mLeI)
opLt = createMagic("<", mLtI) opLt = createMagic("<", mLtI)

View file

@ -112,9 +112,6 @@ proc getIdent*(self: IdentCache; identifier: string): PIdent =
proc getIdent*(self: IdentCache; identifier: string, h: Hash): PIdent = proc getIdent*(self: IdentCache; identifier: string, h: Hash): PIdent =
result = getIdent(cstring(identifier), len(identifier), h) result = getIdent(cstring(identifier), len(identifier), h)
proc identEq*(self: IdentCache; id: PIdent, name: string): bool =
result = id.id == getIdent(name).id
proc newIdentCache*(): IdentCache = proc newIdentCache*(): IdentCache =
if legacy.isNil: if legacy.isNil:
result = IdentCache() result = IdentCache()
@ -135,4 +132,6 @@ proc whichKeyword*(id: PIdent): TSpecialWord =
proc getIdent*(identifier: string): PIdent = proc getIdent*(identifier: string): PIdent =
## for backwards compatibility. ## for backwards compatibility.
if legacy.isNil:
discard newIdentCache()
legacy.getIdent identifier legacy.getIdent identifier

View file

@ -2276,7 +2276,7 @@ proc myOpenCached(s: PSym, rd: PRodReader): PPassContext =
internalError("symbol files are not possible with the JS code generator") internalError("symbol files are not possible with the JS code generator")
result = nil result = nil
proc myOpen(s: PSym): PPassContext = proc myOpen(s: PSym; cache: IdentCache): PPassContext =
var r = newModule(s) var r = newModule(s)
r.target = if gCmd == cmdCompileToPHP: targetPHP else: targetJS r.target = if gCmd == cmdCompileToPHP: targetPHP else: targetJS
result = r result = r

View file

@ -42,6 +42,10 @@ proc createMagic*(name: string, m: TMagic): PSym =
result = newSym(skProc, getIdent(name), nil, unknownLineInfo()) result = newSym(skProc, getIdent(name), nil, unknownLineInfo())
result.magic = m result.magic = m
let
opNot* = createMagic("not", mNot)
opContains* = createMagic("contains", mInSet)
proc getSysMagic*(name: string, m: TMagic): PSym = proc getSysMagic*(name: string, m: TMagic): PSym =
var ti: TIdentIter var ti: TIdentIter
let id = getIdent(name) let id = getIdent(name)

View file

@ -30,39 +30,39 @@ proc semanticPasses =
registerPass verbosePass registerPass verbosePass
registerPass semPass registerPass semPass
proc commandGenDepend = proc commandGenDepend(cache: IdentCache) =
semanticPasses() semanticPasses()
registerPass(gendependPass) registerPass(gendependPass)
registerPass(cleanupPass) registerPass(cleanupPass)
compileProject() compileProject(cache)
generateDot(gProjectFull) generateDot(gProjectFull)
execExternalProgram("dot -Tpng -o" & changeFileExt(gProjectFull, "png") & execExternalProgram("dot -Tpng -o" & changeFileExt(gProjectFull, "png") &
' ' & changeFileExt(gProjectFull, "dot")) ' ' & changeFileExt(gProjectFull, "dot"))
proc commandCheck = proc commandCheck(cache: IdentCache) =
msgs.gErrorMax = high(int) # do not stop after first error msgs.gErrorMax = high(int) # do not stop after first error
defineSymbol("nimcheck") defineSymbol("nimcheck")
semanticPasses() # use an empty backend for semantic checking only semanticPasses() # use an empty backend for semantic checking only
rodPass() rodPass()
compileProject() compileProject(cache)
proc commandDoc2(json: bool) = proc commandDoc2(cache: IdentCache; json: bool) =
msgs.gErrorMax = high(int) # do not stop after first error msgs.gErrorMax = high(int) # do not stop after first error
semanticPasses() semanticPasses()
if json: registerPass(docgen2JsonPass) if json: registerPass(docgen2JsonPass)
else: registerPass(docgen2Pass) else: registerPass(docgen2Pass)
#registerPass(cleanupPass()) #registerPass(cleanupPass())
compileProject() compileProject(cache)
finishDoc2Pass(gProjectName) finishDoc2Pass(gProjectName)
proc commandCompileToC = proc commandCompileToC(cache: IdentCache) =
extccomp.initVars() extccomp.initVars()
semanticPasses() semanticPasses()
registerPass(cgenPass) registerPass(cgenPass)
rodPass() rodPass()
#registerPass(cleanupPass()) #registerPass(cleanupPass())
compileProject() compileProject(cache)
cgenWriteModules() cgenWriteModules()
if gCmd != cmdRun: if gCmd != cmdRun:
extccomp.callCCompiler(changeFileExt(gProjectFull, "")) extccomp.callCCompiler(changeFileExt(gProjectFull, ""))
@ -103,7 +103,7 @@ proc commandCompileToC =
ccgutils.resetCaches() ccgutils.resetCaches()
GC_fullCollect() GC_fullCollect()
proc commandCompileToJS = proc commandCompileToJS(cache: IdentCache) =
#incl(gGlobalOptions, optSafeCode) #incl(gGlobalOptions, optSafeCode)
setTarget(osJS, cpuJS) setTarget(osJS, cpuJS)
#initDefines() #initDefines()
@ -113,9 +113,9 @@ proc commandCompileToJS =
if gCmd == cmdCompileToPHP: defineSymbol("nimphp") if gCmd == cmdCompileToPHP: defineSymbol("nimphp")
semanticPasses() semanticPasses()
registerPass(JSgenPass) registerPass(JSgenPass)
compileProject() compileProject(cache)
proc interactivePasses = proc interactivePasses(cache: IdentCache) =
#incl(gGlobalOptions, optSafeCode) #incl(gGlobalOptions, optSafeCode)
#setTarget(osNimrodVM, cpuNimrodVM) #setTarget(osNimrodVM, cpuNimrodVM)
initDefines() initDefines()
@ -125,30 +125,30 @@ proc interactivePasses =
registerPass(semPass) registerPass(semPass)
registerPass(evalPass) registerPass(evalPass)
proc commandInteractive = proc commandInteractive(cache: IdentCache) =
msgs.gErrorMax = high(int) # do not stop after first error msgs.gErrorMax = high(int) # do not stop after first error
interactivePasses() interactivePasses(cache)
compileSystemModule() compileSystemModule(cache)
if commandArgs.len > 0: if commandArgs.len > 0:
discard compileModule(fileInfoIdx(gProjectFull), {}) discard compileModule(fileInfoIdx(gProjectFull), cache, {})
else: else:
var m = makeStdinModule() var m = makeStdinModule()
incl(m.flags, sfMainModule) incl(m.flags, sfMainModule)
processModule(m, llStreamOpenStdIn(), nil) processModule(m, llStreamOpenStdIn(), nil, cache)
const evalPasses = [verbosePass, semPass, evalPass] const evalPasses = [verbosePass, semPass, evalPass]
proc evalNim(nodes: PNode, module: PSym) = proc evalNim(nodes: PNode, module: PSym; cache: IdentCache) =
carryPasses(nodes, module, evalPasses) carryPasses(nodes, module, cache, evalPasses)
proc commandEval(exp: string) = proc commandEval(cache: IdentCache; exp: string) =
if systemModule == nil: if systemModule == nil:
interactivePasses() interactivePasses(cache)
compileSystemModule() compileSystemModule(cache)
var echoExp = "echo \"eval\\t\", " & "repr(" & exp & ")" let echoExp = "echo \"eval\\t\", " & "repr(" & exp & ")"
evalNim(echoExp.parseString, makeStdinModule()) evalNim(echoExp.parseString(cache), makeStdinModule(), cache)
proc commandScan = proc commandScan(cache: IdentCache) =
var f = addFileExt(mainCommandArg(), NimExt) var f = addFileExt(mainCommandArg(), NimExt)
var stream = llStreamOpen(f, fmRead) var stream = llStreamOpen(f, fmRead)
if stream != nil: if stream != nil:
@ -156,7 +156,7 @@ proc commandScan =
L: TLexer L: TLexer
tok: TToken tok: TToken
initToken(tok) initToken(tok)
openLexer(L, f, stream) openLexer(L, f, stream, cache)
while true: while true:
rawGetTok(L, tok) rawGetTok(L, tok)
printTok(tok) printTok(tok)
@ -165,16 +165,16 @@ proc commandScan =
else: else:
rawMessage(errCannotOpenFile, f) rawMessage(errCannotOpenFile, f)
proc commandSuggest = proc commandSuggest(cache: IdentCache) =
if isServing: if isServing:
# XXX: hacky work-around ahead # XXX: hacky work-around ahead
# Currently, it's possible to issue a idetools command, before # Currently, it's possible to issue a idetools command, before
# issuing the first compile command. This will leave the compiler # issuing the first compile command. This will leave the compiler
# cache in a state where "no recompilation is necessary", but the # cache in a state where "no recompilation is necessary", but the
# cgen pass was never executed at all. # cgen pass was never executed at all.
commandCompileToC() commandCompileToC(cache)
let gDirtyBufferIdx = gTrackPos.fileIndex let gDirtyBufferIdx = gTrackPos.fileIndex
discard compileModule(gDirtyBufferIdx, {sfDirty}) discard compileModule(gDirtyBufferIdx, cache, {sfDirty})
resetModule(gDirtyBufferIdx) resetModule(gDirtyBufferIdx)
else: else:
msgs.gErrorMax = high(int) # do not stop after first error msgs.gErrorMax = high(int) # do not stop after first error
@ -184,7 +184,7 @@ proc commandSuggest =
# but doesn't handle the case when it's imported module # but doesn't handle the case when it's imported module
#var projFile = if gProjectMainIdx == gDirtyOriginalIdx: gDirtyBufferIdx #var projFile = if gProjectMainIdx == gDirtyOriginalIdx: gDirtyBufferIdx
# else: gProjectMainIdx # else: gProjectMainIdx
compileProject() #(projFile) compileProject(cache) #(projFile)
proc resetMemory = proc resetMemory =
resetCompilationLists() resetCompilationLists()
@ -249,28 +249,28 @@ proc mainCommand*(cache: IdentCache) =
of "c", "cc", "compile", "compiletoc": of "c", "cc", "compile", "compiletoc":
# compile means compileToC currently # compile means compileToC currently
gCmd = cmdCompileToC gCmd = cmdCompileToC
commandCompileToC() commandCompileToC(cache)
of "cpp", "compiletocpp": of "cpp", "compiletocpp":
gCmd = cmdCompileToCpp gCmd = cmdCompileToCpp
defineSymbol("cpp") defineSymbol("cpp")
commandCompileToC() commandCompileToC(cache)
of "objc", "compiletooc": of "objc", "compiletooc":
gCmd = cmdCompileToOC gCmd = cmdCompileToOC
defineSymbol("objc") defineSymbol("objc")
commandCompileToC() commandCompileToC(cache)
of "run": of "run":
gCmd = cmdRun gCmd = cmdRun
when hasTinyCBackend: when hasTinyCBackend:
extccomp.setCC("tcc") extccomp.setCC("tcc")
commandCompileToC() commandCompileToC(cache)
else: else:
rawMessage(errInvalidCommandX, command) rawMessage(errInvalidCommandX, command)
of "js", "compiletojs": of "js", "compiletojs":
gCmd = cmdCompileToJS gCmd = cmdCompileToJS
commandCompileToJS() commandCompileToJS(cache)
of "php": of "php":
gCmd = cmdCompileToPHP gCmd = cmdCompileToPHP
commandCompileToJS() commandCompileToJS(cache)
of "doc": of "doc":
wantMainModule() wantMainModule()
gCmd = cmdDoc gCmd = cmdDoc
@ -280,7 +280,7 @@ proc mainCommand*(cache: IdentCache) =
gCmd = cmdDoc gCmd = cmdDoc
loadConfigs(DocConfig, cache) loadConfigs(DocConfig, cache)
defineSymbol("nimdoc") defineSymbol("nimdoc")
commandDoc2(false) commandDoc2(cache, false)
of "rst2html": of "rst2html":
gCmd = cmdRst2html gCmd = cmdRst2html
loadConfigs(DocConfig, cache) loadConfigs(DocConfig, cache)
@ -301,14 +301,14 @@ proc mainCommand*(cache: IdentCache) =
loadConfigs(DocConfig, cache) loadConfigs(DocConfig, cache)
wantMainModule() wantMainModule()
defineSymbol("nimdoc") defineSymbol("nimdoc")
commandDoc2(true) commandDoc2(cache, true)
of "buildindex": of "buildindex":
gCmd = cmdDoc gCmd = cmdDoc
loadConfigs(DocConfig, cache) loadConfigs(DocConfig, cache)
commandBuildIndex() commandBuildIndex()
of "gendepend": of "gendepend":
gCmd = cmdGenDepend gCmd = cmdGenDepend
commandGenDepend() commandGenDepend(cache)
of "dump": of "dump":
gCmd = cmdDump gCmd = cmdDump
if getConfigVar("dump.format") == "json": if getConfigVar("dump.format") == "json":
@ -337,35 +337,35 @@ proc mainCommand*(cache: IdentCache) =
for it in iterSearchPath(searchPaths): msgWriteln(it) for it in iterSearchPath(searchPaths): msgWriteln(it)
of "check": of "check":
gCmd = cmdCheck gCmd = cmdCheck
commandCheck() commandCheck(cache)
of "parse": of "parse":
gCmd = cmdParse gCmd = cmdParse
wantMainModule() wantMainModule()
discard parseFile(gProjectMainIdx) discard parseFile(gProjectMainIdx, cache)
of "scan": of "scan":
gCmd = cmdScan gCmd = cmdScan
wantMainModule() wantMainModule()
commandScan() commandScan(cache)
msgWriteln("Beware: Indentation tokens depend on the parser\'s state!") msgWriteln("Beware: Indentation tokens depend on the parser\'s state!")
of "secret": of "secret":
gCmd = cmdInteractive gCmd = cmdInteractive
commandInteractive() commandInteractive(cache)
of "e": of "e":
# XXX: temporary command for easier testing # XXX: temporary command for easier testing
commandEval(mainCommandArg()) commandEval(cache, mainCommandArg())
of "reset": of "reset":
resetMemory() resetMemory()
of "idetools": of "idetools":
gCmd = cmdIdeTools gCmd = cmdIdeTools
if gEvalExpr != "": if gEvalExpr != "":
commandEval(gEvalExpr) commandEval(cache, gEvalExpr)
else: else:
commandSuggest() commandSuggest(cache)
of "serve": of "serve":
isServing = true isServing = true
gGlobalOptions.incl(optCaasEnabled) gGlobalOptions.incl(optCaasEnabled)
msgs.gErrorMax = high(int) # do not stop after first error msgs.gErrorMax = high(int) # do not stop after first error
serve(mainCommand) serve(cache, mainCommand)
of "nop", "help": of "nop", "help":
# prevent the "success" message: # prevent the "success" message:
gCmd = cmdDump gCmd = cmdDump

View file

@ -186,14 +186,16 @@ proc compileModule*(fileIdx: int32; cache: IdentCache, flags: TSymFlags): PSym =
return return
else: else:
result.id = getID() result.id = getID()
let validFile = processModule(result, if sfMainModule in flags and gProjectIsStdin: llStreamOpen(stdin) else: nil, rd) let validFile = processModule(result,
if sfMainModule in flags and gProjectIsStdin: stdin.llStreamOpen else: nil,
rd, cache)
if optCaasEnabled in gGlobalOptions: if optCaasEnabled in gGlobalOptions:
gMemCacheData[fileIdx].compiledAt = gLastCmdTime gMemCacheData[fileIdx].compiledAt = gLastCmdTime
gMemCacheData[fileIdx].needsRecompile = Recompiled gMemCacheData[fileIdx].needsRecompile = Recompiled
if validFile: doHash fileIdx if validFile: doHash fileIdx
else: else:
if checkDepMem(fileIdx) == Yes: if checkDepMem(fileIdx) == Yes:
result = compileModule(fileIdx, flags) result = compileModule(fileIdx, cache, flags)
else: else:
result = gCompiledModules[fileIdx] result = gCompiledModules[fileIdx]
@ -208,16 +210,16 @@ proc importModule*(s: PSym, fileIdx: int32; cache: IdentCache): PSym {.procvar.}
else: ForeignPackageNotes else: ForeignPackageNotes
proc includeModule*(s: PSym, fileIdx: int32; cache: IdentCache): PNode {.procvar.} = proc includeModule*(s: PSym, fileIdx: int32; cache: IdentCache): PNode {.procvar.} =
result = syntaxes.parseFile(fileIdx) result = syntaxes.parseFile(fileIdx, cache)
if optCaasEnabled in gGlobalOptions: if optCaasEnabled in gGlobalOptions:
growCache gMemCacheData, fileIdx growCache gMemCacheData, fileIdx
addDep(s, fileIdx) addDep(s, fileIdx)
doHash(fileIdx) doHash(fileIdx)
proc compileSystemModule* = proc compileSystemModule*(cache: IdentCache) =
if magicsys.systemModule == nil: if magicsys.systemModule == nil:
systemFileIdx = fileInfoIdx(options.libpath/"system.nim") systemFileIdx = fileInfoIdx(options.libpath/"system.nim")
discard compileModule(systemFileIdx, {sfSystemModule}) discard compileModule(systemFileIdx, cache, {sfSystemModule})
proc wantMainModule* = proc wantMainModule* =
if gProjectFull.len == 0: if gProjectFull.len == 0:
@ -227,15 +229,15 @@ proc wantMainModule* =
passes.gIncludeFile = includeModule passes.gIncludeFile = includeModule
passes.gImportModule = importModule passes.gImportModule = importModule
proc compileProject*(projectFileIdx = -1'i32) = proc compileProject*(cache: IdentCache; projectFileIdx = -1'i32) =
wantMainModule() wantMainModule()
let systemFileIdx = fileInfoIdx(options.libpath / "system.nim") let systemFileIdx = fileInfoIdx(options.libpath / "system.nim")
let projectFile = if projectFileIdx < 0: gProjectMainIdx else: projectFileIdx let projectFile = if projectFileIdx < 0: gProjectMainIdx else: projectFileIdx
if projectFile == systemFileIdx: if projectFile == systemFileIdx:
discard compileModule(projectFile, {sfMainModule, sfSystemModule}) discard compileModule(projectFile, cache, {sfMainModule, sfSystemModule})
else: else:
compileSystemModule() compileSystemModule(cache)
discard compileModule(projectFile, {sfMainModule}) discard compileModule(projectFile, cache, {sfMainModule})
proc makeModule*(filename: string): PSym = proc makeModule*(filename: string): PSym =
result = newModule(fileInfoIdx filename) result = newModule(fileInfoIdx filename)

View file

@ -21,7 +21,7 @@ when defined(i386) and defined(windows) and defined(vcc):
import import
commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes, commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes,
extccomp, strutils, os, osproc, platform, main, parseopt, service, extccomp, strutils, os, osproc, platform, main, parseopt, service,
nodejs, scriptconfig nodejs, scriptconfig, idents
when hasTinyCBackend: when hasTinyCBackend:
import tccgen import tccgen
@ -37,7 +37,7 @@ proc prependCurDir(f: string): string =
else: else:
result = f result = f
proc handleCmdLine() = proc handleCmdLine(cache: IdentCache) =
if paramCount() == 0: if paramCount() == 0:
writeCommandLineUsage() writeCommandLineUsage()
else: else:
@ -61,19 +61,19 @@ proc handleCmdLine() =
loadConfigs(DefaultConfig) # load all config files loadConfigs(DefaultConfig) # load all config files
let scriptFile = gProjectFull.changeFileExt("nims") let scriptFile = gProjectFull.changeFileExt("nims")
if fileExists(scriptFile): if fileExists(scriptFile):
runNimScript(scriptFile, freshDefines=false) runNimScript(cache, scriptFile, freshDefines=false)
# 'nim foo.nims' means to just run the NimScript file and do nothing more: # 'nim foo.nims' means to just run the NimScript file and do nothing more:
if scriptFile == gProjectFull: return if scriptFile == gProjectFull: return
elif fileExists(gProjectPath / "config.nims"): elif fileExists(gProjectPath / "config.nims"):
# directory wide NimScript file # directory wide NimScript file
runNimScript(gProjectPath / "config.nims", freshDefines=false) runNimScript(cache, gProjectPath / "config.nims", freshDefines=false)
# now process command line arguments again, because some options in the # now process command line arguments again, because some options in the
# command line can overwite the config file's settings # command line can overwite the config file's settings
extccomp.initVars() extccomp.initVars()
processCmdLine(passCmd2, "") processCmdLine(passCmd2, "")
if options.command == "": if options.command == "":
rawMessage(errNoCommand, command) rawMessage(errNoCommand, command)
mainCommand() mainCommand(cache)
if optHints in gOptions and hintGCStats in gNotes: echo(GC_getStatistics()) if optHints in gOptions and hintGCStats in gNotes: echo(GC_getStatistics())
#echo(GC_getStatistics()) #echo(GC_getStatistics())
if msgs.gErrorCounter == 0: if msgs.gErrorCounter == 0:
@ -117,5 +117,5 @@ when compileOption("gc", "v2") or compileOption("gc", "refc"):
condsyms.initDefines() condsyms.initDefines()
when not defined(selftest): when not defined(selftest):
handleCmdLine() handleCmdLine(newIdentCache())
msgQuit(int8(msgs.gErrorCounter > 0)) msgQuit(int8(msgs.gErrorCounter > 0))

View file

@ -10,9 +10,9 @@
## implements some little helper passes ## implements some little helper passes
import import
strutils, ast, astalgo, passes, msgs, options, idgen strutils, ast, astalgo, passes, idents, msgs, options, idgen
proc verboseOpen(s: PSym): PPassContext = proc verboseOpen(s: PSym; cache: IdentCache): PPassContext =
#MessageOut('compiling ' + s.name.s); #MessageOut('compiling ' + s.name.s);
result = nil # we don't need a context result = nil # we don't need a context
rawMessage(hintProcessing, s.name.s) rawMessage(hintProcessing, s.name.s)

View file

@ -142,7 +142,7 @@ type
methods*: TSymSeq methods*: TSymSeq
origFile: string origFile: string
inViewMode: bool inViewMode: bool
cache: IdentCache cache*: IdentCache
PRodReader* = ref TRodReader PRodReader* = ref TRodReader

View file

@ -11,7 +11,7 @@
## language. ## language.
import import
ast, modules, passes, passaux, condsyms, ast, modules, idents, passes, passaux, condsyms,
options, nimconf, lists, sem, semdata, llstream, vm, vmdef, commands, msgs, options, nimconf, lists, sem, semdata, llstream, vm, vmdef, commands, msgs,
os, times, osproc, wordrecg, strtabs os, times, osproc, wordrecg, strtabs
@ -25,9 +25,9 @@ proc listDirs(a: VmArgs, filter: set[PathComponent]) =
if kind in filter: result.add path if kind in filter: result.add path
setResult(a, result) setResult(a, result)
proc setupVM*(module: PSym; scriptName: string): PEvalContext = proc setupVM*(module: PSym; cache: IdentCache; scriptName: string): PEvalContext =
# For Nimble we need to export 'setupVM'. # For Nimble we need to export 'setupVM'.
result = newCtx(module) result = newCtx(module, cache)
result.mode = emRepl result.mode = emRepl
registerAdditionalOps(result) registerAdditionalOps(result)
@ -134,7 +134,7 @@ proc setupVM*(module: PSym; scriptName: string): PEvalContext =
cbconf selfExe: cbconf selfExe:
setResult(a, os.getAppFilename()) setResult(a, os.getAppFilename())
proc runNimScript*(scriptName: string; freshDefines=true) = proc runNimScript*(cache: IdentCache; scriptName: string; freshDefines=true) =
passes.gIncludeFile = includeModule passes.gIncludeFile = includeModule
passes.gImportModule = importModule passes.gImportModule = importModule
if freshDefines: initDefines() if freshDefines: initDefines()
@ -148,10 +148,10 @@ proc runNimScript*(scriptName: string; freshDefines=true) =
var m = makeModule(scriptName) var m = makeModule(scriptName)
incl(m.flags, sfMainModule) incl(m.flags, sfMainModule)
vm.globalCtx = setupVM(m, scriptName) vm.globalCtx = setupVM(m, cache, scriptName)
compileSystemModule() compileSystemModule(cache)
discard processModule(m, llStreamOpen(scriptName, fmRead), nil) discard processModule(m, llStreamOpen(scriptName, fmRead), nil, cache)
# ensure we load 'system.nim' again for the real non-config stuff! # ensure we load 'system.nim' again for the real non-config stuff!
resetAllModulesHard() resetAllModulesHard()

View file

@ -398,8 +398,8 @@ proc addCodeForGenerics(c: PContext, n: PNode) =
addSon(n, prc.ast) addSon(n, prc.ast)
c.lastGenericIdx = c.generics.len c.lastGenericIdx = c.generics.len
proc myOpen(module: PSym): PPassContext = proc myOpen(module: PSym; cache: IdentCache): PPassContext =
var c = newContext(module) var c = newContext(module, cache)
if c.p != nil: internalError(module.info, "sem.myOpen") if c.p != nil: internalError(module.info, "sem.myOpen")
c.semConstExpr = semConstExpr c.semConstExpr = semConstExpr
c.semExpr = semExpr c.semExpr = semExpr
@ -428,8 +428,8 @@ proc myOpen(module: PSym): PPassContext =
gNotes = ForeignPackageNotes gNotes = ForeignPackageNotes
result = c result = c
proc myOpenCached(module: PSym, rd: PRodReader): PPassContext = proc myOpenCached(module: PSym; rd: PRodReader): PPassContext =
result = myOpen(module) result = myOpen(module, rd.cache)
for m in items(rd.methods): methodDef(m, true) for m in items(rd.methods): methodDef(m, true)
proc isImportSystemStmt(n: PNode): bool = proc isImportSystemStmt(n: PNode): bool =

View file

@ -620,7 +620,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
proc semStaticExpr(c: PContext, n: PNode): PNode = proc semStaticExpr(c: PContext, n: PNode): PNode =
let a = semExpr(c, n.sons[0]) let a = semExpr(c, n.sons[0])
result = evalStaticExpr(c.module, a, c.p.owner) result = evalStaticExpr(c.module, c.cache, a, c.p.owner)
if result.isNil: if result.isNil:
localError(n.info, errCannotInterpretNodeX, renderTree(n)) localError(n.info, errCannotInterpretNodeX, renderTree(n))
result = emptyNode result = emptyNode
@ -861,7 +861,7 @@ proc lookupInRecordAndBuildCheck(c: PContext, n, r: PNode, field: PIdent,
s = newNodeIT(nkCurly, n.info, setType) s = newNodeIT(nkCurly, n.info, setType)
for j in countup(0, sonsLen(it) - 2): addSon(s, copyTree(it.sons[j])) for j in countup(0, sonsLen(it) - 2): addSon(s, copyTree(it.sons[j]))
var inExpr = newNodeIT(nkCall, n.info, getSysType(tyBool)) var inExpr = newNodeIT(nkCall, n.info, getSysType(tyBool))
addSon(inExpr, newSymNode(ast.opContains, n.info)) addSon(inExpr, newSymNode(opContains, n.info))
addSon(inExpr, s) addSon(inExpr, s)
addSon(inExpr, copyTree(r.sons[0])) addSon(inExpr, copyTree(r.sons[0]))
addSon(check, inExpr) addSon(check, inExpr)
@ -874,11 +874,11 @@ proc lookupInRecordAndBuildCheck(c: PContext, n, r: PNode, field: PIdent,
check = newNodeI(nkCheckedFieldExpr, n.info) check = newNodeI(nkCheckedFieldExpr, n.info)
addSon(check, ast.emptyNode) # make space for access node addSon(check, ast.emptyNode) # make space for access node
var inExpr = newNodeIT(nkCall, n.info, getSysType(tyBool)) var inExpr = newNodeIT(nkCall, n.info, getSysType(tyBool))
addSon(inExpr, newSymNode(ast.opContains, n.info)) addSon(inExpr, newSymNode(opContains, n.info))
addSon(inExpr, s) addSon(inExpr, s)
addSon(inExpr, copyTree(r.sons[0])) addSon(inExpr, copyTree(r.sons[0]))
var notExpr = newNodeIT(nkCall, n.info, getSysType(tyBool)) var notExpr = newNodeIT(nkCall, n.info, getSysType(tyBool))
addSon(notExpr, newSymNode(ast.opNot, n.info)) addSon(notExpr, newSymNode(opNot, n.info))
addSon(notExpr, inExpr) addSon(notExpr, inExpr)
addSon(check, notExpr) addSon(check, notExpr)
return return

View file

@ -11,7 +11,7 @@
import import
times, commands, options, msgs, nimconf, times, commands, options, msgs, nimconf,
extccomp, strutils, os, platform, parseopt extccomp, strutils, os, platform, parseopt, idents
when useCaas: when useCaas:
import net import net
@ -45,11 +45,11 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
if optRun notin gGlobalOptions and arguments != "" and options.command.normalize != "run": if optRun notin gGlobalOptions and arguments != "" and options.command.normalize != "run":
rawMessage(errArgsNeedRunOption, []) rawMessage(errArgsNeedRunOption, [])
proc serve*(action: proc (){.nimcall.}) = proc serve*(cache: IdentCache; action: proc (cache: IdentCache){.nimcall.}) =
template execute(cmd) = template execute(cmd) =
curCaasCmd = cmd curCaasCmd = cmd
processCmdLine(passCmd2, cmd) processCmdLine(passCmd2, cmd)
action() action(cache)
gErrorCounter = 0 gErrorCounter = 0
let typ = getConfigVar("server.type") let typ = getConfigVar("server.type")