diff --git a/il65/src/il65/Main.kt b/il65/src/il65/Main.kt index d1ffc9213..c02df9d43 100644 --- a/il65/src/il65/Main.kt +++ b/il65/src/il65/Main.kt @@ -25,21 +25,20 @@ fun main(args: Array) { val filepath = Paths.get(args[0]).normalize() val moduleAst = importModule(filepath) moduleAst.linkParents() - val globalNamespace = moduleAst.definingScope() - // globalNamespace.debugPrint() + val globalNameSpaceBeforeOptimization = moduleAst.definingScope() // perform syntax checks and optimizations - moduleAst.checkIdentifiers() - moduleAst.optimizeExpressions(globalNamespace) - moduleAst.checkValid(globalNamespace) // check if tree is valid + moduleAst.optimizeExpressions(globalNameSpaceBeforeOptimization) + moduleAst.checkValid(globalNameSpaceBeforeOptimization) // check if tree is valid val allScopedSymbolDefinitions = moduleAst.checkIdentifiers() - moduleAst.optimizeStatements(globalNamespace, allScopedSymbolDefinitions) + moduleAst.optimizeStatements(globalNameSpaceBeforeOptimization, allScopedSymbolDefinitions) val globalNamespaceAfterOptimize = moduleAst.definingScope() // it could have changed in the meantime moduleAst.checkValid(globalNamespaceAfterOptimize) // check if final tree is valid moduleAst.checkRecursion() // check if there are recursive subroutine calls + // globalNamespaceAfterOptimize.debugPrint() // determine special compiler options diff --git a/il65/src/il65/ast/AST.kt b/il65/src/il65/ast/AST.kt index 3a7ebc916..5c513db20 100644 --- a/il65/src/il65/ast/AST.kt +++ b/il65/src/il65/ast/AST.kt @@ -347,11 +347,7 @@ class Module(override val name: String, processor.process(this) } - private val theGlobalNamespace by lazy { - GlobalNamespace("<<>>", statements, position) - } - - override fun definingScope(): INameScope = theGlobalNamespace + override fun definingScope(): INameScope = GlobalNamespace("<<>>", statements, position) override fun usedNames(): Set = throw NotImplementedError("not implemented on sub-scopes") override fun registerUsedName(name: String) = throw NotImplementedError("not implemented on sub-scopes") diff --git a/il65/src/il65/optimizing/ExpressionOptimizer.kt b/il65/src/il65/optimizing/ExpressionOptimizer.kt index 4befad41f..037976293 100644 --- a/il65/src/il65/optimizing/ExpressionOptimizer.kt +++ b/il65/src/il65/optimizing/ExpressionOptimizer.kt @@ -14,10 +14,10 @@ fun Module.optimizeExpressions(globalNamespace: INameScope) { } if(optimizer.optimizationsDone==0) - println("[${this.name}] 0 optimizations performed") + println("[${this.name}] 0 expression optimizations performed") while(optimizer.errors.isEmpty() && optimizer.optimizationsDone>0) { - println("[${this.name}] ${optimizer.optimizationsDone} optimizations performed") + println("[${this.name}] ${optimizer.optimizationsDone} expression optimizations performed") optimizer.optimizationsDone = 0 this.process(optimizer) } diff --git a/il65/src/il65/optimizing/StatementsOptimizer.kt b/il65/src/il65/optimizing/StatementsOptimizer.kt index a25c6ac66..0a57c78ad 100644 --- a/il65/src/il65/optimizing/StatementsOptimizer.kt +++ b/il65/src/il65/optimizing/StatementsOptimizer.kt @@ -8,10 +8,10 @@ fun Module.optimizeStatements(globalNamespace: INameScope, allScopedSymbolDefini this.process(optimizer) optimizer.removeUnusedNodes(globalNamespace.usedNames(), allScopedSymbolDefinitions) if(optimizer.optimizationsDone==0) - println("[${this.name}] 0 optimizations performed") + println("[${this.name}] 0 statement optimizations performed") while(optimizer.optimizationsDone>0) { - println("[${this.name}] ${optimizer.optimizationsDone} optimizations performed") + println("[${this.name}] ${optimizer.optimizationsDone} statement optimizations performed") optimizer.reset() this.process(optimizer) } @@ -91,7 +91,10 @@ class StatementOptimizer(private val globalNamespace: INameScope) : IAstProcesso if(!usedNames.contains(name)) { val parentScope = value.parent as INameScope val localname = name.substringAfterLast(".") - println("${value.position} Warning: ${value::class.simpleName} '$localname' is never used") + // printing every possible node that is removed can result in many dozens of warnings. + // we chose to just print the blocks that aren't used. + if(value is Block) + println("${value.position} Info: block '$localname' is never used") parentScope.removeStatement(value) optimizationsDone++ }