fix asmgen for uword shift right 8 or more bits

This commit is contained in:
Irmen de Jong 2023-12-29 05:04:38 +01:00
parent d28c994ecd
commit ccc11e49d2
6 changed files with 181 additions and 147 deletions

View File

@ -733,7 +733,11 @@ internal class AssignmentAsmGen(private val program: PtProgram,
}
asmgen.out(" tay | lda #0")
} else {
asmgen.out(" ldx #$shifts | jsr math.lsr_word_AY")
asmgen.out(" ldx #$shifts")
if(signed)
asmgen.out(" jsr math.lsr_word_AY")
else
asmgen.out(" jsr math.lsr_uword_AY")
}
assignRegisterpairWord(target, RegisterOrPair.AY)
return true

View File

@ -57,7 +57,15 @@ class ConstExprEvaluator {
if(left.type !in IntegerDatatypes || amount.type !in IntegerDatatypes)
throw ExpressionError("cannot compute $left << $amount", left.position)
val result = left.number.toInt().shl(amount.number.toInt())
return NumericLiteral(left.type, result.toDouble(), left.position)
// when(left.type) {
// DataType.BOOL -> result = result and 1
// DataType.UBYTE -> result = result and 255
// DataType.BYTE -> result = result.toByte().toInt()
// DataType.UWORD -> result = result and 65535
// DataType.WORD -> result = result.toShort().toInt()
// else -> { /* keep as it is */ }
// }
return NumericLiteral.optimalNumeric(result.toDouble(), left.position)
}
private fun bitwiseXor(left: NumericLiteral, right: NumericLiteral): NumericLiteral {
@ -67,7 +75,11 @@ class ConstExprEvaluator {
}
} else if(left.type== DataType.UWORD) {
if(right.type in IntegerDatatypes) {
return NumericLiteral(DataType.UWORD, (left.number.toInt() xor right.number.toInt()).toDouble(), left.position)
return NumericLiteral(DataType.UWORD, (left.number.toInt() xor right.number.toInt() and 65535).toDouble(), left.position)
}
} else if(left.type== DataType.LONG) {
if(right.type in IntegerDatatypes) {
return NumericLiteral.optimalNumeric((left.number.toInt() xor right.number.toInt()).toDouble(), left.position)
}
}
throw ExpressionError("cannot calculate $left ^ $right", left.position)
@ -80,7 +92,11 @@ class ConstExprEvaluator {
}
} else if(left.type== DataType.UWORD) {
if(right.type in IntegerDatatypes) {
return NumericLiteral(DataType.UWORD, (left.number.toInt() or right.number.toInt()).toDouble(), left.position)
return NumericLiteral(DataType.UWORD, (left.number.toInt() or right.number.toInt() and 65535).toDouble(), left.position)
}
} else if(left.type== DataType.LONG) {
if(right.type in IntegerDatatypes) {
return NumericLiteral.optimalNumeric((left.number.toInt() or right.number.toInt()).toDouble(), left.position)
}
}
throw ExpressionError("cannot calculate $left | $right", left.position)
@ -93,7 +109,11 @@ class ConstExprEvaluator {
}
} else if(left.type== DataType.UWORD) {
if(right.type in IntegerDatatypes) {
return NumericLiteral(DataType.UWORD, (left.number.toInt() and right.number.toInt()).toDouble(), left.position)
return NumericLiteral(DataType.UWORD, (left.number.toInt() and right.number.toInt() and 65535).toDouble(), left.position)
}
} else if(left.type== DataType.LONG) {
if(right.type in IntegerDatatypes) {
return NumericLiteral.optimalNumeric((left.number.toInt() and right.number.toInt()).toDouble(), left.position)
}
}
throw ExpressionError("cannot calculate $left & $right", left.position)

View File

