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) return CastValue(true, null, this)
when(type) { when(type) {
DataType.UBYTE -> { DataType.UBYTE -> {
if(targettype==DataType.BYTE && number <= 127) if(targettype==DataType.BYTE)
return CastValue(true, null, NumericLiteral(targettype, number, position)) return CastValue(true, null, NumericLiteral(targettype, number.toInt().toByte().toDouble(), position))
if(targettype==DataType.WORD || targettype==DataType.UWORD) if(targettype==DataType.WORD || targettype==DataType.UWORD)
return CastValue(true, null, NumericLiteral(targettype, number, position)) return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.FLOAT) 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)) return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.UBYTE && number <= 255) if(targettype==DataType.UBYTE && number <= 255)
return CastValue(true, null, NumericLiteral(targettype, number, position)) return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.WORD && number <= 32767) if(targettype==DataType.WORD)
return CastValue(true, null, NumericLiteral(targettype, number, position)) return CastValue(true, null, NumericLiteral(targettype, number.toInt().toShort().toDouble(), position))
if(targettype==DataType.FLOAT) if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position)) return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL) if(targettype==DataType.BOOL)

View File

@ -2,7 +2,6 @@
TODO TODO
==== ====
- make internalCast() not complain anymore about signed <-> unsigned conversions
- fix bitshift.p8 - 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 .... - [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 { main {
sub start() { sub start() {
str poem_data = iso:"Once upon a midnight dreary, while I pondered, weak and weary,"+ uword @shared x = 65535
iso:"Over many a quaint and curious volume of forgotten lore-"+ word @shared y = x as word
iso:"While I nodded, nearly napping, suddenly there came a tapping,"+ txt.print_w(y)
iso:"As of some one gently rapping, rapping at my chamber door. ..." txt.nl()
uword size = len(poem_data) txt.print_w(x as word)
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())
txt.nl() txt.nl()
cbm.SETTIM(0,0,0) word @shared x2 = -1
repeat 20 { uword @shared y2 = x2 as uword
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_uw(y2)
} txt.nl()
txt.print_uwhex(cx16.r9, true) txt.print_uw(x2 as uword)
txt.spc()
txt.print_uw(cbm.RDTIM16())
txt.nl() txt.nl()
cbm.SETTIM(0,0,0) txt.print_uw(shiftluw1())
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()
} }
; sub shiftluw1() -> uword {
; uword q = $a49f
; return (q << 1) & 65535 as uword
; }
} }