mirror of
https://github.com/irmen/prog8.git
synced 2025-01-25 12:30:09 +00:00
small tweak of parse messages
This commit is contained in:
parent
b35abd548c
commit
1ab635bd7e
@ -62,7 +62,9 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
|||||||
val totalTime = measureTimeMillis {
|
val totalTime = measureTimeMillis {
|
||||||
// import main module and everything it needs
|
// import main module and everything it needs
|
||||||
val (programresult, compilationOptions, imported) = parseImports(args.filepath, args.errors, compTarget, args.sourceDirs)
|
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) {
|
with(compilationOptions) {
|
||||||
slowCodegenWarnings = args.slowCodegenWarnings
|
slowCodegenWarnings = args.slowCodegenWarnings
|
||||||
optimize = args.optimize
|
optimize = args.optimize
|
||||||
@ -175,7 +177,7 @@ fun parseImports(filepath: Path,
|
|||||||
errors: IErrorReporter,
|
errors: IErrorReporter,
|
||||||
compTarget: ICompilationTarget,
|
compTarget: ICompilationTarget,
|
||||||
sourceDirs: List<String>): Triple<Program, CompilationOptions, List<Path>> {
|
sourceDirs: List<String>): Triple<Program, CompilationOptions, List<Path>> {
|
||||||
println("Compiler target: ${compTarget.name}. Parsing...")
|
println("Compiler target: ${compTarget.name}")
|
||||||
val bf = BuiltinFunctionsFacade(BuiltinFunctions)
|
val bf = BuiltinFunctionsFacade(BuiltinFunctions)
|
||||||
val program = Program(filepath.nameWithoutExtension, bf, compTarget, compTarget)
|
val program = Program(filepath.nameWithoutExtension, bf, compTarget, compTarget)
|
||||||
bf.program = program
|
bf.program = program
|
||||||
|
@ -39,9 +39,8 @@ class ModuleImporter(private val program: Program,
|
|||||||
else -> candidates.first() // when more candiates, pick the one from the first location
|
else -> candidates.first() // when more candiates, pick the one from the first location
|
||||||
}
|
}
|
||||||
|
|
||||||
print(" importing '${filePath.nameWithoutExtension}' (from file $srcPath)\r")
|
val source = SourceCode.File(srcPath)
|
||||||
val module = importModule(SourceCode.File(srcPath))
|
return Ok(importModule(source))
|
||||||
return Ok(module)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importLibraryModule(name: String): Module? {
|
fun importLibraryModule(name: String): Module? {
|
||||||
@ -52,6 +51,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun importModule(src: SourceCode) : Module {
|
private fun importModule(src: SourceCode) : Module {
|
||||||
|
printImportingMessage(src.name, src.origin)
|
||||||
val moduleAst = Prog8Parser.parseModule(src)
|
val moduleAst = Prog8Parser.parseModule(src)
|
||||||
program.addModule(moduleAst)
|
program.addModule(moduleAst)
|
||||||
|
|
||||||
@ -89,7 +89,6 @@ class ModuleImporter(private val program: Program,
|
|||||||
val importedModule =
|
val importedModule =
|
||||||
moduleResourceSrc.fold(
|
moduleResourceSrc.fold(
|
||||||
success = {
|
success = {
|
||||||
print(" importing '$moduleName' (from internal ${it.origin})\r")
|
|
||||||
importModule(it)
|
importModule(it)
|
||||||
},
|
},
|
||||||
failure = {
|
failure = {
|
||||||
@ -97,7 +96,6 @@ class ModuleImporter(private val program: Program,
|
|||||||
val moduleSrc = getModuleFromFile(moduleName, importingModule)
|
val moduleSrc = getModuleFromFile(moduleName, importingModule)
|
||||||
moduleSrc.fold(
|
moduleSrc.fold(
|
||||||
success = {
|
success = {
|
||||||
print(" importing '$moduleName' (from file ${it.origin})\r")
|
|
||||||
importModule(it)
|
importModule(it)
|
||||||
},
|
},
|
||||||
failure = {
|
failure = {
|
||||||
@ -150,4 +148,18 @@ class ModuleImporter(private val program: Program,
|
|||||||
|
|
||||||
return Err(NoSuchFileException(File("name")))
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ import java.io.File
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
|
import kotlin.io.path.name
|
||||||
import kotlin.io.path.readText
|
import kotlin.io.path.readText
|
||||||
|
import kotlin.io.path.toPath
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates - and ties together - actual source code (=text) and its [origin].
|
* Encapsulates - and ties together - actual source code (=text) and its [origin].
|
||||||
@ -21,6 +23,11 @@ sealed class SourceCode {
|
|||||||
*/
|
*/
|
||||||
abstract val isFromFilesystem: Boolean
|
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.
|
* Where this [SourceCode] instance came from.
|
||||||
* This can be one of the following:
|
* This can be one of the following:
|
||||||
@ -61,6 +68,7 @@ sealed class SourceCode {
|
|||||||
override val isFromResources = false
|
override val isFromResources = false
|
||||||
override val isFromFilesystem = false
|
override val isFromFilesystem = false
|
||||||
override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>"
|
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() {
|
class File(path: Path): SourceCode() {
|
||||||
override val text: String
|
override val text: String
|
||||||
override val origin: String
|
override val origin: String
|
||||||
|
override val name: String
|
||||||
override val isFromResources = false
|
override val isFromResources = false
|
||||||
override val isFromFilesystem = true
|
override val isFromFilesystem = true
|
||||||
|
|
||||||
@ -82,6 +91,7 @@ sealed class SourceCode {
|
|||||||
origin = relative(normalized).toString()
|
origin = relative(normalized).toString()
|
||||||
try {
|
try {
|
||||||
text = normalized.readText()
|
text = normalized.readText()
|
||||||
|
name = normalized.toFile().nameWithoutExtension
|
||||||
} catch (nfx: java.nio.file.NoSuchFileException) {
|
} catch (nfx: java.nio.file.NoSuchFileException) {
|
||||||
throw NoSuchFileException(normalized.toFile()).also { it.initCause(nfx) }
|
throw NoSuchFileException(normalized.toFile()).also { it.initCause(nfx) }
|
||||||
} catch (iox: IOException) {
|
} catch (iox: IOException) {
|
||||||
@ -100,6 +110,7 @@ sealed class SourceCode {
|
|||||||
override val isFromFilesystem = false
|
override val isFromFilesystem = false
|
||||||
override val origin = "$libraryFilePrefix$normalized"
|
override val origin = "$libraryFilePrefix$normalized"
|
||||||
override val text: String
|
override val text: String
|
||||||
|
override val name: String
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val rscURL = object {}.javaClass.getResource(normalized)
|
val rscURL = object {}.javaClass.getResource(normalized)
|
||||||
@ -112,6 +123,7 @@ sealed class SourceCode {
|
|||||||
}
|
}
|
||||||
val stream = object {}.javaClass.getResourceAsStream(normalized)
|
val stream = object {}.javaClass.getResourceAsStream(normalized)
|
||||||
text = stream!!.reader().use { it.readText() }
|
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 isFromResources: Boolean = false
|
||||||
override val isFromFilesystem: Boolean = false
|
override val isFromFilesystem: Boolean = false
|
||||||
override val origin: String = name
|
override val origin: String = name
|
||||||
|
override val name: String = name
|
||||||
override val text: String = "<generated code node, no text representation>"
|
override val text: String = "<generated code node, no text representation>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user