mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 07:31:48 +00:00
some tweaks to errors about long integer literals
This commit is contained in:
parent
c609e982fe
commit
b09e0a05bf
@ -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++
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user