mirror of
https://github.com/irmen/prog8.git
synced 2024-10-24 08:24:25 +00:00
fix import losing statements
This commit is contained in:
parent
d28ce881e4
commit
f98b9c3cb9
@ -1,6 +1,7 @@
|
||||
%zp full
|
||||
%address 33
|
||||
%option enable_floats
|
||||
%option enable_floats
|
||||
|
||||
~ extra {
|
||||
; this is imported
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -32,20 +32,18 @@ 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" ->
|
||||
|
||||
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}")
|
||||
else ->
|
||||
continue
|
||||
}
|
||||
}
|
||||
newStatements.add(stmt)
|
||||
}
|
||||
}
|
||||
}
|
||||
else newStatements.add(stmt)
|
||||
}
|
||||
module.statements = newStatements
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user