Merge pull request #272 from nim-lang/ARAQ-newcompilerapi3
make Nimble compile with the lastest version of the compiler API
This commit is contained in:
commit
15db5da8a1
1 changed files with 23 additions and 26 deletions
|
|
@ -18,6 +18,9 @@ import compiler/options as compiler_options
|
||||||
import common, version, options, packageinfo
|
import common, version, options, packageinfo
|
||||||
import os, strutils, strtabs, times, osproc, sets
|
import os, strutils, strtabs, times, osproc, sets
|
||||||
|
|
||||||
|
when not declared(resetAllModulesHard):
|
||||||
|
import compiler/modulegraphs
|
||||||
|
|
||||||
type
|
type
|
||||||
ExecutionResult*[T] = object
|
ExecutionResult*[T] = object
|
||||||
success*: bool
|
success*: bool
|
||||||
|
|
@ -197,8 +200,9 @@ proc findNimscriptApi(options: Options): string =
|
||||||
|
|
||||||
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
||||||
|
|
||||||
proc execScript(scriptName: string, flags: StringTableRef, options: Options) =
|
proc execScript(scriptName: string, flags: StringTableRef,
|
||||||
## Executes the specified script.
|
options: Options): PSym =
|
||||||
|
## Executes the specified script. Returns the script's module symbol.
|
||||||
##
|
##
|
||||||
## No clean up is performed and must be done manually!
|
## No clean up is performed and must be done manually!
|
||||||
if "nimblepkg/nimscriptapi" notin compiler_options.implicitIncludes:
|
if "nimblepkg/nimscriptapi" notin compiler_options.implicitIncludes:
|
||||||
|
|
@ -234,9 +238,14 @@ proc execScript(scriptName: string, flags: StringTableRef, options: Options) =
|
||||||
|
|
||||||
appendStr(searchPaths, compiler_options.libpath)
|
appendStr(searchPaths, compiler_options.libpath)
|
||||||
|
|
||||||
var m = makeModule(scriptName)
|
when declared(resetAllModulesHard):
|
||||||
incl(m.flags, sfMainModule)
|
result = makeModule(scriptName)
|
||||||
vm.globalCtx = setupVM(m, scriptName, flags)
|
else:
|
||||||
|
let graph = newModuleGraph()
|
||||||
|
result = graph.makeModule(scriptName)
|
||||||
|
|
||||||
|
incl(result.flags, sfMainModule)
|
||||||
|
vm.globalCtx = setupVM(result, scriptName, flags)
|
||||||
|
|
||||||
# Setup builtins defined in nimscriptapi.nim
|
# Setup builtins defined in nimscriptapi.nim
|
||||||
template cbApi(name, body) {.dirty.} =
|
template cbApi(name, body) {.dirty.} =
|
||||||
|
|
@ -248,16 +257,17 @@ proc execScript(scriptName: string, flags: StringTableRef, options: Options) =
|
||||||
setResult(a, scriptName.splitFile.dir)
|
setResult(a, scriptName.splitFile.dir)
|
||||||
|
|
||||||
when declared(newIdentCache):
|
when declared(newIdentCache):
|
||||||
compileSystemModule(identCache)
|
graph.compileSystemModule(identCache)
|
||||||
processModule(m, llStreamOpen(scriptName, fmRead), nil, identCache)
|
graph.processModule(result, llStreamOpen(scriptName, fmRead), nil, identCache)
|
||||||
else:
|
else:
|
||||||
compileSystemModule()
|
compileSystemModule()
|
||||||
processModule(m, llStreamOpen(scriptName, fmRead), nil)
|
processModule(result, llStreamOpen(scriptName, fmRead), nil)
|
||||||
|
|
||||||
proc cleanup() =
|
proc cleanup() =
|
||||||
# ensure everything can be called again:
|
# ensure everything can be called again:
|
||||||
compiler_options.gProjectName = ""
|
compiler_options.gProjectName = ""
|
||||||
compiler_options.command = ""
|
compiler_options.command = ""
|
||||||
|
when declared(resetAllModulesHard):
|
||||||
resetAllModulesHard()
|
resetAllModulesHard()
|
||||||
clearPasses()
|
clearPasses()
|
||||||
msgs.gErrorMax = 1
|
msgs.gErrorMax = 1
|
||||||
|
|
@ -287,7 +297,7 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
|
||||||
compiler_options.command = internalCmd
|
compiler_options.command = internalCmd
|
||||||
|
|
||||||
# Execute the nimscript file.
|
# Execute the nimscript file.
|
||||||
execScript(scriptName, nil, options)
|
let thisModule = execScript(scriptName, nil, options)
|
||||||
|
|
||||||
# Check whether an error has occurred.
|
# Check whether an error has occurred.
|
||||||
if msgs.gErrorCounter > 0:
|
if msgs.gErrorCounter > 0:
|
||||||
|
|
@ -305,12 +315,6 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
|
||||||
template trivialFieldSeq(field) =
|
template trivialFieldSeq(field) =
|
||||||
result.field.add getGlobalAsSeq(getSym(thisModule, astToStr field))
|
result.field.add getGlobalAsSeq(getSym(thisModule, astToStr field))
|
||||||
|
|
||||||
# Grab the module Sym for .nimble file (nimscriptapi is included in it).
|
|
||||||
let idx = fileInfoIdx(scriptName)
|
|
||||||
let thisModule = getModule(idx)
|
|
||||||
assert(not thisModule.isNil)
|
|
||||||
assert thisModule.kind == skModule
|
|
||||||
|
|
||||||
# keep reasonable default:
|
# keep reasonable default:
|
||||||
let name = getGlobal(thisModule.tab.strTableGet(getIdent"packageName"))
|
let name = getGlobal(thisModule.tab.strTableGet(getIdent"packageName"))
|
||||||
if name.len > 0: result.name = name
|
if name.len > 0: result.name = name
|
||||||
|
|
@ -363,11 +367,7 @@ proc execTask*(scriptName, taskName: string,
|
||||||
compiler_options.command = internalCmd
|
compiler_options.command = internalCmd
|
||||||
echo("Executing task ", taskName, " in ", scriptName)
|
echo("Executing task ", taskName, " in ", scriptName)
|
||||||
|
|
||||||
execScript(scriptName, result.flags, options)
|
let thisModule = execScript(scriptName, result.flags, options)
|
||||||
# Explicitly execute the task procedure, instead of relying on hack.
|
|
||||||
let idx = fileInfoIdx(scriptName)
|
|
||||||
let thisModule = getModule(idx)
|
|
||||||
assert thisModule.kind == skModule
|
|
||||||
let prc = thisModule.tab.strTableGet(getIdent(taskName & "Task"))
|
let prc = thisModule.tab.strTableGet(getIdent(taskName & "Task"))
|
||||||
if prc.isNil:
|
if prc.isNil:
|
||||||
# Procedure not defined in the NimScript module.
|
# Procedure not defined in the NimScript module.
|
||||||
|
|
@ -397,11 +397,8 @@ proc execHook*(scriptName, actionName: string, before: bool,
|
||||||
else: actionName.toLower & "After"
|
else: actionName.toLower & "After"
|
||||||
echo("Attempting to execute hook ", hookName, " in ", scriptName)
|
echo("Attempting to execute hook ", hookName, " in ", scriptName)
|
||||||
|
|
||||||
execScript(scriptName, result.flags, options)
|
let thisModule = execScript(scriptName, result.flags, options)
|
||||||
# Explicitly execute the task procedure, instead of relying on hack.
|
# Explicitly execute the task procedure, instead of relying on hack.
|
||||||
let idx = fileInfoIdx(scriptName)
|
|
||||||
let thisModule = getModule(idx)
|
|
||||||
assert thisModule.kind == skModule
|
|
||||||
let prc = thisModule.tab.strTableGet(getIdent(hookName))
|
let prc = thisModule.tab.strTableGet(getIdent(hookName))
|
||||||
if prc.isNil:
|
if prc.isNil:
|
||||||
# Procedure not defined in the NimScript module.
|
# Procedure not defined in the NimScript module.
|
||||||
|
|
@ -435,7 +432,7 @@ proc hasTaskRequestedCommand*(execResult: ExecutionResult): bool =
|
||||||
proc listTasks*(scriptName: string, options: Options) =
|
proc listTasks*(scriptName: string, options: Options) =
|
||||||
setNimScriptCommand("help")
|
setNimScriptCommand("help")
|
||||||
|
|
||||||
execScript(scriptName, nil, options)
|
discard execScript(scriptName, nil, options)
|
||||||
# TODO: Make the 'task' template generate explicit data structure containing
|
# TODO: Make the 'task' template generate explicit data structure containing
|
||||||
# all the task names + descriptions.
|
# all the task names + descriptions.
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue