mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
unified @embedded@ and library: into the latter
This commit is contained in:
parent
2d26b9c994
commit
c55ac0450f
@ -351,8 +351,8 @@ fun printAst(programAst: Program) {
|
|||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadAsmIncludeFile(filename: String, sourcePath: Path): String {
|
internal fun loadAsmIncludeFile(filename: String, sourcePath: Path): String {
|
||||||
return if (filename.startsWith("library:")) { // FIXME: is the prefix "library:" or is it "@embedded@"?
|
return if (filename.startsWith("library:")) {
|
||||||
val resource = tryGetEmbeddedResource(filename.substring(8))
|
val resource = tryGetEmbeddedResource(filename.substring(8))
|
||||||
?: throw IllegalArgumentException("library file '$filename' not found")
|
?: throw IllegalArgumentException("library file '$filename' not found")
|
||||||
resource.bufferedReader().use { it.readText() }
|
resource.bufferedReader().use { it.readText() }
|
||||||
|
@ -36,7 +36,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
else -> candidates.first() // TODO: report error if more than 1 candidate?
|
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)
|
println(logMsg)
|
||||||
|
|
||||||
return importModule(SourceCode.fromPath(srcPath))
|
return importModule(SourceCode.fromPath(srcPath))
|
||||||
@ -79,7 +79,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)
|
var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)
|
||||||
val importedModule =
|
val importedModule =
|
||||||
if (srcCode != null) {
|
if (srcCode != null) {
|
||||||
println("importing '$moduleName' (library): ${srcCode.origin}")
|
println("importing '$moduleName' (from internal ${srcCode.origin})")
|
||||||
importModule(srcCode)
|
importModule(srcCode)
|
||||||
} else {
|
} else {
|
||||||
srcCode = tryGetModuleFromFile(moduleName, importingModule)
|
srcCode = tryGetModuleFromFile(moduleName, importingModule)
|
||||||
|
@ -32,7 +32,7 @@ abstract class SourceCode {
|
|||||||
* This can be one of the following:
|
* 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])
|
* * 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]
|
* * `<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
|
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 {
|
fun fromResources(pathString: String): SourceCode {
|
||||||
val path = Path.of(pathString).normalize()
|
val path = Path.of(pathString).normalize()
|
||||||
@ -121,7 +121,7 @@ abstract class SourceCode {
|
|||||||
}
|
}
|
||||||
return object : SourceCode() {
|
return object : SourceCode() {
|
||||||
override val isFromResources = true
|
override val isFromResources = true
|
||||||
override val origin = "@embedded@$normalized"
|
override val origin = "library:$normalized"
|
||||||
override fun getCharStream(): CharStream {
|
override fun getCharStream(): CharStream {
|
||||||
val inpStr = object {}.javaClass.getResourceAsStream(normalized)
|
val inpStr = object {}.javaClass.getResourceAsStream(normalized)
|
||||||
return CharStreams.fromStream(inpStr)
|
return CharStreams.fromStream(inpStr)
|
||||||
|
@ -77,7 +77,7 @@ class TestSourceCode {
|
|||||||
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/$pathString", src.origin)
|
assertEquals("library:/$pathString", src.origin)
|
||||||
assertEquals(srcFile.readText(), src.asString())
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class TestSourceCode {
|
|||||||
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@$pathString", src.origin)
|
assertEquals("library:$pathString", src.origin)
|
||||||
assertEquals(srcFile.readText(), src.asString())
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ class TestSourceCode {
|
|||||||
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/$pathString", src.origin)
|
assertEquals("library:/$pathString", src.origin)
|
||||||
assertEquals(srcFile.readText(), src.asString())
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
assertTrue(src.isFromResources, ".isFromResources")
|
assertTrue(src.isFromResources, ".isFromResources")
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ class TestSourceCode {
|
|||||||
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@$pathString", src.origin)
|
assertEquals("library:$pathString", src.origin)
|
||||||
assertEquals(srcFile.readText(), src.asString())
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ class TestSourceCode {
|
|||||||
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/prog8lib/math.p8", src.origin)
|
assertEquals("library:/prog8lib/math.p8", src.origin)
|
||||||
assertEquals(srcFile.readText(), src.asString())
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
assertTrue(src.isFromResources, ".isFromResources")
|
assertTrue(src.isFromResources, ".isFromResources")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user