diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 29822a972..d16fae2b8 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -519,13 +519,18 @@ internal class AstChecker(private val program: Program, err("const modifier can only be used on numeric types (byte, word, float)") } + // @zp can only occur on integers + if(decl.datatype !in IntegerDatatypes) { + if(decl.zeropage==ZeropageWish.PREFER_ZEROPAGE) + errors.warn("this datatype can't be placed in zeropage", decl.position) + if(decl.zeropage==ZeropageWish.REQUIRE_ZEROPAGE) + errors.err("this datatype can't be placed in zeropage", decl.position) + } + // FLOATS enabled? if(!compilerOptions.floats && decl.datatype.oneOf(DataType.FLOAT, DataType.ARRAY_F) && decl.type!= VarDeclType.MEMORY) err("floating point used, but that is not enabled via options") - if(decl.datatype == DataType.FLOAT && (decl.zeropage==ZeropageWish.REQUIRE_ZEROPAGE || decl.zeropage==ZeropageWish.PREFER_ZEROPAGE)) - errors.warn("floating point values won't be placed in Zeropage due to size constraints", decl.position) - // ARRAY without size specifier MUST have an iterable initializer value if(decl.isArray && decl.arraysize==null) { if(decl.type== VarDeclType.MEMORY) diff --git a/compiler/test/codegeneration/AsmGenSymbolsTests.kt b/compiler/test/codegeneration/TestAsmGenSymbols.kt similarity index 99% rename from compiler/test/codegeneration/AsmGenSymbolsTests.kt rename to compiler/test/codegeneration/TestAsmGenSymbols.kt index e817a4214..570d08dad 100644 --- a/compiler/test/codegeneration/AsmGenSymbolsTests.kt +++ b/compiler/test/codegeneration/TestAsmGenSymbols.kt @@ -21,7 +21,7 @@ import prog8tests.helpers.DummyStringEncoder import prog8tests.helpers.ErrorReporterForTests import java.nio.file.Path -class AsmGenSymbolsTests: StringSpec({ +class TestAsmGenSymbols: StringSpec({ fun createTestProgram(): Program { /* main { diff --git a/compiler/test/codegeneration/TestVariables.kt b/compiler/test/codegeneration/TestVariables.kt new file mode 100644 index 000000000..80c319e25 --- /dev/null +++ b/compiler/test/codegeneration/TestVariables.kt @@ -0,0 +1,32 @@ +package prog8tests.codegeneration + +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain +import prog8.compiler.target.C64Target +import prog8tests.helpers.ErrorReporterForTests +import prog8tests.helpers.assertSuccess +import prog8tests.helpers.compileText + + +class TestVariables: FunSpec({ + + test("shared variables without refs not removed for inlined asm") { + val text = """ + main { + sub start() { + ubyte[] @shared array = [1,2,3,4] + str @shared name = "test" + ubyte @shared bytevar = 0 + + %asm {{ + lda array + lda name + lda bytevar + }} + } + } + """ + compileText(C64Target, true, text, writeAssembly = true).assertSuccess() + } +}) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 72167e591..ed35a51c7 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,10 @@ TODO For next compiler release (7.6) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +why does the following use a intermediate return value and not just A? + sub pushing_start() -> ubyte { + return joy_info & 16 + } ... diff --git a/examples/test.p8 b/examples/test.p8 index b550d36d1..803be376f 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,49 +1,16 @@ -%import textio -%import floats -%zeropage basicsafe +%option enable_floats main { sub start() { - ubyte xx = 0 + ubyte[] @shared @zp array = [1,2,3,4] + str @shared @zp name = "test" + ubyte @shared @zp bytevar = 0 + float @shared @zp fl - singleparamb(123) - singleparamb(123) - singleparamw(-9999) - singleparamw(-9999) - doubleparamb(xx+111,-99) - doubleparamb(xx+111,-99) - doubleparamw(xx+8888,-9999) - doubleparamw(xx+8888,-9999) - singleparamf(1.23456) - singleparamf(1.23456) - } - - sub singleparamb(ubyte bb) { - txt.print_ub(bb) - txt.nl() - } - - sub doubleparamb(ubyte bb, byte bs) { - txt.print_ub(bb) - txt.spc() - txt.print_b(bs) - txt.nl() - } - - sub singleparamw(word ww) { - txt.print_w(ww) - txt.nl() - } - - sub doubleparamw(uword uw, word ww) { - txt.print_uw(uw) - txt.spc() - txt.print_w(ww) - txt.nl() - } - - sub singleparamf(float ff) { - floats.print_f(ff) - txt.nl() + %asm {{ + lda array + lda name + lda bytevar + }} } } diff --git a/parser/antlr/Prog8ANTLR.g4 b/parser/antlr/Prog8ANTLR.g4 index af773671e..dd15d4261 100644 --- a/parser/antlr/Prog8ANTLR.g4 +++ b/parser/antlr/Prog8ANTLR.g4 @@ -128,7 +128,7 @@ directive : directivearg : stringliteral | identifier | integerliteral ; -vardecl: datatype SHARED? ZEROPAGE? (arrayindex | ARRAYSIG) ? varname=identifier ; +vardecl: datatype (arrayindex | ARRAYSIG)? SHARED? ZEROPAGE? varname=identifier ; varinitializer : vardecl '=' expression ;