import lib paths

This commit is contained in:
Irmen de Jong 2018-08-13 12:07:16 +02:00
parent 8974a9cc2d
commit 0b8e3183b7
2 changed files with 24 additions and 12 deletions

View File

@ -86,12 +86,24 @@ fun fileNameWithoutSuffix(filePath: Path) =
filePath.fileName.toString().substringBeforeLast('.')
fun discoverImportedModule(name: String, importedFrom: Path): Path {
val tryName = Paths.get(importedFrom.parent.toString(), name + ".ill")
if(Files.exists(tryName))
return tryName
else
throw ParsingFailedError("No such module source file: $tryName")
fun discoverImportedModule(name: String, importedFrom: Path, position: Position?): Path {
val fileName = name + ".ill"
val locations = mutableListOf(Paths.get(importedFrom.parent.toString()))
val propPath = System.getProperty("il65.libpath")
if(propPath!=null)
locations.add(Paths.get(propPath))
val envPath = System.getenv("IL65_LIBPATH")
if(envPath!=null)
locations.add(Paths.get(envPath))
locations.add(Paths.get(Paths.get("").toAbsolutePath().toString(), "lib65"))
locations.forEach {
val file = Paths.get(it.toString(), fileName)
if (Files.isReadable(file)) return file
}
throw ParsingFailedError("$position Import: no module source file '$fileName' found (I've looked in: $locations)")
}
@ -102,7 +114,7 @@ fun executeImportDirective(import: Directive, importedFrom: Path): Module? {
if(importedModules.containsKey(moduleName))
return null
val modulePath = discoverImportedModule(moduleName, importedFrom)
val modulePath = discoverImportedModule(moduleName, importedFrom, import.position)
val importedModule = loadModule(modulePath)
importedModule.checkImportValid()

View File

@ -250,7 +250,7 @@ data class AssignTarget(val register: Register?, val identifier: Identifier?) :
identifier?.linkParents(this)
}
fun process(processor: IAstProcessor) = this // for now
fun process(processor: IAstProcessor) = this
}
@ -649,8 +649,8 @@ private fun il65Parser.LabeldefContext.toAst(withPosition: Boolean): IStatement
private fun il65Parser.SubroutineContext.toAst(withPosition: Boolean) : Subroutine {
val sub = Subroutine(identifier().text,
if(sub_params()==null) emptyList() else sub_params().toAst(withPosition),
if(sub_returns()==null) emptyList() else sub_returns().toAst(withPosition),
if(sub_params()==null) emptyList() else sub_params().toAst(),
if(sub_returns()==null) emptyList() else sub_returns().toAst(),
sub_address()?.integerliteral()?.toAst(),
if(sub_body()==null) emptyList() else sub_body().statement().map {it.toAst(withPosition)})
sub.position = toPosition(withPosition)
@ -658,11 +658,11 @@ private fun il65Parser.SubroutineContext.toAst(withPosition: Boolean) : Subrouti
}
private fun il65Parser.Sub_paramsContext.toAst(withPosition: Boolean): List<SubroutineParameter> =
private fun il65Parser.Sub_paramsContext.toAst(): List<SubroutineParameter> =
sub_param().map { SubroutineParameter(it.identifier().text, it.register().toAst()) }
private fun il65Parser.Sub_returnsContext.toAst(withPosition: Boolean): List<SubroutineReturnvalue> =
private fun il65Parser.Sub_returnsContext.toAst(): List<SubroutineReturnvalue> =
sub_return().map {
val isClobber = it.childCount==2 && it.children[1].text == "?"
SubroutineReturnvalue(it.register().toAst(), isClobber)