@ -16,13 +16,13 @@ internal val constEvaluatorsForBuiltinFuncs: Map<String, ConstExpressionCaller>
"len" to ::builtinLen,
"sizeof" to ::builtinSizeof,
"sgn" to ::builtinSgn,
"sqrt__ubyte" to { a, p, prg -> oneIntArgOutputInt(a, p, prg) { sqrt(it.toDouble()) } },
"sqrt__uword" to { a, p, prg -> oneIntArgOutputInt(a, p, prg) { sqrt(it.toDouble()) } },
"sqrt__ubyte" to { a, p, prg -> oneIntArgOutputInt(a, p, prg, false) { sqrt(it.toDouble()) } },
"sqrt__uword" to { a, p, prg -> oneIntArgOutputInt(a, p, prg, false) { sqrt(it.toDouble()) } },
"sqrt__float" to { a, p, prg -> oneFloatArgOutputFloat(a, p, prg) { sqrt(it) } },
"any" to { a, p, prg -> collectionArg(a, p, prg, ::builtinAny) },
"all" to { a, p, prg -> collectionArg(a, p, prg, ::builtinAll) },
"lsb" to { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> (x and 255).toDouble() } },
"msb" to { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> (x ushr 8 and 255).toDouble()} },
"lsb" to { a, p, prg -> oneIntArgOutputInt(a, p, prg, true) { x: Int -> (x and 255).toDouble() } },
"msb" to { a, p, prg -> oneIntArgOutputInt(a, p, prg, true) { x: Int -> (x ushr 8 and 255).toDouble()} },
"mkword" to ::builtinMkword,
"clamp__ubyte" to ::builtinClampUByte,
"clamp__byte" to ::builtinClampByte,
@ -59,11 +59,12 @@ internal class NotConstArgumentException: AstException("not a const argument to
internal class CannotEvaluateException(func:String, msg: String): FatalAstException("cannot evaluate built-in function $func: $msg")
private fun oneIntArgOutputInt(args: List<Expression>, position: Position, program: Program, function: (arg: Int)->Double): NumericLiteral {
private fun oneIntArgOutputInt(args: List<Expression>, position: Position, program: Program, signed: Boolean, function: (arg: Int)->Double): NumericLiteral {
if(args.size!=1)
throw SyntaxError("built-in function requires one integer argument", position)
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
if(constval.type != DataType.UBYTE && constval.type!= DataType.UWORD)
val allowedDt = if(signed) IntegerDatatypesNoBool else arrayOf(DataType.UBYTE, DataType.UWORD)
if(constval.type !in allowedDt)
throw SyntaxError("built-in function requires one integer argument", position)
val integer = constval.number.toInt()

View File

@ -4,76 +4,77 @@
main {
str inputbuffer = "?" * 20
sub start() {
ubyte a
txt.print("ubyte shift left\n")
a = shiftlb0()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb1()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb2()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb3()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb4()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb5()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb6()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb7()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb8()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftlb9()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
txt.print("ubyte shift right\n")
a = shiftrb0()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb1()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb2()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb3()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb4()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb5()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb6()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb7()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb8()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
a = shiftrb9()
txt.print_ubbin(a, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
@ -82,70 +83,70 @@ main {
byte signedb
signedb = shiftlsb0()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb1()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb2()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb3()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb4()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb5()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb6()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb7()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb8()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftlsb9()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
txt.print("signed byte shift right\n")
signedb = shiftrsb0()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb1()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb2()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb3()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb4()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb5()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb6()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb7()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb8()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
signedb = shiftrsb9()
txt.print_ubbin(signedb as ubyte, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
@ -154,233 +155,233 @@ main {
uword uw
uw = shiftluw0()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw1()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw2()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw3()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw4()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw5()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw6()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw7()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw8()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw9()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw10()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw11()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw12()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw13()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw14()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw15()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw16()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftluw17()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
txt.print("uword shift right\n")
uw = shiftruw0()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw1()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw2()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw3()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw4()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw5()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw6()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw7()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw8()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw9()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw10()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw11()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw12()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw13()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw14()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw15()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw16()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
uw = shiftruw17()
txt.print_uwbin(uw, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
txt.print("signed word shift left\n")
word sw
sw = shiftlsw0()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw1()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw2()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw3()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw4()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw5()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw6()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw7()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw8()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw9()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw10()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw11()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw12()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw13()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw14()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw15()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw16()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftlsw17()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
txt.print("enter to continue:\n")
void cbm.CHRIN()
void txt.input_chars(inputbuffer)
txt.print("signed word shift right\n")
sw = shiftrsw0()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw1()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw2()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw3()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw4()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw5()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw6()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw7()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw8()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw9()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw10()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw11()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw12()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw13()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw14()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw15()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw16()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
sw = shiftrsw17()
txt.print_uwbin(sw as uword, true)
cbm.CHROUT('\n')
txt.chrout('\n')
}

View File

@ -577,11 +577,11 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, this)
when(type) {
DataType.UBYTE -> {
if(targettype== DataType.BYTE && number <= 127)
if(targettype==DataType.BYTE && number <= 127)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype== DataType.WORD || targettype== DataType.UWORD)
if(targettype==DataType.WORD || targettype==DataType.UWORD)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype== DataType.FLOAT)
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.LONG)
return CastValue(true, null, NumericLiteral(targettype, number, position))
@ -589,21 +589,21 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, fromBoolean(number!=0.0, position))
}
DataType.BYTE -> {
if(targettype== DataType.UBYTE) {
if(targettype==DataType.UBYTE) {
if(number in -128.0..0.0)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toUByte().toDouble(), position))
else if(number in 0.0..255.0)
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
if(targettype== DataType.UWORD) {
if(targettype==DataType.UWORD) {
if(number in -32768.0..0.0)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toUShort().toDouble(), position))
else if(number in 0.0..65535.0)
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
if(targettype== DataType.WORD)
if(targettype==DataType.WORD)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype== DataType.FLOAT)
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL)
return CastValue(true, null, fromBoolean(number!=0.0, position))
@ -611,13 +611,13 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
DataType.UWORD -> {
if(targettype== DataType.BYTE && number <= 127)
if(targettype==DataType.BYTE && number <= 127)
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))
if(targettype== DataType.WORD && number <= 32767)
if(targettype==DataType.WORD && number <= 32767)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype== DataType.FLOAT)
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL)
return CastValue(true, null, fromBoolean(number!=0.0, position))
@ -625,21 +625,21 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
DataType.WORD -> {
if(targettype== DataType.BYTE && number >= -128 && number <=127)
if(targettype==DataType.BYTE && number >= -128 && number <=127)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype== DataType.UBYTE) {
if(targettype==DataType.UBYTE) {
if(number in -128.0..0.0)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toUByte().toDouble(), position))
else if(number in 0.0..255.0)
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
if(targettype== DataType.UWORD) {
if(targettype==DataType.UWORD) {
if(number in -32768.0 .. 0.0)
return CastValue(true, null, NumericLiteral(targettype, number.toInt().toUShort().toDouble(), position))
else if(number in 0.0..65535.0)
return CastValue(true, null, NumericLiteral(targettype, number, position))
}
if(targettype== DataType.FLOAT)
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL)
return CastValue(true, null, fromBoolean(number!=0.0, position))
@ -679,7 +679,7 @@ class NumericLiteral(val type: DataType, // only numerical types allowed
return CastValue(true, null, NumericLiteral(targettype, number, position))
if(targettype==DataType.BOOL)
return CastValue(true, null, fromBoolean(number!=0.0, position))
if(targettype== DataType.FLOAT)
if(targettype==DataType.FLOAT)
return CastValue(true, null, NumericLiteral(targettype, number, position))
} catch (x: ExpressionError) {
return CastValue(false, x.message, null)

View File

@ -2,7 +2,15 @@
TODO
====
- add unittest for aa%bb (without space) to be parsed correctly as modulo
ubyte bb1 = 199
ubyte bb2 = 12
ubyte bb3 = bb1%bb2
txt.print_ub(bb3)
- fix bitshift.p8
- make internalCast() not complain anymore about signed <-> unsigned conversions
- add crc8 and crc16 and crc32 to math
- fix crc* bench routines to no longer depend on the kernal rom version (use a bin file)