diff --git a/compiler/build.gradle b/compiler/build.gradle index 80d9a8589..65c0698d8 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -76,17 +76,6 @@ artifacts { archives shadowJar } -task p8vmScript(type: CreateStartScripts) { - mainClassName = "prog8.vm.stackvm.MainKt" - applicationName = "p8vm" - outputDir = new File(project.buildDir, 'scripts') - classpath = jar.outputs.files + project.configurations.runtime -} - -applicationDistribution.into("bin") { - from(p8vmScript) - fileMode = 0755 -} // To create a fat-jar use the 'create_compiler_jar' script for now // @todo investigate https://imperceptiblethoughts.com/shadow/introduction/ diff --git a/compiler/src/prog8/ast/processing/AstIdentifiersChecker.kt b/compiler/src/prog8/ast/processing/AstIdentifiersChecker.kt index 273a4470d..ba9ce994c 100644 --- a/compiler/src/prog8/ast/processing/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/ast/processing/AstIdentifiersChecker.kt @@ -62,8 +62,9 @@ internal class AstIdentifiersChecker(private val namespace: INameScope) : IAstMo if(decl.structHasBeenFlattened) return decl // don't do this multiple times - val decls: MutableList = decl.struct!!.statements.map { - val member = it as VarDecl + val decls: MutableList = decl.struct!!.statements.withIndex().map { + val member = it.value as VarDecl + val initvalue = if(decl.value!=null) (decl.value as LiteralValue).arrayvalue!![it.index] else null VarDecl( VarDeclType.VAR, member.datatype, @@ -71,7 +72,7 @@ internal class AstIdentifiersChecker(private val namespace: INameScope) : IAstMo member.arraysize, mangledStructMemberName(decl.name, member.name), null, - member.value, + initvalue, member.isArray, true, member.position diff --git a/compiler/src/prog8/ast/processing/VarInitValueAndAddressOfCreator.kt b/compiler/src/prog8/ast/processing/VarInitValueAndAddressOfCreator.kt index 6d495172e..37ee4f42d 100644 --- a/compiler/src/prog8/ast/processing/VarInitValueAndAddressOfCreator.kt +++ b/compiler/src/prog8/ast/processing/VarInitValueAndAddressOfCreator.kt @@ -62,22 +62,23 @@ internal class VarInitValueAndAddressOfCreator(private val namespace: INameScope ) } - if(decl.datatype==DataType.STRUCT) { - // a struct initialization value - // flatten it to assignment statements - val sourceArray = (decl.value as LiteralValue).arrayvalue!! - val memberAssignments = decl.struct!!.statements.zip(sourceArray).map { member -> - val memberDecl = member.first as VarDecl - val mangled = mangledStructMemberName(decl.name, memberDecl.name) - val idref = IdentifierReference(listOf(mangled), decl.position) - val target = AssignTarget(null, idref, null, null, decl.position) - val assign = VariableInitializationAssignment(target, null, member.second, member.second.position) - assign - } - val scope = AnonymousScope(memberAssignments.toMutableList(), decl.position) - scope.linkParents(decl.parent) - return scope - } +// if(decl.datatype==DataType.STRUCT) { +// println("STRUCT INIT DECL $decl") +// // a struct initialization value perhaps +// // flatten it to assignment statements +// val sourceArray = (decl.value as LiteralValue).arrayvalue!! +// val memberAssignments = decl.struct!!.statements.zip(sourceArray).map { member -> +// val memberDecl = member.first as VarDecl +// val mangled = mangledStructMemberName(decl.name, memberDecl.name) +// val idref = IdentifierReference(listOf(mangled), decl.position) +// val target = AssignTarget(null, idref, null, null, decl.position) +// val assign = VariableInitializationAssignment(target, null, member.second, member.second.position) +// assign +// } +// val scope = AnonymousScope(memberAssignments.toMutableList(), decl.position) +// scope.linkParents(decl.parent) +// return scope +// } return decl } diff --git a/compiler/src/prog8/compiler/Main.kt b/compiler/src/prog8/compiler/Main.kt index 7ce44951c..bb7cd3781 100644 --- a/compiler/src/prog8/compiler/Main.kt +++ b/compiler/src/prog8/compiler/Main.kt @@ -63,6 +63,7 @@ fun compileProgram(filepath: Path, } //println(" time2: $time2") val time3 = measureTimeMillis { + programAst.removeNopsFlattenAnonScopes() programAst.reorderStatements() // reorder statements and add type casts, to please the compiler later } //println(" time3: $time3") @@ -88,7 +89,7 @@ fun compileProgram(filepath: Path, programAst.checkValid(compilerOptions) // check if final tree is valid programAst.checkRecursion() // check if there are recursive subroutine calls - printAst(programAst) + // printAst(programAst) // namespace.debugPrint() if(generateVmCode) { diff --git a/docs/source/building.rst b/docs/source/building.rst index 1b2c23513..d3cacf11b 100644 --- a/docs/source/building.rst +++ b/docs/source/building.rst @@ -54,14 +54,10 @@ The compiler will link everything together into one output program at the end. If you start the compiler without arguments, it will print a short usage text. For normal use the compiler is invoked with the command: - ``$ java -jar prog8compiler.jar sourcefile.p8`` if you're using the packaged release version, or + ``$ java -jar prog8compiler.jar sourcefile.p8`` - ``$ ./p8compile.sh sourcefile.p8`` if you're running an unpackaged development version. - -If you tell it to save the intermediate code for the prog8 virtual machine, you can -actually run this code with the command: - - ``$ ./p8vm.sh sourcefile.vm.txt`` + Other options are also available, see the introduction page about how + to build and run the compiler. By default, assembly code is generated and written to ``sourcefile.asm``. diff --git a/examples/test.p8 b/examples/test.p8 index 073551f98..4afeebb27 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,8 +3,11 @@ ~ main { + Color blocklevelcolor + sub start() { - uword derp + + uword derp =44 ubyte[] v = [22,33,44] Color foreground = [1,2,3] @@ -16,15 +19,15 @@ c64.CHROUT('\n') - Color background = [255,255,255] ; @todo make zeros if no value is given - Color cursor + Color background + Color cursor = [255,255,255] foreground.red=99 background.blue=foreground.red cursor = [1,2,3] ; assign all members at once cursor = v - ;cursor=foreground ; @todo memberwise assignment + cursor = foreground ; @todo memberwise assignment c64scr.print_ub(foreground.red) c64.CHROUT(':') @@ -45,9 +48,29 @@ c64scr.print_ub(cursor.blue) c64.CHROUT('\n') + foo() + foo() + foo() + foo() + foo() + foo() + foo() + + return } + sub foo() { + Color localcolor + localcolor.red++ + c64scr.print_ub(localcolor.red) + c64.CHROUT(':') + c64scr.print_ub(localcolor.green) + c64.CHROUT(':') + c64scr.print_ub(localcolor.blue) + c64.CHROUT('\n') + } + struct Color { ubyte red ubyte green