small tweak of parse messages

This commit is contained in:
Irmen de Jong 2022-02-05 14:02:24 +01:00
parent b35abd548c
commit 1ab635bd7e
3 changed files with 34 additions and 7 deletions

View File

@ -62,7 +62,9 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
val totalTime = measureTimeMillis {
// import main module and everything it needs
val (programresult, compilationOptions, imported) = parseImports(args.filepath, args.errors, compTarget, args.sourceDirs)
println("${args.filepath} parsed.\u001B[0K")
print("Parsed ${args.filepath}")
ModuleImporter.ansiEraseRestOfLine(true)
with(compilationOptions) {
slowCodegenWarnings = args.slowCodegenWarnings
optimize = args.optimize
@ -175,7 +177,7 @@ fun parseImports(filepath: Path,
errors: IErrorReporter,
compTarget: ICompilationTarget,
sourceDirs: List<String>): Triple<Program, CompilationOptions, List<Path>> {
println("Compiler target: ${compTarget.name}. Parsing...")
println("Compiler target: ${compTarget.name}")
val bf = BuiltinFunctionsFacade(BuiltinFunctions)
val program = Program(filepath.nameWithoutExtension, bf, compTarget, compTarget)
bf.program = program

View File

@ -39,9 +39,8 @@ class ModuleImporter(private val program: Program,
else -> candidates.first() // when more candiates, pick the one from the first location
}
print(" importing '${filePath.nameWithoutExtension}' (from file $srcPath)\r")
val module = importModule(SourceCode.File(srcPath))
return Ok(module)
val source = SourceCode.File(srcPath)
return Ok(importModule(source))
}
fun importLibraryModule(name: String): Module? {
@ -52,6 +51,7 @@ class ModuleImporter(private val program: Program,
}
private fun importModule(src: SourceCode) : Module {
printImportingMessage(src.name, src.origin)
val moduleAst = Prog8Parser.parseModule(src)
program.addModule(moduleAst)
@ -89,7 +89,6 @@ class ModuleImporter(private val program: Program,
val importedModule =
moduleResourceSrc.fold(
success = {
print(" importing '$moduleName' (from internal ${it.origin})\r")
importModule(it)
},
failure = {
@ -97,7 +96,6 @@ class ModuleImporter(private val program: Program,
val moduleSrc = getModuleFromFile(moduleName, importingModule)
moduleSrc.fold(
success = {
print(" importing '$moduleName' (from file ${it.origin})\r")
importModule(it)
},
failure = {
@ -150,4 +148,18 @@ class ModuleImporter(private val program: Program,
return Err(NoSuchFileException(File("name")))
}
fun printImportingMessage(module: String, origin: String) {
print(" importing '$module' (from ${origin})")
ansiEraseRestOfLine(false)
print("\r")
}
companion object {
fun ansiEraseRestOfLine(newline: Boolean) {
print("\u001b[0K")
if(newline)
println()
}
}
}

View File

@ -4,7 +4,9 @@ import java.io.File
import java.io.IOException
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.name
import kotlin.io.path.readText
import kotlin.io.path.toPath
/**
* Encapsulates - and ties together - actual source code (=text) and its [origin].
@ -21,6 +23,11 @@ sealed class SourceCode {
*/
abstract val isFromFilesystem: Boolean
/**
* The logical name of the source code unit. Usually the module's name.
*/
abstract val name: String
/**
* Where this [SourceCode] instance came from.
* This can be one of the following:
@ -61,6 +68,7 @@ sealed class SourceCode {
override val isFromResources = false
override val isFromFilesystem = false
override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>"
override val name = "<unnamed-text>"
}
/**
@ -74,6 +82,7 @@ sealed class SourceCode {
class File(path: Path): SourceCode() {
override val text: String
override val origin: String
override val name: String
override val isFromResources = false
override val isFromFilesystem = true
@ -82,6 +91,7 @@ sealed class SourceCode {
origin = relative(normalized).toString()
try {
text = normalized.readText()
name = normalized.toFile().nameWithoutExtension
} catch (nfx: java.nio.file.NoSuchFileException) {
throw NoSuchFileException(normalized.toFile()).also { it.initCause(nfx) }
} catch (iox: IOException) {
@ -100,6 +110,7 @@ sealed class SourceCode {
override val isFromFilesystem = false
override val origin = "$libraryFilePrefix$normalized"
override val text: String
override val name: String
init {
val rscURL = object {}.javaClass.getResource(normalized)
@ -112,6 +123,7 @@ sealed class SourceCode {
}
val stream = object {}.javaClass.getResourceAsStream(normalized)
text = stream!!.reader().use { it.readText() }
name = Path.of(pathString).toFile().nameWithoutExtension
}
}
@ -122,6 +134,7 @@ sealed class SourceCode {
override val isFromResources: Boolean = false
override val isFromFilesystem: Boolean = false
override val origin: String = name
override val name: String = name
override val text: String = "<generated code node, no text representation>"
}
}