fix import losing statements

This commit is contained in:
Irmen de Jong 2018-08-16 17:08:26 +02:00
parent d28ce881e4
commit f98b9c3cb9
5 changed files with 20 additions and 12 deletions

View File

@ -1,6 +1,7 @@
%zp full
%address 33
%option enable_floats
%option enable_floats
~ extra {
; this is imported

View File

@ -84,6 +84,9 @@ some_label_def: A=44
%asmbinary "derp", 0, 200
}
%option enable_floats
%option enable_floats
%option enable_floats
%import imported
%import imported

View File

@ -22,6 +22,12 @@ fun main(args: Array<String>) {
moduleAst.optimizeStatements(globalNamespace)
moduleAst.checkValid(globalNamespace) // check if final tree is valid
// determine special compiler options
val options = moduleAst.statements.filter { it is Directive && it.directive=="%option" }.flatMap { (it as Directive).args }.toSet()
val optionEnableFloats = options.contains(DirectiveArg(null, "enable_floats", null))
if(optionEnableFloats) println("Compiler: floats enabled")
// todo compile to asm...
moduleAst.statements.forEach {
println(it)

View File

@ -273,7 +273,7 @@ class AstChecker(private val globalNamespace: INameScope) : IAstProcessor {
"%option" -> {
if(directive.parent !is Module) err("this directive may only occur at module level")
if(directive.args.size!=1 || directive.args[0].name != "enable_floats")
err("invalid option directive argument, expected enable_floats")
err("invalid option directive argument(s)")
}
else -> throw SyntaxError("invalid directive ${directive.directive}", directive.position)
}

View File

@ -32,19 +32,17 @@ class ImportedAstChecker : IAstProcessor {
override fun process(module: Module) {
super.process(module)
val newStatements : MutableList<IStatement> = mutableListOf()
module.statements.forEach {
val stmt = it.process(this)
if(stmt is Directive) {
if(stmt.parent is Module) {
when(stmt.directive) {
"%output", "%launcher", "%zp", "%address" ->
println("${stmt.position} Warning: ignoring module directive because it was imported: ${stmt.directive}")
else ->
newStatements.add(stmt)
}
val moduleLevelDirectives = listOf("%output", "%launcher", "%zp", "%address")
for (sourceStmt in module.statements) {
val stmt = sourceStmt.process(this)
if(stmt is Directive && stmt.parent is Module) {
if(moduleLevelDirectives.contains(stmt.directive)) {
println("${stmt.position} Warning: ignoring module directive because it was imported: ${stmt.directive}")
continue
}
}
else newStatements.add(stmt)
newStatements.add(stmt)
}
module.statements = newStatements
}