vm now free of global variables
This commit is contained in:
parent
5d45e630c5
commit
382bc34f93
4 changed files with 12 additions and 17 deletions
|
|
@ -41,6 +41,8 @@ type
|
||||||
backend*: RootRef # minor hack so that a backend can extend this easily
|
backend*: RootRef # minor hack so that a backend can extend this easily
|
||||||
config*: ConfigRef
|
config*: ConfigRef
|
||||||
cache*: IdentCache
|
cache*: IdentCache
|
||||||
|
vm*: RootRef # unfortunately the 'vm' state is shared project-wise, this will
|
||||||
|
# be clarified in later compiler implementations.
|
||||||
doStopCompile*: proc(): bool {.closure.}
|
doStopCompile*: proc(): bool {.closure.}
|
||||||
usageSym*: PSym # for nimsuggest
|
usageSym*: PSym # for nimsuggest
|
||||||
owners*: seq[PSym]
|
owners*: seq[PSym]
|
||||||
|
|
|
||||||
|
|
@ -166,14 +166,13 @@ proc runNimScript*(cache: IdentCache; scriptName: string;
|
||||||
|
|
||||||
var m = graph.makeModule(scriptName)
|
var m = graph.makeModule(scriptName)
|
||||||
incl(m.flags, sfMainModule)
|
incl(m.flags, sfMainModule)
|
||||||
vm.globalCtx = setupVM(m, cache, scriptName, graph)
|
graph.vm = setupVM(m, cache, scriptName, graph)
|
||||||
|
|
||||||
graph.compileSystemModule(cache)
|
graph.compileSystemModule(cache)
|
||||||
discard graph.processModule(m, llStreamOpen(scriptName, fmRead), nil, cache)
|
discard graph.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!
|
||||||
resetSystemArtifacts(graph)
|
resetSystemArtifacts(graph)
|
||||||
vm.globalCtx = nil
|
|
||||||
# do not remove the defined symbols
|
# do not remove the defined symbols
|
||||||
#initDefines()
|
#initDefines()
|
||||||
undefSymbol(conf.symbols, "nimscript")
|
undefSymbol(conf.symbols, "nimscript")
|
||||||
|
|
|
||||||
|
|
@ -1654,18 +1654,12 @@ proc getGlobalValue*(c: PCtx; s: PSym): PNode =
|
||||||
|
|
||||||
include vmops
|
include vmops
|
||||||
|
|
||||||
# for now we share the 'globals' environment. XXX Coming soon: An API for
|
|
||||||
# storing&loading the 'globals' environment to get what a component system
|
|
||||||
# requires.
|
|
||||||
var
|
|
||||||
globalCtx*: PCtx
|
|
||||||
|
|
||||||
proc setupGlobalCtx(module: PSym; cache: IdentCache; graph: ModuleGraph) =
|
proc setupGlobalCtx(module: PSym; cache: IdentCache; graph: ModuleGraph) =
|
||||||
if globalCtx.isNil:
|
if graph.vm.isNil:
|
||||||
globalCtx = newCtx(module, cache, graph)
|
graph.vm = newCtx(module, cache, graph)
|
||||||
registerAdditionalOps(globalCtx)
|
registerAdditionalOps(PCtx graph.vm)
|
||||||
else:
|
else:
|
||||||
refresh(globalCtx, module)
|
refresh(PCtx graph.vm, module)
|
||||||
|
|
||||||
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
#var c = newEvalContext(module, emRepl)
|
#var c = newEvalContext(module, emRepl)
|
||||||
|
|
@ -1674,9 +1668,9 @@ proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
|
|
||||||
# XXX produce a new 'globals' environment here:
|
# XXX produce a new 'globals' environment here:
|
||||||
setupGlobalCtx(module, cache, graph)
|
setupGlobalCtx(module, cache, graph)
|
||||||
result = globalCtx
|
result = PCtx graph.vm
|
||||||
when hasFFI:
|
when hasFFI:
|
||||||
globalCtx.features = {allowFFI, allowCast}
|
PCtx(graph.vm).features = {allowFFI, allowCast}
|
||||||
|
|
||||||
proc myProcess(c: PPassContext, n: PNode): PNode =
|
proc myProcess(c: PPassContext, n: PNode): PNode =
|
||||||
let c = PCtx(c)
|
let c = PCtx(c)
|
||||||
|
|
@ -1698,7 +1692,7 @@ proc evalConstExprAux(module: PSym; cache: IdentCache;
|
||||||
mode: TEvalMode): PNode =
|
mode: TEvalMode): PNode =
|
||||||
let n = transformExpr(g, module, n)
|
let n = transformExpr(g, module, n)
|
||||||
setupGlobalCtx(module, cache, g)
|
setupGlobalCtx(module, cache, g)
|
||||||
var c = globalCtx
|
var c = PCtx g.vm
|
||||||
let oldMode = c.mode
|
let oldMode = c.mode
|
||||||
defer: c.mode = oldMode
|
defer: c.mode = oldMode
|
||||||
c.mode = mode
|
c.mode = mode
|
||||||
|
|
@ -1763,7 +1757,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache; g: ModuleGraph;
|
||||||
n.renderTree, $(n.safeLen-1), $(sym.typ.len-1)])
|
n.renderTree, $(n.safeLen-1), $(sym.typ.len-1)])
|
||||||
|
|
||||||
setupGlobalCtx(module, cache, g)
|
setupGlobalCtx(module, cache, g)
|
||||||
var c = globalCtx
|
var c = PCtx g.vm
|
||||||
c.comesFromHeuristic.line = 0'u16
|
c.comesFromHeuristic.line = 0'u16
|
||||||
|
|
||||||
c.callsite = nOrig
|
c.callsite = nOrig
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,7 @@ proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: Cac
|
||||||
proc recompileFullProject(graph: ModuleGraph; cache: IdentCache) =
|
proc recompileFullProject(graph: ModuleGraph; cache: IdentCache) =
|
||||||
#echo "recompiling full project"
|
#echo "recompiling full project"
|
||||||
resetSystemArtifacts(graph)
|
resetSystemArtifacts(graph)
|
||||||
vm.globalCtx = nil
|
graph.vm = nil
|
||||||
graph.resetAllModules()
|
graph.resetAllModules()
|
||||||
GC_fullcollect()
|
GC_fullcollect()
|
||||||
compileProject(graph, cache)
|
compileProject(graph, cache)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue