Fix UINT -> UNSIGNED_INT.

This commit is contained in:
Stephen Chung 2022-01-13 22:51:56 +08:00
parent 25f54c0ea5
commit 96764c0d2d
5 changed files with 15 additions and 10 deletions

View File

@ -859,7 +859,8 @@ impl Engine {
( (
start as u8, start as u8,
// 2^bits - 1 // 2^bits - 1
(((2 as crate::UINT).pow((end - start) as u32) - 1) as crate::INT) (((2 as crate::UNSIGNED_INT).pow((end - start) as u32) - 1)
as crate::INT)
<< start, << start,
) )
} }
@ -883,7 +884,8 @@ impl Engine {
( (
start as u8, start as u8,
// 2^bits - 1 // 2^bits - 1
(((2 as crate::UINT).pow((end - start + 1) as u32) - 1) as crate::INT) (((2 as crate::UNSIGNED_INT).pow((end - start + 1) as u32) - 1)
as crate::INT)
<< start, << start,
) )
} }

View File

@ -112,7 +112,8 @@ pub type INT = i32;
/// If the `only_i32` feature is enabled, this will be [`u32`] instead. /// If the `only_i32` feature is enabled, this will be [`u32`] instead.
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
type UINT = u64; type UNSIGNED_INT = u64;
/// The unsigned system integer base type. /// The unsigned system integer base type.
/// It is defined as [`u32`] since the `only_i32` feature is used. /// It is defined as [`u32`] since the `only_i32` feature is used.
/// ///

View File

@ -2,7 +2,9 @@
use crate::eval::calc_index; use crate::eval::calc_index;
use crate::plugin::*; use crate::plugin::*;
use crate::{def_package, ExclusiveRange, InclusiveRange, Position, RhaiResultOf, ERR, INT, UINT}; use crate::{
def_package, ExclusiveRange, InclusiveRange, Position, RhaiResultOf, ERR, INT, UNSIGNED_INT,
};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -75,7 +77,7 @@ mod bit_field_functions {
} }
// 2^bits - 1 // 2^bits - 1
let mask = ((2 as UINT).pow(bits as u32) - 1) as crate::INT; let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as crate::INT;
Ok(((value & (mask << bit)) >> bit) & mask) Ok(((value & (mask << bit)) >> bit) & mask)
} }
@ -121,7 +123,7 @@ mod bit_field_functions {
} }
// 2^bits - 1 // 2^bits - 1
let mask = ((2 as UINT).pow(bits as u32) - 1) as crate::INT; let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as crate::INT;
*value &= !(mask << bit); *value &= !(mask << bit);
*value |= (new_value & mask) << bit; *value |= (new_value & mask) << bit;

View File

@ -1,7 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::plugin::*; use crate::plugin::*;
use crate::{def_package, Position, RhaiResultOf, ERR, INT, UINT}; use crate::{def_package, Position, RhaiResultOf, ERR, INT, UNSIGNED_INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -118,7 +118,7 @@ mod int_functions {
.into()); .into());
} }
UINT::from_str_radix(string.trim(), radix as u32) UNSIGNED_INT::from_str_radix(string.trim(), radix as u32)
.map(|v| v as INT) .map(|v| v as INT)
.map_err(|err| { .map_err(|err| {
ERR::ErrorArithmetic( ERR::ErrorArithmetic(

View File

@ -5,7 +5,7 @@ use crate::engine::{
KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF,
}; };
use crate::func::native::OnParseTokenCallback; use crate::func::native::OnParseTokenCallback;
use crate::{Engine, LexError, StaticVec, INT, UINT}; use crate::{Engine, LexError, StaticVec, INT, UNSIGNED_INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
use std::{ use std::{
@ -1530,7 +1530,7 @@ fn get_next_token_inner(
.filter(|&&c| c != NUMBER_SEPARATOR) .filter(|&&c| c != NUMBER_SEPARATOR)
.collect(); .collect();
UINT::from_str_radix(&out, radix) UNSIGNED_INT::from_str_radix(&out, radix)
.map(|v| v as INT) .map(|v| v as INT)
.map(Token::IntegerConstant) .map(Token::IntegerConstant)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {