allow casting of byte<->ubyte and word<->uword

This commit is contained in:
Irmen de Jong 2023-12-29 16:23:24 +01:00
parent 01bd648cb2
commit 932bbd0381
3 changed files with 21 additions and 34 deletions

View File

@ -577,8 +577,8 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, this)
when(type) {
DataType.UBYTE -> {
if(targettype==DataType.BYTE && number <= 127)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BYTE)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toByte().toDouble(), position))
if(targettype==DataType.WORD || targettype==DataType.UWORD)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.FLOAT)
@ -615,8 +615,8 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.UBYTE && number <= 255)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.WORD && number <= 32767)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.WORD)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toShort().toDouble(), position))
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL)

View File

@ -2,7 +2,6 @@
TODO
====
- make internalCast() not complain anymore about signed <-> unsigned conversions
- fix bitshift.p8
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....

View File

@ -4,38 +4,26 @@
main {
sub start() {
str poem_data = iso:"Once upon a midnight dreary, while I pondered, weak and weary,"+
iso:"Over many a quaint and curious volume of forgotten lore-"+
iso:"While I nodded, nearly napping, suddenly there came a tapping,"+
iso:"As of some one gently rapping, rapping at my chamber door. ..."
uword size = len(poem_data)
cbm.SETTIM(0,0,0)
repeat 20 {
cx16.r9 = math.crc16(poem_data, size)
}
txt.print_uwhex(cx16.r9, true)
txt.spc()
txt.print_uw(cbm.RDTIM16())
uword @shared x = 65535
word @shared y = x as word
txt.print_w(y)
txt.nl()
txt.print_w(x as word)
txt.nl()
cbm.SETTIM(0,0,0)
repeat 20 {
cx16.r9 = cx16.memory_crc(poem_data, size) ; faster but I can't figure out the flavour of crc algorithm it uses, it's not any on https://crccalc.com/
}
txt.print_uwhex(cx16.r9, true)
txt.spc()
txt.print_uw(cbm.RDTIM16())
word @shared x2 = -1
uword @shared y2 = x2 as uword
txt.print_uw(y2)
txt.nl()
txt.print_uw(x2 as uword)
txt.nl()
cbm.SETTIM(0,0,0)
repeat 20 {
math.crc32(poem_data, size)
}
txt.print_uwhex(cx16.r1, true)
txt.print_uwhex(cx16.r0, false)
txt.spc()
txt.print_uw(cbm.RDTIM16())
txt.nl()
txt.print_uw(shiftluw1())
}
; sub shiftluw1() -> uword {
; uword q = $a49f
; return (q << 1) & 65535 as uword
; }
}