unified @embedded@ and library: into the latter

This commit is contained in:
Irmen de Jong 2021-10-11 19:22:56 +02:00
parent 2d26b9c994
commit c55ac0450f
4 changed files with 12 additions and 12 deletions

View File

@ -351,8 +351,8 @@ fun printAst(programAst: Program) {
println()
}
fun loadAsmIncludeFile(filename: String, sourcePath: Path): String {
return if (filename.startsWith("library:")) { // FIXME: is the prefix "library:" or is it "@embedded@"?
internal fun loadAsmIncludeFile(filename: String, sourcePath: Path): String {
return if (filename.startsWith("library:")) {
val resource = tryGetEmbeddedResource(filename.substring(8))
?: throw IllegalArgumentException("library file '$filename' not found")
resource.bufferedReader().use { it.readText() }

View File

@ -36,7 +36,7 @@ class ModuleImporter(private val program: Program,
else -> candidates.first() // TODO: report error if more than 1 candidate?
}
val logMsg = "importing '${filePath.nameWithoutExtension}' (from $srcPath)"
val logMsg = "importing '${filePath.nameWithoutExtension}' (from file $srcPath)"
println(logMsg)
return importModule(SourceCode.fromPath(srcPath))
@ -79,7 +79,7 @@ class ModuleImporter(private val program: Program,
var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)
val importedModule =
if (srcCode != null) {
println("importing '$moduleName' (library): ${srcCode.origin}")
println("importing '$moduleName' (from internal ${srcCode.origin})")
importModule(srcCode)
} else {
srcCode = tryGetModuleFromFile(moduleName, importingModule)

View File

@ -32,7 +32,7 @@ abstract class SourceCode {
* This can be one of the following:
* * a normal string representation of a [java.nio.file.Path], if it originates from a file (see [fromPath])
* * `<String@44c56085>` if was created via [of]
* * `@embedded@/x/y/z.ext` if it came from resources (see [fromResources])
* * `library:/x/y/z.ext` if it is a library file that was loaded from resources (see [fromResources])
*/
abstract val origin: String
@ -106,7 +106,7 @@ abstract class SourceCode {
}
/**
* [origin]: `<res:/x/y/z.p8>` for a given `pathString` of "x/y/z.p8"
* [origin]: `<library:/x/y/z.p8>` for a given `pathString` of "x/y/z.p8"
*/
fun fromResources(pathString: String): SourceCode {
val path = Path.of(pathString).normalize()
@ -121,7 +121,7 @@ abstract class SourceCode {
}
return object : SourceCode() {
override val isFromResources = true
override val origin = "@embedded@$normalized"
override val origin = "library:$normalized"
override fun getCharStream(): CharStream {
val inpStr = object {}.javaClass.getResourceAsStream(normalized)
return CharStreams.fromStream(inpStr)

View File

@ -77,7 +77,7 @@ class TestSourceCode {
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
val src = SourceCode.fromResources(pathString)
assertEquals("@embedded@/$pathString", src.origin)
assertEquals("library:/$pathString", src.origin)
assertEquals(srcFile.readText(), src.asString())
}
@ -87,7 +87,7 @@ class TestSourceCode {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.fromResources(pathString)
assertEquals("@embedded@$pathString", src.origin)
assertEquals("library:$pathString", src.origin)
assertEquals(srcFile.readText(), src.asString())
}
@ -97,7 +97,7 @@ class TestSourceCode {
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
val src = SourceCode.fromResources(pathString)
assertEquals("@embedded@/$pathString", src.origin)
assertEquals("library:/$pathString", src.origin)
assertEquals(srcFile.readText(), src.asString())
assertTrue(src.isFromResources, ".isFromResources")
}
@ -108,7 +108,7 @@ class TestSourceCode {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.fromResources(pathString)
assertEquals("@embedded@$pathString", src.origin)
assertEquals("library:$pathString", src.origin)
assertEquals(srcFile.readText(), src.asString())
}
@ -118,7 +118,7 @@ class TestSourceCode {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.fromResources(pathString)
assertEquals("@embedded@/prog8lib/math.p8", src.origin)
assertEquals("library:/prog8lib/math.p8", src.origin)
assertEquals(srcFile.readText(), src.asString())
assertTrue(src.isFromResources, ".isFromResources")
}