Avoid warnings.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use crate::def_package;
|
||||
use crate::module::FuncReturn;
|
||||
use crate::parser::INT;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::{result::EvalAltResult, token::Position};
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use crate::parser::FLOAT;
|
||||
@@ -11,22 +12,25 @@ use crate::parser::FLOAT;
|
||||
#[cfg(feature = "no_std")]
|
||||
use num_traits::*;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use num_traits::{
|
||||
identities::Zero, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl,
|
||||
CheckedShr, CheckedSub,
|
||||
};
|
||||
|
||||
use crate::stdlib::{
|
||||
boxed::Box,
|
||||
fmt::Display,
|
||||
format,
|
||||
ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Sub},
|
||||
};
|
||||
use crate::stdlib::ops::{BitAnd, BitOr, BitXor};
|
||||
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
use crate::stdlib::ops::{Add, Div, Mul, Neg, Rem, Sub};
|
||||
|
||||
#[cfg(feature = "unchecked")]
|
||||
use crate::stdlib::ops::{Shl, Shr};
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::stdlib::{boxed::Box, fmt::Display, format};
|
||||
|
||||
// Checked add
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn add<T: Display + CheckedAdd>(x: T, y: T) -> FuncReturn<T> {
|
||||
x.checked_add(&y).ok_or_else(|| {
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
@@ -36,6 +40,7 @@ pub(crate) fn add<T: Display + CheckedAdd>(x: T, y: T) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Checked subtract
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn sub<T: Display + CheckedSub>(x: T, y: T) -> FuncReturn<T> {
|
||||
x.checked_sub(&y).ok_or_else(|| {
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
@@ -45,6 +50,7 @@ pub(crate) fn sub<T: Display + CheckedSub>(x: T, y: T) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Checked multiply
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn mul<T: Display + CheckedMul>(x: T, y: T) -> FuncReturn<T> {
|
||||
x.checked_mul(&y).ok_or_else(|| {
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
@@ -54,6 +60,7 @@ pub(crate) fn mul<T: Display + CheckedMul>(x: T, y: T) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Checked divide
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn div<T>(x: T, y: T) -> FuncReturn<T>
|
||||
where
|
||||
T: Display + CheckedDiv + PartialEq + Zero,
|
||||
@@ -74,6 +81,7 @@ where
|
||||
})
|
||||
}
|
||||
// Checked negative - e.g. -(i32::MIN) will overflow i32::MAX
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn neg<T: Display + CheckedNeg>(x: T) -> FuncReturn<T> {
|
||||
x.checked_neg().ok_or_else(|| {
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
@@ -83,6 +91,7 @@ pub(crate) fn neg<T: Display + CheckedNeg>(x: T) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Checked absolute
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn abs<T: Display + CheckedNeg + PartialOrd + Zero>(x: T) -> FuncReturn<T> {
|
||||
// FIX - We don't use Signed::abs() here because, contrary to documentation, it panics
|
||||
// when the number is ::MIN instead of returning ::MIN itself.
|
||||
@@ -98,26 +107,32 @@ pub(crate) fn abs<T: Display + CheckedNeg + PartialOrd + Zero>(x: T) -> FuncRetu
|
||||
}
|
||||
}
|
||||
// Unchecked add - may panic on overflow
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn add_u<T: Add>(x: T, y: T) -> FuncReturn<<T as Add>::Output> {
|
||||
Ok(x + y)
|
||||
}
|
||||
// Unchecked subtract - may panic on underflow
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn sub_u<T: Sub>(x: T, y: T) -> FuncReturn<<T as Sub>::Output> {
|
||||
Ok(x - y)
|
||||
}
|
||||
// Unchecked multiply - may panic on overflow
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn mul_u<T: Mul>(x: T, y: T) -> FuncReturn<<T as Mul>::Output> {
|
||||
Ok(x * y)
|
||||
}
|
||||
// Unchecked divide - may panic when dividing by zero
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn div_u<T: Div>(x: T, y: T) -> FuncReturn<<T as Div>::Output> {
|
||||
Ok(x / y)
|
||||
}
|
||||
// Unchecked negative - may panic on overflow
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn neg_u<T: Neg>(x: T) -> FuncReturn<<T as Neg>::Output> {
|
||||
Ok(-x)
|
||||
}
|
||||
// Unchecked absolute - may panic on overflow
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn abs_u<T>(x: T) -> FuncReturn<<T as Neg>::Output>
|
||||
where
|
||||
T: Neg + PartialOrd + Default + Into<<T as Neg>::Output>,
|
||||
@@ -140,6 +155,7 @@ fn binary_xor<T: BitXor>(x: T, y: T) -> FuncReturn<<T as BitXor>::Output> {
|
||||
Ok(x ^ y)
|
||||
}
|
||||
// Checked left-shift
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn shl<T: Display + CheckedShl>(x: T, y: INT) -> FuncReturn<T> {
|
||||
// Cannot shift by a negative number of bits
|
||||
if y < 0 {
|
||||
@@ -157,6 +173,7 @@ pub(crate) fn shl<T: Display + CheckedShl>(x: T, y: INT) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Checked right-shift
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn shr<T: Display + CheckedShr>(x: T, y: INT) -> FuncReturn<T> {
|
||||
// Cannot shift by a negative number of bits
|
||||
if y < 0 {
|
||||
@@ -184,6 +201,7 @@ pub(crate) fn shr_u<T: Shr<T>>(x: T, y: T) -> FuncReturn<<T as Shr<T>>::Output>
|
||||
Ok(x.shr(y))
|
||||
}
|
||||
// Checked modulo
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn modulo<T: Display + CheckedRem>(x: T, y: T) -> FuncReturn<T> {
|
||||
x.checked_rem(&y).ok_or_else(|| {
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
@@ -193,10 +211,12 @@ pub(crate) fn modulo<T: Display + CheckedRem>(x: T, y: T) -> FuncReturn<T> {
|
||||
})
|
||||
}
|
||||
// Unchecked modulo - may panic if dividing by zero
|
||||
#[cfg(any(feature = "unchecked", not(feature = "no_float")))]
|
||||
fn modulo_u<T: Rem>(x: T, y: T) -> FuncReturn<<T as Rem>::Output> {
|
||||
Ok(x % y)
|
||||
}
|
||||
// Checked power
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn pow_i_i(x: INT, y: INT) -> FuncReturn<INT> {
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
if y > (u32::MAX as INT) {
|
||||
@@ -245,6 +265,7 @@ pub(crate) fn pow_f_f(x: FLOAT, y: FLOAT) -> FuncReturn<FLOAT> {
|
||||
}
|
||||
// Checked power
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub(crate) fn pow_f_i(x: FLOAT, y: INT) -> FuncReturn<FLOAT> {
|
||||
// Raise to power that is larger than an i32
|
||||
if y > (i32::MAX as INT) {
|
||||
|
@@ -5,10 +5,14 @@ use crate::def_package;
|
||||
use crate::engine::{Array, Engine};
|
||||
use crate::module::{FuncReturn, Module};
|
||||
use crate::parser::{ImmutableString, INT};
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
|
||||
use crate::stdlib::{any::TypeId, boxed::Box, string::ToString};
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::{result::EvalAltResult, token::Position};
|
||||
|
||||
use crate::stdlib::{any::TypeId, boxed::Box};
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::stdlib::string::ToString;
|
||||
|
||||
// Register array utility functions
|
||||
fn push<T: Variant + Clone>(list: &mut Array, item: T) -> FuncReturn<()> {
|
||||
@@ -26,7 +30,7 @@ fn ins<T: Variant + Clone>(list: &mut Array, position: INT, item: T) -> FuncRetu
|
||||
Ok(())
|
||||
}
|
||||
fn pad<T: Variant + Clone>(
|
||||
engine: &Engine,
|
||||
_engine: &Engine,
|
||||
_: &Module,
|
||||
args: &mut [&mut Dynamic],
|
||||
) -> FuncReturn<()> {
|
||||
@@ -34,10 +38,13 @@ fn pad<T: Variant + Clone>(
|
||||
|
||||
// Check if array will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if engine.max_array_size > 0 && len > 0 && (len as usize) > engine.max_array_size {
|
||||
if _engine.limits.max_array_size > 0
|
||||
&& len > 0
|
||||
&& (len as usize) > _engine.limits.max_array_size
|
||||
{
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Size of array".to_string(),
|
||||
engine.max_array_size,
|
||||
_engine.limits.max_array_size,
|
||||
len as usize,
|
||||
Position::none(),
|
||||
)));
|
||||
|
@@ -1,16 +1,20 @@
|
||||
#![cfg(not(feature = "no_object"))]
|
||||
|
||||
use crate::any::Dynamic;
|
||||
use crate::def_package;
|
||||
use crate::engine::Map;
|
||||
use crate::module::FuncReturn;
|
||||
use crate::parser::{ImmutableString, INT};
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
use crate::{any::Dynamic, module::FuncReturn};
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
use crate::stdlib::vec::Vec;
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
fn map_get_keys(map: &mut Map) -> FuncReturn<Vec<Dynamic>> {
|
||||
Ok(map.iter().map(|(k, _)| k.clone().into()).collect())
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
fn map_get_values(map: &mut Map) -> FuncReturn<Vec<Dynamic>> {
|
||||
Ok(map.iter().map(|(_, v)| v.clone()).collect())
|
||||
}
|
||||
|
@@ -1,20 +1,26 @@
|
||||
use crate::def_package;
|
||||
use crate::parser::INT;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use crate::parser::FLOAT;
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::{result::EvalAltResult, token::Position};
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[cfg(feature = "no_std")]
|
||||
use num_traits::*;
|
||||
|
||||
use crate::stdlib::{boxed::Box, format, i32, i64};
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::stdlib::{boxed::Box, format};
|
||||
|
||||
#[cfg(feature = "only_i32")]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub const MAX_INT: INT = i32::MAX;
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
pub const MAX_INT: INT = i64::MAX;
|
||||
|
||||
def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, {
|
||||
|
@@ -24,7 +24,6 @@ pub use arithmetic::ArithmeticPackage;
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub use array_basic::BasicArrayPackage;
|
||||
pub use eval::EvalPackage;
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use fn_basic::BasicFnPackage;
|
||||
pub use iter_basic::BasicIteratorPackage;
|
||||
pub use logic::LogicPackage;
|
||||
|
@@ -3,10 +3,11 @@ use crate::def_package;
|
||||
use crate::engine::Engine;
|
||||
use crate::module::{FuncReturn, Module};
|
||||
use crate::parser::{ImmutableString, INT};
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
use crate::utils::StaticVec;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::{result::EvalAltResult, token::Position};
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
use crate::engine::Array;
|
||||
|
||||
@@ -226,15 +227,15 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
||||
lib.set_raw_fn(
|
||||
"pad",
|
||||
&[TypeId::of::<ImmutableString>(), TypeId::of::<INT>(), TypeId::of::<char>()],
|
||||
|engine: &Engine, _: &Module, args: &mut [&mut Dynamic]| {
|
||||
|_engine: &Engine, _: &Module, args: &mut [&mut Dynamic]| {
|
||||
let len = *args[1].downcast_ref::< INT>().unwrap();
|
||||
|
||||
// Check if string will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if engine.max_string_size > 0 && len > 0 && (len as usize) > engine.max_string_size {
|
||||
if _engine.limits.max_string_size > 0 && len > 0 && (len as usize) > _engine.limits.max_string_size {
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
_engine.limits.max_string_size,
|
||||
len as usize,
|
||||
Position::none(),
|
||||
)));
|
||||
@@ -253,10 +254,11 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
||||
p.push(ch);
|
||||
}
|
||||
|
||||
if engine.max_string_size > 0 && s.len() > engine.max_string_size {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _engine.limits.max_string_size > 0 && s.len() > _engine.limits.max_string_size {
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
_engine.limits.max_string_size,
|
||||
s.len(),
|
||||
Position::none(),
|
||||
)));
|
||||
|
@@ -2,6 +2,7 @@
|
||||
use super::logic::{eq, gt, gte, lt, lte, ne};
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use super::math_basic::MAX_INT;
|
||||
|
||||
use crate::def_package;
|
||||
@@ -11,7 +12,11 @@ use crate::result::EvalAltResult;
|
||||
use crate::parser::FLOAT;
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
use crate::{module::FuncReturn, parser::INT, token::Position};
|
||||
use crate::parser::INT;
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::token::Position;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::stdlib::time::Instant;
|
||||
|
Reference in New Issue
Block a user