reducing dependencies

This commit is contained in:
Irmen de Jong 2022-03-10 23:08:41 +01:00
parent 9a798360f4
commit e75d0c58a9
85 changed files with 292 additions and 148 deletions

42
codeAst/build.gradle Normal file
View File

@ -0,0 +1,42 @@
plugins {
id 'java'
id 'application'
id "org.jetbrains.kotlin.jvm"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
}
compileKotlin {
kotlinOptions {
jvmTarget = javaVersion
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = javaVersion
}
}
dependencies {
implementation project(':codeCore')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
sourceSets {
main {
java {
srcDirs = ["${project.projectDir}/src"]
}
resources {
srcDirs = ["${project.projectDir}/res"]
}
}
}
// note: there are no unit tests in this module!

View File

@ -1,4 +1,5 @@
package prog8.compilerinterface
package prog8.code
import prog8.code.core.DataType
import prog8.code.core.Encoding
@ -32,7 +33,7 @@ class SymbolTable : StNode("", StNodeType.GLOBAL, Position.DUMMY) {
val vars = mutableListOf<StStaticVariable>()
fun collect(node: StNode) {
for(child in node.children) {
if(child.value.type==StNodeType.STATICVAR)
if(child.value.type== StNodeType.STATICVAR)
vars.add(child.value as StStaticVariable)
else
collect(child.value)
@ -93,7 +94,7 @@ open class StNode(val name: String,
private fun lookupQualified(scopedName: List<String>): StNode? {
// a scoped name refers to a name in another namespace, and always stars from the root.
var node = this
while(node.type!=StNodeType.GLOBAL)
while(node.type!= StNodeType.GLOBAL)
node = node.parent
for(name in scopedName) {
@ -108,10 +109,10 @@ open class StNode(val name: String,
private fun lookupUnqualified(name: String): StNode? {
// first consider the builtin functions
var globalscope = this
while(globalscope.type!=StNodeType.GLOBAL)
while(globalscope.type!= StNodeType.GLOBAL)
globalscope = globalscope.parent
val globalNode = globalscope.children[name]
if(globalNode!=null && globalNode.type==StNodeType.BUILTINFUNC)
if(globalNode!=null && globalNode.type== StNodeType.BUILTINFUNC)
return globalNode
// search for the unqualified name in the current scope or its parent scopes
@ -120,7 +121,7 @@ open class StNode(val name: String,
val node = scope.children[name]
if(node!=null)
return node
if(scope.type==StNodeType.GLOBAL)
if(scope.type== StNodeType.GLOBAL)
return null
else
scope = scope.parent

View File

@ -4,7 +4,7 @@ import prog8.code.core.IMemSizer
import prog8.code.core.IStringEncoding
import prog8.code.core.Position
// New (work-in-progress) simplified AST for the code generator.
// TODO : once the CodeGen doesn't need the old Ast anymore, get rid of the 'Pt' prefixes ?

41
codeCore/build.gradle Normal file
View File

@ -0,0 +1,41 @@
plugins {
id 'java'
id 'application'
id "org.jetbrains.kotlin.jvm"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
}
compileKotlin {
kotlinOptions {
jvmTarget = javaVersion
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = javaVersion
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
sourceSets {
main {
java {
srcDirs = ["${project.projectDir}/src"]
}
resources {
srcDirs = ["${project.projectDir}/res"]
}
}
}
// note: there are no unit tests in this module!

View File

@ -151,3 +151,24 @@ val Cx16VirtualRegisters = arrayOf(
RegisterOrPair.R8, RegisterOrPair.R9, RegisterOrPair.R10, RegisterOrPair.R11,
RegisterOrPair.R12, RegisterOrPair.R13, RegisterOrPair.R14, RegisterOrPair.R15
)
enum class OutputType {
RAW,
PRG,
XEX
}
enum class CbmPrgLauncherType {
BASIC,
NONE
}
enum class ZeropageType {
BASICSAFE,
FLOATSAFE,
KERNALSAFE,
FULL,
DONTUSE
}

View File

@ -1,7 +1,7 @@
package prog8.compilerinterface
package prog8.code.core
class InternalCompilerException(message: String?) : Exception(message)
class AbortCompilation(message: String?) : Exception(message)
class AssemblyError(msg: String) : RuntimeException(msg)
class ErrorsReportedException(message: String?) : Exception(message)

View File

@ -0,0 +1,23 @@
package prog8.code.core
import java.nio.file.Path
interface IAssemblyGenerator {
fun compileToAssembly(): IAssemblyProgram?
}
interface IAssemblyProgram {
val name: String
fun assemble(options: AssemblerOptions): Boolean
}
fun viceMonListName(baseFilename: String) = "$baseFilename.vice-mon-list"
class AssemblerOptions(
val output: OutputType,
var asmQuiet: Boolean = false,
var asmListfile: Boolean = false,
var outputDir: Path
)

View File

@ -1,6 +1,4 @@
package prog8.compilerinterface
import prog8.code.core.Position
package prog8.code.core
interface IErrorReporter {
fun err(msg: String, position: Position)
@ -9,7 +7,6 @@ interface IErrorReporter {
fun report()
fun finalizeNumErrors(numErrors: Int, numWarnings: Int) {
if(numErrors>0)
throw AbortCompilation("There are $numErrors errors and $numWarnings warnings.")
throw ErrorsReportedException("There are $numErrors errors and $numWarnings warnings.")
}
}

View File

@ -24,8 +24,10 @@ compileTestKotlin {
}
dependencies {
implementation project(':compilerInterfaces')
implementation project(':codeAst')
implementation project(':codeCore')
implementation project(':compilerAst')
implementation project(':compilerInterfaces')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.14"

View File

@ -9,9 +9,10 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="codeAst" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="codeCore" />
</component>
</module>

View File

@ -5,6 +5,7 @@ import prog8.ast.*
import prog8.ast.base.FatalAstException
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.code.SymbolTable
import prog8.code.core.*
import prog8.codegen.cpu6502.assignment.*
import prog8.compilerinterface.*

View File

@ -3,6 +3,7 @@ package prog8.codegen.cpu6502
import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.mapError
import prog8.code.core.*
import prog8.compilerinterface.*
import prog8.parser.SourceCode
import java.io.File
@ -23,7 +24,7 @@ internal class AssemblyProgram(
private val viceMonListFile = outputDir.resolve(viceMonListName(name))
private val listFile = outputDir.resolve("$name.list")
override fun assemble(options: CompilationOptions): Boolean {
override fun assemble(options: AssemblerOptions): Boolean {
val assemblerCommand: List<String>

View File

@ -1606,7 +1606,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
private fun translateArguments(args: MutableList<Expression>, signature: FSignature, scope: Subroutine?) {
val callConv = signature.callConvention(args.map {
it.inferType(program).getOrElse { throw AssemblyError("unknown dt")}
it.inferType(program).getOrElse { throw AssemblyError("unknown dt") }
})
fun getSourceForFloat(value: Expression): AsmAssignSource {

View File

@ -3,7 +3,7 @@ package prog8.codegen.cpu6502
import prog8.ast.Program
import prog8.ast.expressions.*
import prog8.code.core.*
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
import prog8.compilerinterface.CpuType
import kotlin.math.absoluteValue

View File

@ -9,7 +9,7 @@ import prog8.code.core.ArrayToElementTypes
import prog8.code.core.DataType
import prog8.code.core.RegisterOrPair
import prog8.code.core.toHex
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
import prog8.compilerinterface.Zeropage
import kotlin.math.absoluteValue

View File

@ -13,7 +13,7 @@ import prog8.codegen.cpu6502.assignment.AsmAssignSource
import prog8.codegen.cpu6502.assignment.AsmAssignTarget
import prog8.codegen.cpu6502.assignment.AsmAssignment
import prog8.codegen.cpu6502.assignment.TargetStorageKind
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
internal class FunctionCallAsmGen(private val program: Program, private val asmgen: AsmGen) {

View File

@ -5,7 +5,7 @@ import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.NumericLiteral
import prog8.ast.statements.PostIncrDecr
import prog8.code.core.*
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
internal class PostIncrDecrAsmGen(private val program: Program, private val asmgen: AsmGen) {

View File

@ -3,6 +3,7 @@ package prog8.codegen.cpu6502
import prog8.ast.Program
import prog8.ast.antlr.escape
import prog8.ast.statements.*
import prog8.code.*
import prog8.code.core.*
import prog8.codegen.cpu6502.assignment.AsmAssignTarget
import prog8.codegen.cpu6502.assignment.TargetStorageKind

View File

@ -2,15 +2,15 @@ package prog8.codegen.cpu6502
import com.github.michaelbull.result.fold
import com.github.michaelbull.result.onSuccess
import prog8.code.core.ArrayDatatypes
import prog8.code.core.DataType
import prog8.code.core.IntegerDatatypes
import prog8.code.*
import prog8.code.core.*
import prog8.compilerinterface.*
internal class VariableAllocator(private val symboltable: SymbolTable,
private val options: CompilationOptions,
private val errors: IErrorReporter) {
private val errors: IErrorReporter
) {
private val zeropage = options.compTarget.machine.zeropage
private val memorySlabsInternal = mutableMapOf<String, Pair<UInt, UInt>>()
@ -126,7 +126,7 @@ internal class VariableAllocator(private val symboltable: SymbolTable,
val vars = mutableListOf<StStaticVariable>()
fun collect(node: StNode) {
for(child in node.children) {
if(child.value.type==StNodeType.STATICVAR)
if(child.value.type == StNodeType.STATICVAR)
vars.add(child.value as StStaticVariable)
else
collect(child.value)

View File

@ -5,7 +5,7 @@ import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.code.core.*
import prog8.codegen.cpu6502.AsmGen
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
internal enum class TargetStorageKind {

View File

@ -6,7 +6,7 @@ import prog8.ast.statements.*
import prog8.code.core.*
import prog8.codegen.cpu6502.AsmGen
import prog8.codegen.cpu6502.VariableAllocator
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
import prog8.compilerinterface.CpuType
import prog8.compilerinterface.builtinFunctionReturnType

View File

@ -7,7 +7,7 @@ import prog8.ast.statements.Subroutine
import prog8.code.core.*
import prog8.codegen.cpu6502.AsmGen
import prog8.codegen.cpu6502.VariableAllocator
import prog8.compilerinterface.AssemblyError
import prog8.code.core.AssemblyError
import prog8.compilerinterface.CpuType

View File

@ -24,7 +24,8 @@ compileTestKotlin {
}
dependencies {
implementation project(':compilerInterfaces')
implementation project(':codeAst')
implementation project(':codeCore')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.14"

View File

@ -9,8 +9,8 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="codeAst" />
<orderEntry type="module" module-name="codeCore" />
</component>
</module>

View File

@ -1,13 +1,26 @@
package prog8.codegen.experimental6502
import prog8.code.SymbolTable
import prog8.code.ast.PtProgram
import prog8.compilerinterface.*
import prog8.code.core.AssemblerOptions
import prog8.code.core.IAssemblyGenerator
import prog8.code.core.IAssemblyProgram
import prog8.code.core.IErrorReporter
/*
NOTE: The goal is to keep the dependencies as lean as possible! For now, we depend only on:
- codeAst (the 'lean' new AST and the SymbolTable)
- codeCore (various base enums and interfaces)
This *should* be enough to build a complete code generator with. But we'll see :)
*/
class AsmGen(internal val program: PtProgram,
internal val errors: IErrorReporter,
internal val symbolTable: SymbolTable,
internal val options: CompilationOptions
internal val options: AssemblerOptions // TODO this may not be enough, maybe we actually need the other CompilationOptions as well
): IAssemblyGenerator {
override fun compileToAssembly(): IAssemblyProgram? {

View File

@ -1,12 +1,12 @@
package prog8.codegen.experimental6502
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.IAssemblyProgram
import prog8.code.core.AssemblerOptions
import prog8.code.core.IAssemblyProgram
internal class AssemblyProgram(override val name: String) : IAssemblyProgram
{
override fun assemble(options: CompilationOptions): Boolean {
override fun assemble(options: AssemblerOptions): Boolean {
println("..todo: assemble code into binary..")
return false
}

View File

@ -24,8 +24,9 @@ compileTestKotlin {
}
dependencies {
implementation project(':compilerInterfaces')
implementation project(':codeCore')
implementation project(':compilerAst')
implementation project(':compilerInterfaces')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.14"

View File

@ -6,7 +6,7 @@ import prog8.code.core.IStringEncoding
import prog8.codegen.target.cbm.AtasciiEncoding
import prog8.codegen.target.cbm.IsoEncoding
import prog8.codegen.target.cbm.PetsciiEncoding
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
internal object Encoder: IStringEncoding {

View File

@ -1,5 +1,7 @@
package prog8.codegen.target.atari
import prog8.code.core.CbmPrgLauncherType
import prog8.code.core.OutputType
import prog8.codegen.target.c64.normal6502instructions
import prog8.compilerinterface.*
import java.nio.file.Path

View File

@ -1,9 +1,9 @@
package prog8.codegen.target.atari
import prog8.code.core.ZeropageType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import prog8.compilerinterface.Zeropage
import prog8.compilerinterface.ZeropageType
class AtariZeropage(options: CompilationOptions) : Zeropage(options) {

View File

@ -1,5 +1,8 @@
package prog8.codegen.target.c128
import prog8.code.core.CbmPrgLauncherType
import prog8.code.core.OutputType
import prog8.code.core.viceMonListName
import prog8.codegen.target.c64.normal6502instructions
import prog8.codegen.target.cbm.Mflpt5
import prog8.compilerinterface.*

View File

@ -1,9 +1,10 @@
package prog8.codegen.target.c128
import prog8.code.core.ZeropageType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import prog8.compilerinterface.Zeropage
import prog8.compilerinterface.ZeropageType
class C128Zeropage(options: CompilationOptions) : Zeropage(options) {

View File

@ -1,5 +1,8 @@
package prog8.codegen.target.c64
import prog8.code.core.CbmPrgLauncherType
import prog8.code.core.OutputType
import prog8.code.core.viceMonListName
import prog8.codegen.target.cbm.Mflpt5
import prog8.compilerinterface.*
import java.io.IOException

View File

@ -1,9 +1,10 @@
package prog8.codegen.target.c64
import prog8.code.core.ZeropageType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import prog8.compilerinterface.Zeropage
import prog8.compilerinterface.ZeropageType
class C64Zeropage(options: CompilationOptions) : Zeropage(options) {

View File

@ -1,7 +1,7 @@
package prog8.codegen.target.cbm
import prog8.compilerinterface.IMachineFloat
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import kotlin.math.absoluteValue
import kotlin.math.pow

View File

@ -1,5 +1,8 @@
package prog8.codegen.target.cx16
import prog8.code.core.CbmPrgLauncherType
import prog8.code.core.OutputType
import prog8.code.core.viceMonListName
import prog8.codegen.target.cbm.Mflpt5
import prog8.compilerinterface.*
import java.nio.file.Path

View File

@ -1,10 +1,10 @@
package prog8.codegen.target.cx16
import prog8.code.core.DataType
import prog8.code.core.ZeropageType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import prog8.compilerinterface.Zeropage
import prog8.compilerinterface.ZeropageType
class CX16Zeropage(options: CompilationOptions) : Zeropage(options) {

View File

@ -24,6 +24,7 @@ compileTestKotlin {
}
dependencies {
implementation project(':codeCore')
implementation project(':compilerInterfaces')
implementation project(':compilerAst')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

View File

@ -9,8 +9,8 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="module" module-name="compilerInterfaces" />
</component>
</module>

View File

@ -10,8 +10,8 @@ import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.code.core.*
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.IErrorReporter
import prog8.code.core.InternalCompilerException
// Fix up the literal value's type to match that of the vardecl
// (also check range literal operands types before they get expanded into arrays for instance)

View File

@ -9,7 +9,7 @@ import prog8.ast.walk.IAstModification
import prog8.code.core.DataType
import prog8.code.core.IntegerDatatypes
import prog8.code.core.NumericDatatypes
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import kotlin.math.abs
import kotlin.math.log2
import kotlin.math.pow

View File

@ -4,7 +4,7 @@ import prog8.ast.IBuiltinFunctions
import prog8.ast.Program
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
fun Program.constantFold(errors: IErrorReporter, compTarget: ICompilationTarget) {

View File

@ -9,14 +9,14 @@ import prog8.code.core.ArrayDatatypes
import prog8.code.core.DataType
import prog8.code.core.IntegerDatatypes
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import kotlin.math.floor
class StatementOptimizer(private val program: Program,
private val errors: IErrorReporter,
private val functions: IBuiltinFunctions,
private val compTarget: ICompilationTarget
private val errors: IErrorReporter,
private val functions: IBuiltinFunctions,
private val compTarget: ICompilationTarget
) : AstWalker() {
override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {

View File

@ -8,7 +8,7 @@ import prog8.ast.walk.IAstModification
import prog8.code.core.DataType
import prog8.compilerinterface.CallGraph
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import prog8.compilerinterface.isIOAddress

View File

@ -27,6 +27,8 @@ compileTestKotlin {
def prog8version = rootProject.file('compiler/res/version.txt').text.trim()
dependencies {
implementation project(':codeAst')
implementation project(':codeCore')
implementation project(':compilerInterfaces')
implementation project(':codeOptimizers')
implementation project(':compilerAst')

View File

@ -11,19 +11,18 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="codeOptimizers" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="codeGenTargets" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="antlr.antlr4" level="project" />
<orderEntry type="module" module-name="codeGenCpu6502" />
<orderEntry type="module" module-name="codeGenExperimental6502" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="codeAst" />
<orderEntry type="module" module-name="codeAst" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="codeOptimizers" />
<orderEntry type="module" module-name="codeGenTargets" />
<orderEntry type="module" module-name="codeGenCpu6502" />
<orderEntry type="module" module-name="codeGenExperimental6502" />
</component>
</module>

View File

@ -2,6 +2,7 @@ package prog8
import kotlinx.cli.*
import prog8.ast.base.AstException
import prog8.code.core.CbmPrgLauncherType
import prog8.codegen.target.AtariTarget
import prog8.codegen.target.C128Target
import prog8.codegen.target.C64Target
@ -9,7 +10,6 @@ import prog8.codegen.target.Cx16Target
import prog8.compiler.CompilationResult
import prog8.compiler.CompilerArguments
import prog8.compiler.compileProgram
import prog8.compilerinterface.CbmPrgLauncherType
import java.io.File
import java.nio.file.FileSystems
import java.nio.file.Path

View File

@ -11,7 +11,8 @@ import prog8.ast.expressions.NumericLiteral
import prog8.ast.statements.Directive
import prog8.ast.statements.VarDecl
import prog8.ast.walk.IAstVisitor
import prog8.code.core.Position
import prog8.code.SymbolTable
import prog8.code.core.*
import prog8.codegen.target.AtariTarget
import prog8.codegen.target.C128Target
import prog8.codegen.target.C64Target
@ -117,7 +118,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
System.err.print("\n\u001b[91m") // bright red
System.err.println("${px.position.toClickableStr()} parse error: ${px.message}".trim())
System.err.print("\u001b[0m") // reset
} catch (ac: AbortCompilation) {
} catch (ac: ErrorsReportedException) {
if(!ac.message.isNullOrEmpty()) {
System.err.print("\n\u001b[91m") // bright red
System.err.println(ac.message)
@ -360,7 +361,13 @@ private fun createAssemblyAndAssemble(program: Program,
errors.report()
return if(assembly!=null && errors.noErrors()) {
assembly.assemble(compilerOptions)
val options = AssemblerOptions(
compilerOptions.output,
compilerOptions.asmQuiet,
compilerOptions.asmListfile,
compilerOptions.outputDir
)
assembly.assemble(options)
} else {
false
}
@ -403,7 +410,13 @@ internal fun asmGeneratorFor(program: Program,
// TODO for now, only use the new Intermediary Ast for this experimental codegen:
val intermediateAst = IntermediateAstMaker(program).transform()
return prog8.codegen.experimental6502.AsmGen(intermediateAst, errors, symbolTable, options)
val asmOptions = AssemblerOptions(
options.output,
options.asmQuiet,
options.asmListfile,
options.outputDir
)
return prog8.codegen.experimental6502.AsmGen(intermediateAst, errors, symbolTable, asmOptions)
}
} else {
if (options.compTarget.machine.cpu in arrayOf(CpuType.CPU6502, CpuType.CPU65c02))

View File

@ -1,7 +1,7 @@
package prog8.compiler
import prog8.code.core.Position
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class ErrorReporter: IErrorReporter {

View File

@ -7,7 +7,7 @@ import prog8.ast.base.SyntaxError
import prog8.ast.statements.Directive
import prog8.ast.statements.DirectiveArg
import prog8.code.core.Position
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import prog8.parser.Prog8Parser
import prog8.parser.SourceCode
import java.io.File

View File

@ -13,7 +13,7 @@ import prog8.code.core.DataType
import prog8.code.core.Encoding
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal fun Program.checkValid(errors: IErrorReporter, compilerOptions: CompilationOptions) {

View File

@ -11,7 +11,7 @@ import prog8.ast.walk.IAstVisitor
import prog8.code.core.Position
import prog8.compilerinterface.BuiltinFunctions
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class AstIdentifiersChecker(private val errors: IErrorReporter,

View File

@ -11,8 +11,8 @@ import prog8.ast.walk.IAstModification
import prog8.code.core.Encoding
import prog8.code.core.NumericDatatypes
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.IErrorReporter
import prog8.code.core.InternalCompilerException
class AstPreprocessor(val program: Program, val errors: IErrorReporter, val compTarget: ICompilationTarget) : AstWalker() {

View File

@ -7,9 +7,7 @@ import prog8.ast.statements.*
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.ast.walk.IAstVisitor
import prog8.code.core.DataType
import prog8.code.core.NumericDatatypes
import prog8.code.core.Position
import prog8.code.core.*
import prog8.compilerinterface.*
internal class BeforeAsmAstChanger(val program: Program,

View File

@ -12,7 +12,7 @@ import prog8.code.core.ByteDatatypes
import prog8.code.core.DataType
import prog8.code.core.PassByReferenceDatatypes
import prog8.code.core.WordDatatypes
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class BeforeAsmTypecastCleaner(val program: Program,

View File

@ -9,7 +9,7 @@ import prog8.ast.statements.*
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.code.core.Position
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
private var generatedLabelSequenceNumber: Int = 0

View File

@ -14,12 +14,13 @@ import prog8.ast.walk.IAstModification
import prog8.code.core.DataType
import prog8.code.core.Encoding
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class LiteralsToAutoVars(private val program: Program,
private val target: ICompilationTarget,
private val errors: IErrorReporter) : AstWalker() {
private val errors: IErrorReporter
) : AstWalker() {
override fun after(string: StringLiteral, parent: Node): Iterable<IAstModification> {
if(string.encoding != Encoding.DEFAULT && string.encoding !in target.supportedEncodings) {

View File

@ -10,7 +10,7 @@ import prog8.code.core.*
import prog8.compilerinterface.BuiltinFunctions
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class StatementReorderer(val program: Program,
val errors: IErrorReporter,

View File

@ -5,8 +5,8 @@ import prog8.ast.base.FatalAstException
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.ast.walk.IAstVisitor
import prog8.code.*
import prog8.code.core.Position
import prog8.compilerinterface.*
import java.util.*
internal class SymbolTableMaker: IAstVisitor {

View File

@ -14,7 +14,7 @@ import prog8.code.core.IterableDatatypes
import prog8.code.core.PassByReferenceDatatypes
import prog8.compilerinterface.BuiltinFunctions
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
class TypecastsAdder(val program: Program, val options: CompilationOptions, val errors: IErrorReporter) : AstWalker() {

View File

@ -14,7 +14,7 @@ import prog8.ast.walk.IAstModification
import prog8.code.core.ArrayDatatypes
import prog8.code.core.DataType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class VariousCleanups(val program: Program, val errors: IErrorReporter, val options: CompilationOptions): AstWalker() {

View File

@ -11,7 +11,7 @@ import prog8.ast.walk.IAstVisitor
import prog8.code.core.DataType
import prog8.code.core.Position
import prog8.compilerinterface.BuiltinFunctions
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import prog8.compilerinterface.builtinFunctionReturnType
internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorReporter) : IAstVisitor {

View File

@ -12,7 +12,7 @@ import io.kotest.matchers.string.shouldContain
import prog8.ast.Program
import prog8.ast.internedStringsModuleName
import prog8.compiler.ModuleImporter
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
import prog8.parser.ParseError
import prog8.parser.SourceCode
import prog8tests.helpers.*

View File

@ -5,10 +5,10 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldStartWith
import prog8.ast.internedStringsModuleName
import prog8.code.core.ZeropageType
import prog8.codegen.target.C64Target
import prog8.compiler.determineCompilationOptions
import prog8.compiler.parseImports
import prog8.compilerinterface.ZeropageType
import prog8tests.helpers.ErrorReporterForTests
import prog8tests.helpers.compileText
import prog8tests.helpers.outputDir

View File

@ -9,7 +9,7 @@ import io.kotest.matchers.string.shouldContain
import prog8.code.core.toHex
import prog8.codegen.target.C64Target
import prog8.codegen.target.cbm.Mflpt5
import prog8.compilerinterface.InternalCompilerException
import prog8.code.core.InternalCompilerException
import prog8tests.helpers.ErrorReporterForTests
import prog8tests.helpers.compileText

View File

@ -13,15 +13,11 @@ import prog8.ast.ParentSentinel
import prog8.ast.Program
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.code.core.DataType
import prog8.code.core.Position
import prog8.code.core.*
import prog8.codegen.target.C64Target
import prog8.compiler.astprocessing.processAstBeforeAsmGeneration
import prog8.compiler.printProgram
import prog8.compilerinterface.CbmPrgLauncherType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.OutputType
import prog8.compilerinterface.ZeropageType
import prog8tests.helpers.*

View File

@ -4,9 +4,9 @@ import io.kotest.assertions.fail
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import prog8.code.*
import prog8.code.core.DataType
import prog8.code.core.Position
import prog8.compilerinterface.*
class TestSymbolTable: FunSpec({
test("empty symboltable") {

View File

@ -12,7 +12,7 @@ import io.kotest.matchers.collections.shouldNotBeIn
import io.kotest.matchers.comparables.shouldBeGreaterThan
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import prog8.code.core.DataType
import prog8.code.core.*
import prog8.codegen.target.C64Target
import prog8.codegen.target.Cx16Target
import prog8.codegen.target.c64.C64Zeropage

View File

@ -8,17 +8,12 @@ import prog8.ast.expressions.AddressOf
import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.NumericLiteral
import prog8.ast.statements.*
import prog8.code.core.DataType
import prog8.code.core.Position
import prog8.code.core.RegisterOrPair
import prog8.code.core.*
import prog8.codegen.cpu6502.AsmGen
import prog8.codegen.target.C64Target
import prog8.codegen.target.c64.C64Zeropage
import prog8.compiler.astprocessing.SymbolTableMaker
import prog8.compilerinterface.CbmPrgLauncherType
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.OutputType
import prog8.compilerinterface.ZeropageType
import prog8.parser.SourceCode
import prog8tests.helpers.DummyFunctions
import prog8tests.helpers.DummyMemsizer

View File

@ -1,9 +1,10 @@
package prog8tests.helpers
import prog8.code.core.Position
import prog8.compilerinterface.IErrorReporter
import prog8.code.core.IErrorReporter
internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors: Boolean=true, private val keepMessagesAfterReporting: Boolean=false): IErrorReporter {
internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors: Boolean=true, private val keepMessagesAfterReporting: Boolean=false):
IErrorReporter {
val errors = mutableListOf<String>()
val warnings = mutableListOf<String>()

View File

@ -1,6 +1,7 @@
package prog8tests.helpers
import prog8.ast.Program
import prog8.code.core.*
import prog8.codegen.cpu6502.AsmGen
import prog8.codegen.target.C64Target
import prog8.codegen.target.c64.C64Zeropage

View File

@ -22,6 +22,7 @@ compileTestKotlin {
}
dependencies {
implementation project(':codeCore')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation 'org.antlr:antlr4-runtime:4.9.3'
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.14"

View File

@ -11,8 +11,8 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="parser" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="library" name="antlr.antlr4" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="codeCore" />
</component>
</module>

View File

@ -24,6 +24,7 @@ compileTestKotlin {
}
dependencies {
implementation project(':codeCore')
implementation project(':compilerAst')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.14"

View File

@ -10,8 +10,8 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="codeCore" />
</component>
</module>

View File

@ -9,6 +9,7 @@ import prog8.ast.expressions.FunctionCallExpression
import prog8.ast.expressions.IdentifierReference
import prog8.ast.statements.*
import prog8.ast.walk.IAstVisitor
import prog8.code.core.IErrorReporter
class CallGraph(private val program: Program, private val allowMissingIdentifierTargetVarDecls: Boolean=false) : IAstVisitor {

View File

@ -1,26 +1,11 @@
package prog8.compilerinterface
import prog8.code.core.CbmPrgLauncherType
import prog8.code.core.OutputType
import prog8.code.core.ZeropageType
import java.nio.file.Path
import kotlin.io.path.Path
enum class OutputType {
RAW,
PRG,
XEX
}
enum class CbmPrgLauncherType {
BASIC,
NONE
}
enum class ZeropageType {
BASICSAFE,
FLOATSAFE,
KERNALSAFE,
FULL,
DONTUSE
}
class CompilationOptions(val output: OutputType,
val launcher: CbmPrgLauncherType,

View File

@ -1,13 +0,0 @@
package prog8.compilerinterface
interface IAssemblyGenerator {
fun compileToAssembly(): IAssemblyProgram?
}
interface IAssemblyProgram {
val name: String
fun assemble(options: CompilationOptions): Boolean
}
fun viceMonListName(baseFilename: String) = "$baseFilename.vice-mon-list"

View File

@ -46,7 +46,8 @@ abstract class Zeropage(protected val options: CompilationOptions) {
datatype: DataType,
numElements: Int?,
position: Position?,
errors: IErrorReporter): Result<Pair<UInt, Int>, ZeropageAllocationError> {
errors: IErrorReporter
): Result<Pair<UInt, Int>, ZeropageAllocationError> {
require(name.isEmpty() || name !in allocatedVariables) {"name can't be allocated twice"}

View File

@ -25,6 +25,7 @@ compileTestKotlin {
}
dependencies {
implementation project(':codeCore')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.4'

View File

@ -12,5 +12,6 @@
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />
<orderEntry type="library" name="github.hypfvieh.dbus.java" level="project" />
<orderEntry type="library" name="slf4j.simple" level="project" />
<orderEntry type="module" module-name="codeCore" />
</component>
</module>

View File

@ -3,10 +3,6 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- make an intermediate representation containing the SymbolTable and dumbed down version of the Ast.
no vardecls in it anymore (these are part of the symboltable) and baked types, so no inferType too.
no name lookup in the Ast, always do this in the symbol table.
...

View File

@ -25,6 +25,7 @@ compileTestKotlin {
}
dependencies {
implementation project(':codeCore')
implementation project(':compilerInterfaces')
implementation project(':compiler')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

View File

@ -9,11 +9,12 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compiler" />
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />
<orderEntry type="library" name="glassfish.javax.json" level="project" />
<orderEntry type="library" name="takes" level="project" />
<orderEntry type="library" name="slf4j.simple" level="project" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="compiler" />
</component>
</module>

View File

@ -1,7 +1,9 @@
include(
':parser',
':compilerInterfaces',
':codeCore',
':codeAst',
':compilerAst',
':compilerInterfaces',
':codeOptimizers',
':codeGenTargets',
':codeGenCpu6502',