diff --git a/compiler/test/TestNumbers.kt b/compiler/test/TestNumbers.kt index a2f1e5980..fa445d919 100644 --- a/compiler/test/TestNumbers.kt +++ b/compiler/test/TestNumbers.kt @@ -123,7 +123,7 @@ class TestNumbers: FunSpec({ uword xx = 10 if xx+99 == 1.23456 xx++ - if xx+99 == 1234567 + if xx+99 == 1234567.8 xx++ } } @@ -143,7 +143,7 @@ class TestNumbers: FunSpec({ uword xx = 10 if xx+99 == 1.23456 xx++ - if xx+99 == 1234567 + if xx+99 == 1234567.8 xx++ } } diff --git a/compiler/test/TestTypecasts.kt b/compiler/test/TestTypecasts.kt index b15a9bd8a..cce7ad43d 100644 --- a/compiler/test/TestTypecasts.kt +++ b/compiler/test/TestTypecasts.kt @@ -1053,6 +1053,7 @@ main { thing(320*240/8/8) thing(320*HEIGHT/8/8) thing(320*HEIGHT) ; overflow + large = 12345678 ; overflow } sub thing(uword value) { @@ -1061,9 +1062,12 @@ main { }""" val errors=ErrorReporterForTests() compileText(C64Target(), false, src, writeAssembly = false, errors=errors) shouldBe null - errors.errors.size shouldBe 2 + errors.errors.size shouldBe 5 errors.errors[0] shouldContain "can't cast" errors.errors[1] shouldContain "overflow" + errors.errors[2] shouldContain "LONG doesn't match" + errors.errors[3] shouldContain "out of range" + errors.errors[4] shouldContain "overflow" } }) diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 654b14538..f8fe3d004 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -369,6 +369,7 @@ private fun IntegerliteralContext.toAst(): NumericLiteralNode { in -128..127 -> DataType.BYTE in 0..65535 -> DataType.UWORD in -32768..32767 -> DataType.WORD + in -2147483647..2147483647 -> DataType.LONG else -> DataType.FLOAT } } @@ -420,6 +421,7 @@ private fun ExpressionContext.toAst() : Expression { DataType.BYTE -> NumericLiteral(DataType.BYTE, intLit.number, litval.toPosition()) DataType.UWORD -> NumericLiteral(DataType.UWORD, intLit.number, litval.toPosition()) DataType.WORD -> NumericLiteral(DataType.WORD, intLit.number, litval.toPosition()) + DataType.LONG -> NumericLiteral(DataType.LONG, intLit.number, litval.toPosition()) DataType.FLOAT -> NumericLiteral(DataType.FLOAT, intLit.number, litval.toPosition()) else -> throw FatalAstException("invalid datatype for numeric literal") } diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index 36d386de2..145cc487d 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -472,6 +472,7 @@ class NumericLiteral(val type: DataType, // only numerical types allowed in -128..127 -> NumericLiteral(DataType.BYTE, dvalue, position) in 0..65535 -> NumericLiteral(DataType.UWORD, dvalue, position) in -32768..32767 -> NumericLiteral(DataType.WORD, dvalue, position) + in -2147483647..2147483647 -> NumericLiteral(DataType.LONG, dvalue, position) else -> NumericLiteral(DataType.FLOAT, dvalue, position) } } diff --git a/examples/test.p8 b/examples/test.p8 index 9d5c5cd44..b3f6923ee 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,14 +1,10 @@ +%import textio +%zeropage basicsafe + main { sub start() { const ubyte HEIGHT=240 - uword large = 320*240/8/8 - thing(large) - thing(320*240/8/8) - thing(320*HEIGHT/8/8) - thing(320*HEIGHT) ; overflow - } - - sub thing(uword value) { - value++ + uword zz = 823423 + txt.print_uw(320*HEIGHT/8/8) } }