diff --git a/il65/examples/imported.ill b/il65/examples/imported.ill index 836c4b2f6..26e27de22 100644 --- a/il65/examples/imported.ill +++ b/il65/examples/imported.ill @@ -1,6 +1,7 @@ %zp full %address 33 %option enable_floats +%option enable_floats ~ extra { ; this is imported diff --git a/il65/examples/test.ill b/il65/examples/test.ill index b027b9263..220e71b62 100644 --- a/il65/examples/test.ill +++ b/il65/examples/test.ill @@ -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 diff --git a/il65/src/il65/Main.kt b/il65/src/il65/Main.kt index af952f5ba..cc68601cc 100644 --- a/il65/src/il65/Main.kt +++ b/il65/src/il65/Main.kt @@ -22,6 +22,12 @@ fun main(args: Array) { 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) diff --git a/il65/src/il65/ast/AstChecker.kt b/il65/src/il65/ast/AstChecker.kt index b17806a7d..e31f61fc0 100644 --- a/il65/src/il65/ast/AstChecker.kt +++ b/il65/src/il65/ast/AstChecker.kt @@ -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) } diff --git a/il65/src/il65/ast/ImportedAstChecker.kt b/il65/src/il65/ast/ImportedAstChecker.kt index f9d1ff971..81517b43e 100644 --- a/il65/src/il65/ast/ImportedAstChecker.kt +++ b/il65/src/il65/ast/ImportedAstChecker.kt @@ -32,19 +32,17 @@ class ImportedAstChecker : IAstProcessor { override fun process(module: Module) { super.process(module) val newStatements : MutableList = 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 }