diff --git a/compiler/build.gradle b/compiler/build.gradle index 084fd929a..a8d97f27f 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -62,8 +62,10 @@ task fatJar(type: Jar) { attributes 'Main-Class': 'prog8.CompilerMainKt' } archiveBaseName = 'prog8compiler' - destinationDir = rootProject.projectDir - from { project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } + destinationDirectory = rootProject.projectDir + from { + project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } + } with jar } // build.finalizedBy(fatJar) diff --git a/compiler/src/prog8/ast/AST.kt b/compiler/src/prog8/ast/AST.kt index cccd822cd..55ff37d62 100644 --- a/compiler/src/prog8/ast/AST.kt +++ b/compiler/src/prog8/ast/AST.kt @@ -926,8 +926,8 @@ class BinaryExpression(var left: IExpression, var operator: String, var right: I else -> throw FatalAstException("arithmetic operation on incompatible datatypes: $leftDt and $rightDt") } DataType.UWORD -> when(rightDt) { - in ByteDatatypes -> DataType.UWORD - in WordDatatypes -> DataType.WORD + DataType.UBYTE, DataType.UWORD -> DataType.UWORD + DataType.BYTE, DataType.WORD -> DataType.WORD DataType.FLOAT -> DataType.FLOAT else -> throw FatalAstException("arithmetic operation on incompatible datatypes: $leftDt and $rightDt") } diff --git a/compiler/src/prog8/compiler/target/c64/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/AsmGen.kt index 308f6c0e3..2298136c3 100644 --- a/compiler/src/prog8/compiler/target/c64/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/AsmGen.kt @@ -3317,44 +3317,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram, null }, - // 16 bit addition avoiding excessive stack usage - // @todo optimize 8 and 16 bit adds and subs even more with longer asmpatterns (avoid stack use altogether on most common operations) - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.ADD_UW), - listOf(Opcode.PUSH_VAR_WORD, Opcode.ADD_W)) { segment -> - """ - clc - lda ${segment[0].callLabel} - adc ${(ESTACK_LO+1).toHex()},x - sta ${(ESTACK_LO+1).toHex()},x - lda ${segment[0].callLabel}+1 - adc ${(ESTACK_HI+1).toHex()},x - sta ${(ESTACK_HI+1).toHex()},x - """ - }, - AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.ADD_UW), - listOf(Opcode.PUSH_MEM_W, Opcode.ADD_W)) { segment -> - """ - clc - lda ${hexVal(segment[0])} - adc ${(ESTACK_LO + 1).toHex()},x - sta ${(ESTACK_LO + 1).toHex()},x - lda ${hexValPlusOne(segment[0])} - adc ${(ESTACK_HI + 1).toHex()},x - sta ${(ESTACK_HI + 1).toHex()},x - """ - }, - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.ADD_UW), - listOf(Opcode.PUSH_WORD, Opcode.ADD_W)) { segment -> - """ - clc - lda #<${hexVal(segment[0])} - adc ${(ESTACK_LO+1).toHex()},x - sta ${(ESTACK_LO+1).toHex()},x - lda #>${hexVal(segment[0])} - adc ${(ESTACK_HI+1).toHex()},x - sta ${(ESTACK_HI+1).toHex()},x - """ - }, + // @todo optimize 8 and 16 bit adds and subs (avoid stack use altogether on most common operations) AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment -> // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) diff --git a/compiler/src/prog8/functions/BuiltinFunctions.kt b/compiler/src/prog8/functions/BuiltinFunctions.kt index 97024e400..0e54fa095 100644 --- a/compiler/src/prog8/functions/BuiltinFunctions.kt +++ b/compiler/src/prog8/functions/BuiltinFunctions.kt @@ -74,7 +74,7 @@ val BuiltinFunctions = mapOf( "memcopy" to FunctionSignature(false, listOf( BuiltinFunctionParam("from", IterableDatatypes + setOf(DataType.UWORD)), BuiltinFunctionParam("to", IterableDatatypes + setOf(DataType.UWORD)), - BuiltinFunctionParam("numbytes", IntegerDatatypes)), null), + BuiltinFunctionParam("numbytes", setOf(DataType.UBYTE))), null), "memset" to FunctionSignature(false, listOf( BuiltinFunctionParam("address", IterableDatatypes + setOf(DataType.UWORD)), BuiltinFunctionParam("numbytes", setOf(DataType.UWORD)), diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index da3c00d47..b9b906cad 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -204,10 +204,10 @@ waitkey: ; block colors I, J, L, O, S, T, Z: cyan, blue, orange, yellow, green, purple, red ubyte[7] blockColors = [3, 6, 8, 7, 5, 4, 2] - ubyte[4] blockI = [4, 5, 6, 7] ; note: special rotation + ubyte[4] blockI = [4, 5, 6, 7] ; note: special rotation (only 2 states) ubyte[4] blockJ = [0, 4, 5, 6] ubyte[4] blockL = [2, 4, 5, 6] - ubyte[4] blockO = [1, 2, 5, 6] ; note: no rotation + ubyte[4] blockO = [1, 2, 5, 6] ; note: no rotation (square) ubyte[4] blockS = [1, 2, 4, 5] ubyte[4] blockT = [1, 4, 5, 6] ubyte[4] blockZ = [0, 1, 5, 6] @@ -454,7 +454,7 @@ waitkey: } sub canMoveDown(ubyte xpos, ubyte ypos) -> ubyte { - return ypos ubyte { diff --git a/examples/test.p8 b/examples/test.p8 index 118b74d5f..4115d6499 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,40 +3,12 @@ ~ main { - ; @todo test memset/memcopy (there's a bug in memcopy?) - ; @todo see problem in looplabelproblem.p8 ; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars) ; @todo gradle fatJar should include the antlr runtime jar - ; uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword" - ; uword ypos=4; ypos += 5000 ; @todo fix "cannot assign word to uword" - - sub start() { - uword ypos=4 - - byte bb=44 - byte bb2 - word ww=4444 - word ww2 - - bb2 = bb*55 - ww2 = ww*55 - - uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword" - ;ypos += 5000 ; @todo fix "cannot assign word to uword" - -; -; memset($0400+(ypos+0)*40, 40, 1) -; memset($0400+(ypos+1)*40, 40, 2) -; memset($0400+(ypos+2)*40, 40, 3) -; memset($0400+(ypos+3)*40, 40, 4) - - ;memsetw($0400+(ypos+1)*40, 20, $4455) - ;memsetw($0400+(ypos+3)*40, 20, $4455) - } }