fix type casting issues and unary ^ operator

signed numbers are no longer implicitly converted to unsigned
proper range check on bankof()
This commit is contained in:
Irmen de Jong
2024-12-01 14:28:41 +01:00
parent 58f696d00a
commit 50c3d809dc
18 changed files with 271 additions and 86 deletions

View File

@@ -294,6 +294,14 @@ class PtNumber(type: DataType, val number: Double, position: Position) : PtExpre
if (trunc != number)
throw IllegalArgumentException("refused truncating of float to avoid loss of precision @$position")
}
when(type) {
DataType.UBYTE -> require(number in 0.0..255.0)
DataType.BYTE -> require(number in -128.0..127.0)
DataType.UWORD -> require(number in 0.0..65535.0)
DataType.WORD -> require(number in -32728.0..32767.0)
DataType.LONG -> require(number in -2147483647.0..2147483647.0)
else -> {}
}
}
override fun hashCode(): Int = Objects.hash(type, number)
@@ -318,7 +326,7 @@ class PtPrefix(val operator: String, type: DataType, position: Position): PtExpr
get() = children.single() as PtExpression
init {
require(operator in setOf("+", "-", "~", "^", "<<", "not")) { "invalid prefix operator: $operator" }
require(operator in setOf("+", "-", "~", "^", "<<", "not")) { "invalid prefix operator: $operator" } // TODO ^ and << are experimental
}
}

View File

@@ -4,7 +4,7 @@ val AssociativeOperators = setOf("+", "*", "&", "|", "^", "==", "!=", "xor")
val ComparisonOperators = setOf("==", "!=", "<", ">", "<=", ">=")
val LogicalOperators = setOf("and", "or", "xor", "not", "in")
val BitwiseOperators = setOf("&", "|", "^", "~")
val PrefixOperators = setOf("+", "-", "~", "not")
val PrefixOperators = setOf("+", "-", "~", "^", "<<", "not") // TODO ^ and << are experimental
fun invertedComparisonOperator(operator: String) =
when (operator) {

View File

@@ -1089,7 +1089,7 @@ object PetsciiEncoding {
Ok(text.map {
try {
encodeChar(it, lowercase)
} catch (x: CharConversionException) {
} catch (_: CharConversionException) {
encodeChar(it, !lowercase)
}
})
@@ -1135,7 +1135,7 @@ object PetsciiEncoding {
Ok(text.map {
try {
encodeChar(it, lowercase)
} catch (x: CharConversionException) {
} catch (_: CharConversionException) {
encodeChar(it, !lowercase)
}
})