some tweaks to errors about long integer literals

This commit is contained in:
Irmen de Jong 2023-12-03 02:45:26 +01:00
parent c609e982fe
commit b09e0a05bf
5 changed files with 15 additions and 12 deletions

View File

@ -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++
}
}

View File

@ -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"
}
})

View File

@ -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")
}

View File

@ -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)
}
}

View File

@ -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)
}
}