diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index ae6043d57..c639684db 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -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() } diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index 808380453..131b61e0e 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -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) diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index 8a7bbadc3..dbe0ccb52 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -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]) * * `` 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]: `` for a given `pathString` of "x/y/z.p8" + * [origin]: `` 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) diff --git a/compilerAst/test/TestSourceCode.kt b/compilerAst/test/TestSourceCode.kt index dfbcca52d..a35420a83 100644 --- a/compilerAst/test/TestSourceCode.kt +++ b/compilerAst/test/TestSourceCode.kt @@ -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") }