mirror of
https://github.com/irmen/prog8.git
synced 2025-01-16 00:31:26 +00:00
reducing ast dependencies
This commit is contained in:
parent
02fae0e722
commit
be75b8dbe5
@ -6,7 +6,6 @@ import prog8.ast.expressions.IdentifierReference
|
||||
import prog8.ast.walk.IAstVisitor
|
||||
import prog8.ast.statements.*
|
||||
import prog8.ast.walk.AstWalker
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import java.nio.file.Path
|
||||
import kotlin.math.abs
|
||||
|
||||
@ -246,8 +245,8 @@ interface IAssignable {
|
||||
|
||||
/*********** Everything starts from here, the Program; zero or more modules *************/
|
||||
|
||||
class Program(val name: String, val modules: MutableList<Module>): Node {
|
||||
val namespace = GlobalNamespace(modules)
|
||||
class Program(val name: String, val modules: MutableList<Module>, builtinFunctionNames: Set<String>): Node {
|
||||
val namespace = GlobalNamespace(modules, builtinFunctionNames)
|
||||
|
||||
val definedLoadAddress: Int
|
||||
get() = modules.first().loadAddress
|
||||
@ -322,7 +321,7 @@ class Module(override val name: String,
|
||||
}
|
||||
|
||||
|
||||
class GlobalNamespace(val modules: List<Module>): Node, INameScope {
|
||||
class GlobalNamespace(val modules: List<Module>, private val builtinFunctionNames: Set<String>): Node, INameScope {
|
||||
override val name = "<<<global>>>"
|
||||
override val position = Position("<<<global>>>", 0, 0, 0)
|
||||
override val statements = mutableListOf<Statement>() // not used
|
||||
@ -337,7 +336,7 @@ class GlobalNamespace(val modules: List<Module>): Node, INameScope {
|
||||
}
|
||||
|
||||
override fun lookup(scopedName: List<String>, localContext: Node): Statement? {
|
||||
if (scopedName.size == 1 && scopedName[0] in BuiltinFunctions) {
|
||||
if (scopedName.size == 1 && scopedName[0] in builtinFunctionNames) {
|
||||
// builtin functions always exist, return a dummy localContext for them
|
||||
val builtinPlaceholder = Label("builtin::${scopedName.last()}", localContext.position)
|
||||
builtinPlaceholder.parent = ParentSentinel
|
||||
|
@ -4,9 +4,15 @@ import prog8.ast.AstToSourceCode
|
||||
import prog8.ast.Program
|
||||
import prog8.ast.base.*
|
||||
import prog8.ast.statements.Directive
|
||||
import prog8.compiler.astprocessing.*
|
||||
import prog8.compiler.astprocessing.addTypecasts
|
||||
import prog8.compiler.astprocessing.checkValid
|
||||
import prog8.compiler.astprocessing.processAstBeforeAsmGeneration
|
||||
import prog8.compiler.astprocessing.reorderStatements
|
||||
import prog8.compiler.target.C64Target
|
||||
import prog8.compiler.target.CompilationTarget
|
||||
import prog8.compiler.target.Cx16Target
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import prog8.optimizer.*
|
||||
import prog8.optimizer.UnusedCodeRemover
|
||||
import prog8.optimizer.constantFold
|
||||
@ -91,13 +97,13 @@ fun compileProgram(filepath: Path,
|
||||
throw x
|
||||
}
|
||||
|
||||
return CompilationResult(false, Program("failed", mutableListOf()), programName, emptyList())
|
||||
return CompilationResult(false, Program("failed", mutableListOf(), setOf()), programName, emptyList())
|
||||
}
|
||||
|
||||
private fun parseImports(filepath: Path, errors: ErrorReporter): Triple<Program, CompilationOptions, List<Path>> {
|
||||
println("Compiler target: ${CompilationTarget.instance.name}. Parsing...")
|
||||
val importer = ModuleImporter()
|
||||
val programAst = Program(moduleName(filepath.fileName), mutableListOf())
|
||||
val programAst = Program(moduleName(filepath.fileName), mutableListOf(), BuiltinFunctions.keys)
|
||||
importer.importModule(programAst, filepath)
|
||||
errors.handle()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.INameScope
|
||||
import prog8.ast.Module
|
||||
@ -999,7 +999,8 @@ internal class AstChecker(private val program: Program,
|
||||
}
|
||||
}
|
||||
|
||||
val error = VerifyFunctionArgTypes.checkTypes(functionCallStatement, functionCallStatement.definingScope(), program)
|
||||
val error =
|
||||
VerifyFunctionArgTypes.checkTypes(functionCallStatement, functionCallStatement.definingScope(), program)
|
||||
if(error!=null) {
|
||||
errors.err(error, functionCallStatement.args.firstOrNull()?.position ?: functionCallStatement.position)
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package prog8.compiler
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.Module
|
||||
import prog8.ast.Program
|
||||
import prog8.ast.base.ErrorReporter
|
||||
import prog8.ast.base.FatalAstException
|
||||
import prog8.ast.processing.*
|
||||
import prog8.ast.statements.Directive
|
||||
import prog8.compiler.BeforeAsmGenerationAstChanger
|
||||
import prog8.compiler.CompilationOptions
|
||||
|
||||
|
||||
internal fun Program.checkValid(compilerOptions: CompilationOptions, errors: ErrorReporter) {
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.Module
|
||||
import prog8.ast.Program
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.Node
|
||||
import prog8.ast.Program
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.INameScope
|
||||
import prog8.ast.Node
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.Node
|
||||
import prog8.ast.Program
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
|
||||
/*
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.*
|
||||
import prog8.ast.base.*
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.INameScope
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.INameScope
|
||||
import prog8.ast.Node
|
@ -1,4 +1,4 @@
|
||||
package prog8.ast.processing
|
||||
package prog8.compiler.astprocessing
|
||||
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.INameScope
|
@ -8,7 +8,7 @@ import prog8.ast.base.Position
|
||||
import prog8.ast.base.SyntaxError
|
||||
import prog8.ast.statements.Directive
|
||||
import prog8.ast.statements.DirectiveArg
|
||||
import prog8.compiler.checkImportedValid
|
||||
import prog8.compiler.astprocessing.checkImportedValid
|
||||
import prog8.compiler.target.CompilationTarget
|
||||
import prog8.pathFrom
|
||||
import java.io.InputStream
|
||||
|
Loading…
x
Reference in New Issue
Block a user