mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
Parse hex integers in unary operators
Unary operators ~ and - should work with hex integers
This commit is contained in:
@@ -1941,14 +1941,23 @@ pub fn translate_expr(
|
||||
// Special case: if we're negating "9223372036854775808", this is exactly MIN_INT64
|
||||
// If we don't do this -1 * 9223372036854775808 will overflow and parse will fail
|
||||
// and trigger conversion to Real.
|
||||
if numeric_value == "9223372036854775808" {
|
||||
if numeric_value == "9223372036854775808"
|
||||
|| numeric_value == "0x7fffffffffffffff"
|
||||
|| numeric_value == "0x7FFFFFFFFFFFFFFF"
|
||||
{
|
||||
program.emit_insn(Insn::Integer {
|
||||
value: i64::MIN,
|
||||
dest: target_register,
|
||||
});
|
||||
} else {
|
||||
let maybe_int = numeric_value.parse::<i64>();
|
||||
if let Ok(value) = maybe_int {
|
||||
if numeric_value.starts_with("0x") {
|
||||
// must be a hex decimal
|
||||
let int_value = i64::from_str_radix(&numeric_value[2..], 16)?;
|
||||
program.emit_insn(Insn::Integer {
|
||||
value: -int_value,
|
||||
dest: target_register,
|
||||
});
|
||||
} else if let Ok(value) = numeric_value.parse::<i64>() {
|
||||
program.emit_insn(Insn::Integer {
|
||||
value: value * -1,
|
||||
dest: target_register,
|
||||
@@ -1982,8 +1991,13 @@ pub fn translate_expr(
|
||||
Ok(target_register)
|
||||
}
|
||||
(UnaryOperator::BitwiseNot, ast::Expr::Literal(ast::Literal::Numeric(num_val))) => {
|
||||
let maybe_int = num_val.parse::<i64>();
|
||||
if let Ok(val) = maybe_int {
|
||||
if num_val.starts_with("0x") {
|
||||
let int_value = i64::from_str_radix(&num_val[2..], 16)?;
|
||||
program.emit_insn(Insn::Integer {
|
||||
value: !int_value,
|
||||
dest: target_register,
|
||||
});
|
||||
} else if let Ok(val) = num_val.parse::<i64>() {
|
||||
program.emit_insn(Insn::Integer {
|
||||
value: !val,
|
||||
dest: target_register,
|
||||
|
||||
@@ -612,10 +612,14 @@ do_execsql_test bitwise-not-text-float {
|
||||
SELECT ~'823.34'
|
||||
} {-824}
|
||||
|
||||
do_execsql_test bitwise-not-text-int {
|
||||
do_execsql_test bitwise-not-text-int-1 {
|
||||
SELECT ~'1234'
|
||||
} {-1235}
|
||||
|
||||
do_execsql_test bitwise-not-text-int-2 {
|
||||
SELECT ~0xA
|
||||
} {-11}
|
||||
|
||||
do_execsql_test bitwise-not-scalar-float {
|
||||
SELECT ~abs(693.9)
|
||||
} {-694}
|
||||
|
||||
@@ -15,6 +15,10 @@ do_execsql_test select-const-3 {
|
||||
SELECT 0xDEAF
|
||||
} {57007}
|
||||
|
||||
do_execsql_test select-const-4 {
|
||||
SELECT -0xA
|
||||
} {-10}
|
||||
|
||||
do_execsql_test select-true {
|
||||
SELECT true
|
||||
} {1}
|
||||
|
||||
Reference in New Issue
Block a user