Support hex integers beginning with uppercase notation like 0Xfff or 0XFFF

This commit is contained in:
Anton Harniakou
2025-04-14 21:23:04 +03:00
parent 3c06ddadde
commit 0cebeef2ff

View File

@@ -1850,7 +1850,7 @@ pub fn translate_expr(
}
ast::Expr::Literal(lit) => match lit {
ast::Literal::Numeric(val) => {
if val.starts_with("0x") {
if val.starts_with("0x") || val.starts_with("0X") {
// must be a hex decimal
let int_value = i64::from_str_radix(&val[2..], 16)?;
program.emit_insn(Insn::Integer {
@@ -1942,15 +1942,14 @@ pub fn translate_expr(
// If we don't do this -1 * 9223372036854775808 will overflow and parse will fail
// and trigger conversion to Real.
if numeric_value == "9223372036854775808"
|| numeric_value == "0x7fffffffffffffff"
|| numeric_value == "0x7FFFFFFFFFFFFFFF"
|| numeric_value.to_lowercase() == "0x7fffffffffffffff"
{
program.emit_insn(Insn::Integer {
value: i64::MIN,
dest: target_register,
});
} else {
if numeric_value.starts_with("0x") {
if numeric_value.starts_with("0x") || 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 {
@@ -1991,7 +1990,7 @@ pub fn translate_expr(
Ok(target_register)
}
(UnaryOperator::BitwiseNot, ast::Expr::Literal(ast::Literal::Numeric(num_val))) => {
if num_val.starts_with("0x") {
if num_val.starts_with("0x") || num_val.starts_with("0X") {
let int_value = i64::from_str_radix(&num_val[2..], 16)?;
program.emit_insn(Insn::Integer {
value: !int_value,