mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
renamed command line option -libdirs to -srcdirs
this more clearly separates this meaning from the internal library modules
This commit is contained in:
parent
ca3a990f9e
commit
6b8c3ef614
@ -39,7 +39,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watches for file changes), greatly increases compilation speed")
|
val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watches for file changes), greatly increases compilation speed")
|
||||||
val slowCodegenWarnings by cli.option(ArgType.Boolean, fullName = "slowwarn", description="show debug warnings about slow/problematic assembly code generation")
|
val slowCodegenWarnings by cli.option(ArgType.Boolean, fullName = "slowwarn", description="show debug warnings about slow/problematic assembly code generation")
|
||||||
val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler, currently '${C64Target.name}' and '${Cx16Target.name}' available").default(C64Target.name)
|
val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler, currently '${C64Target.name}' and '${Cx16Target.name}' available").default(C64Target.name)
|
||||||
val libDirs by cli.option(ArgType.String, fullName="libdirs", description = "list of extra paths to search in for imported modules").multiple().delimiter(File.pathSeparator)
|
val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths to search in for imported modules").multiple().delimiter(File.pathSeparator)
|
||||||
val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999)
|
val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -61,9 +61,9 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val libdirs = libDirs.toMutableList()
|
val srcdirs = sourceDirs.toMutableList()
|
||||||
if(libdirs.firstOrNull()!=".")
|
if(srcdirs.firstOrNull()!=".")
|
||||||
libdirs.add(0, ".")
|
srcdirs.add(0, ".")
|
||||||
|
|
||||||
if(watchMode==true) {
|
if(watchMode==true) {
|
||||||
val watchservice = FileSystems.getDefault().newWatchService()
|
val watchservice = FileSystems.getDefault().newWatchService()
|
||||||
@ -74,7 +74,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
val results = mutableListOf<CompilationResult>()
|
val results = mutableListOf<CompilationResult>()
|
||||||
for(filepathRaw in moduleFiles) {
|
for(filepathRaw in moduleFiles) {
|
||||||
val filepath = pathFrom(filepathRaw).normalize()
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, libdirs, outputPath)
|
val compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, srcdirs, outputPath)
|
||||||
results.add(compilationResult)
|
results.add(compilationResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
val filepath = pathFrom(filepathRaw).normalize()
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val compilationResult: CompilationResult
|
val compilationResult: CompilationResult
|
||||||
try {
|
try {
|
||||||
compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, libdirs, outputPath)
|
compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, srcdirs, outputPath)
|
||||||
if(!compilationResult.success)
|
if(!compilationResult.success)
|
||||||
return false
|
return false
|
||||||
} catch (x: ParsingFailedError) {
|
} catch (x: ParsingFailedError) {
|
||||||
|
@ -70,7 +70,7 @@ fun compileProgram(filepath: Path,
|
|||||||
writeAssembly: Boolean,
|
writeAssembly: Boolean,
|
||||||
slowCodegenWarnings: Boolean,
|
slowCodegenWarnings: Boolean,
|
||||||
compilationTarget: String,
|
compilationTarget: String,
|
||||||
libdirs: List<String>,
|
sourceDirs: List<String>,
|
||||||
outputDir: Path): CompilationResult {
|
outputDir: Path): CompilationResult {
|
||||||
var programName = ""
|
var programName = ""
|
||||||
lateinit var programAst: Program
|
lateinit var programAst: Program
|
||||||
@ -87,7 +87,7 @@ fun compileProgram(filepath: Path,
|
|||||||
try {
|
try {
|
||||||
val totalTime = measureTimeMillis {
|
val totalTime = measureTimeMillis {
|
||||||
// import main module and everything it needs
|
// import main module and everything it needs
|
||||||
val (ast, compilationOptions, imported) = parseImports(filepath, errors, compTarget, libdirs)
|
val (ast, compilationOptions, imported) = parseImports(filepath, errors, compTarget, sourceDirs)
|
||||||
compilationOptions.slowCodegenWarnings = slowCodegenWarnings
|
compilationOptions.slowCodegenWarnings = slowCodegenWarnings
|
||||||
compilationOptions.optimize = optimize
|
compilationOptions.optimize = optimize
|
||||||
programAst = ast
|
programAst = ast
|
||||||
@ -172,15 +172,15 @@ private class BuiltinFunctionsFacade(functions: Map<String, FSignature>): IBuilt
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun parseImports(filepath: Path,
|
fun parseImports(filepath: Path,
|
||||||
errors: IErrorReporter,
|
errors: IErrorReporter,
|
||||||
compTarget: ICompilationTarget,
|
compTarget: ICompilationTarget,
|
||||||
libdirs: 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}. Parsing...")
|
||||||
val bf = BuiltinFunctionsFacade(BuiltinFunctions)
|
val bf = BuiltinFunctionsFacade(BuiltinFunctions)
|
||||||
val programAst = Program(filepath.nameWithoutExtension, bf, compTarget)
|
val programAst = Program(filepath.nameWithoutExtension, bf, compTarget)
|
||||||
bf.program = programAst
|
bf.program = programAst
|
||||||
|
|
||||||
val importer = ModuleImporter(programAst, compTarget.name, errors, libdirs)
|
val importer = ModuleImporter(programAst, compTarget.name, errors, sourceDirs)
|
||||||
val importedModuleResult = importer.importModule(filepath)
|
val importedModuleResult = importer.importModule(filepath)
|
||||||
importedModuleResult.onFailure { throw it }
|
importedModuleResult.onFailure { throw it }
|
||||||
errors.report()
|
errors.report()
|
||||||
|
@ -18,9 +18,9 @@ import kotlin.io.path.*
|
|||||||
class ModuleImporter(private val program: Program,
|
class ModuleImporter(private val program: Program,
|
||||||
private val compilationTargetName: String,
|
private val compilationTargetName: String,
|
||||||
val errors: IErrorReporter,
|
val errors: IErrorReporter,
|
||||||
libdirs: List<String>) {
|
sourceDirs: List<String>) {
|
||||||
|
|
||||||
private val libpaths: List<Path> = libdirs.map { Path(it) }
|
private val libpaths: List<Path> = sourceDirs.map { Path(it) }
|
||||||
|
|
||||||
fun importModule(filePath: Path): Result<Module, NoSuchFileException> {
|
fun importModule(filePath: Path): Result<Module, NoSuchFileException> {
|
||||||
val currentDir = Path("").absolute()
|
val currentDir = Path("").absolute()
|
||||||
|
@ -41,7 +41,7 @@ class TestCompilerOnExamples {
|
|||||||
writeAssembly = true,
|
writeAssembly = true,
|
||||||
slowCodegenWarnings = false,
|
slowCodegenWarnings = false,
|
||||||
compilationTarget = platform.name,
|
compilationTarget = platform.name,
|
||||||
libdirs = listOf(),
|
sourceDirs = listOf(),
|
||||||
outputDir
|
outputDir
|
||||||
).assertSuccess("; $displayName")
|
).assertSuccess("; $displayName")
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import kotlin.io.path.writeText
|
|||||||
* from source file loading all the way through to running 64tass.
|
* from source file loading all the way through to running 64tass.
|
||||||
*/
|
*/
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestCompilerOptionLibdirs {
|
class TestCompilerOptionSourcedirs {
|
||||||
|
|
||||||
private lateinit var tempFileInWorkingDir: Path
|
private lateinit var tempFileInWorkingDir: Path
|
||||||
|
|
||||||
@ -39,14 +39,14 @@ class TestCompilerOptionLibdirs {
|
|||||||
tempFileInWorkingDir.deleteExisting()
|
tempFileInWorkingDir.deleteExisting()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compileFile(filePath: Path, libdirs: List<String>) =
|
private fun compileFile(filePath: Path, sourceDirs: List<String>) =
|
||||||
compileProgram(
|
compileProgram(
|
||||||
filepath = filePath,
|
filepath = filePath,
|
||||||
optimize = false,
|
optimize = false,
|
||||||
writeAssembly = true,
|
writeAssembly = true,
|
||||||
slowCodegenWarnings = false,
|
slowCodegenWarnings = false,
|
||||||
compilationTarget = Cx16Target.name,
|
compilationTarget = Cx16Target.name,
|
||||||
libdirs,
|
sourceDirs,
|
||||||
outputDir
|
outputDir
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class TestCompilerOptionLibdirs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFilePathInWorkingDirRelativeTo1stInLibdirs() {
|
fun testFilePathInWorkingDirRelativeTo1stInSourcedirs() {
|
||||||
val filepath = assumeReadableFile(tempFileInWorkingDir)
|
val filepath = assumeReadableFile(tempFileInWorkingDir)
|
||||||
compileFile(filepath.fileName, listOf(workingDir.toString()))
|
compileFile(filepath.fileName, listOf(workingDir.toString()))
|
||||||
.assertSuccess()
|
.assertSuccess()
|
||||||
@ -86,10 +86,10 @@ class TestCompilerOptionLibdirs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFilePathOutsideWorkingDirRelativeTo1stInLibdirs() {
|
fun testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs() {
|
||||||
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8")
|
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8")
|
||||||
val libdirs = listOf("$fixturesDir")
|
val sourcedirs = listOf("$fixturesDir")
|
||||||
compileFile(filepath.fileName, libdirs)
|
compileFile(filepath.fileName, sourcedirs)
|
||||||
.assertSuccess()
|
.assertSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ internal fun compileFile(
|
|||||||
writeAssembly = true,
|
writeAssembly = true,
|
||||||
slowCodegenWarnings = false,
|
slowCodegenWarnings = false,
|
||||||
platform.name,
|
platform.name,
|
||||||
libdirs = listOf(),
|
sourceDirs = listOf(),
|
||||||
outputDir
|
outputDir
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -118,11 +118,13 @@ They are embedded into the packaged release version of the compiler so you don't
|
|||||||
where they are, but their names are still reserved.
|
where they are, but their names are still reserved.
|
||||||
|
|
||||||
|
|
||||||
User defined library files and -location
|
Importing other source files and specifying search location(s)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
You can create library files yourself too that can be shared among programs.
|
You can create multiple source files yourself to modularize your large programs into
|
||||||
You can tell the compiler where it should look for these files, by using
|
multiple module files. You can also create "library" modules this way with handy routines,
|
||||||
the libdirs command line option.
|
that can be shared among programs. By importing those module files, you can use them in other modules.
|
||||||
|
It is possible to tell the compiler where it should look for these files, by using
|
||||||
|
the ``srcdirs`` command line option.
|
||||||
|
|
||||||
|
|
||||||
.. _debugging:
|
.. _debugging:
|
||||||
|
@ -3,7 +3,6 @@ TODO
|
|||||||
|
|
||||||
For next compiler release
|
For next compiler release
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
- rename libdirs option to srcdirs?
|
|
||||||
- can we derive module.name from module.source (taking just the filename base)?
|
- can we derive module.name from module.source (taking just the filename base)?
|
||||||
- can Position.file be a Path- making the source variable for nodes unnecessary?
|
- can Position.file be a Path- making the source variable for nodes unnecessary?
|
||||||
- address more questions/issues from the testability discussions.
|
- address more questions/issues from the testability discussions.
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
%import textio
|
%option enable_floats
|
||||||
|
|
||||||
main {
|
main {
|
||||||
str myBar = "main.bar"
|
sub start() {
|
||||||
|
float[] cs = 1 to 42 ; values are computed at compile time
|
||||||
foo_bar:
|
cs[0] = 23 ; keep optimizer from removing it
|
||||||
%asminclude "compiler/test/fixtures/foo_bar.asm" ; FIXME: should be accessible from inside start() but give assembler error
|
}
|
||||||
|
|
||||||
sub start() {
|
|
||||||
txt.print(myBar)
|
|
||||||
txt.print(&foo_bar)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class RequestParser : Take {
|
|||||||
writeAssembly = true,
|
writeAssembly = true,
|
||||||
slowCodegenWarnings = true,
|
slowCodegenWarnings = true,
|
||||||
compilationTarget = "c64",
|
compilationTarget = "c64",
|
||||||
libdirs = emptyList(),
|
sourceDirs = emptyList(),
|
||||||
outputDir = Path.of(".")
|
outputDir = Path.of(".")
|
||||||
)
|
)
|
||||||
return RsJson(Jsonding())
|
return RsJson(Jsonding())
|
||||||
|
Loading…
Reference in New Issue
Block a user