fix no_std building
This commit is contained in:
parent
d2ea44e37c
commit
0b6dd64219
|
@ -15,9 +15,8 @@ wasmi-validation = { version = "0.2", path = "validation", default-features = fa
|
||||||
parity-wasm = { version = "0.40.1", default-features = false }
|
parity-wasm = { version = "0.40.1", default-features = false }
|
||||||
memory_units = "0.3.0"
|
memory_units = "0.3.0"
|
||||||
libm = { version = "0.1.2", optional = true }
|
libm = { version = "0.1.2", optional = true }
|
||||||
num-rational = "0.2.2"
|
num-rational = { version = "0.2.2", default-features = false }
|
||||||
num-traits = "0.2.8"
|
num-traits = { version = "0.2.8", default-features = false }
|
||||||
libc = "0.2.58"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = "1.1"
|
assert_matches = "1.1"
|
||||||
|
@ -31,6 +30,7 @@ std = [
|
||||||
"parity-wasm/std",
|
"parity-wasm/std",
|
||||||
"wasmi-validation/std",
|
"wasmi-validation/std",
|
||||||
"num-rational/std",
|
"num-rational/std",
|
||||||
|
"num-rational/bigint-std",
|
||||||
"num-traits/std"
|
"num-traits/std"
|
||||||
]
|
]
|
||||||
# Enable for no_std support
|
# Enable for no_std support
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use libm::{F32Ext, F64Ext};
|
||||||
|
|
||||||
use core::cmp::{Ordering, PartialEq, PartialOrd};
|
use core::cmp::{Ordering, PartialEq, PartialOrd};
|
||||||
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
|
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
|
||||||
|
|
||||||
|
|
27
src/value.rs
27
src/value.rs
|
@ -368,6 +368,7 @@ impl WrapInto<F32> for F64 {
|
||||||
macro_rules! impl_try_truncate_into {
|
macro_rules! impl_try_truncate_into {
|
||||||
(@primitive $from: ident, $into: ident, $to_primitive:path) => {
|
(@primitive $from: ident, $into: ident, $to_primitive:path) => {
|
||||||
impl TryTruncateInto<$into, TrapKind> for $from {
|
impl TryTruncateInto<$into, TrapKind> for $from {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
||||||
// Casting from a float to an integer will round the float towards zero
|
// Casting from a float to an integer will round the float towards zero
|
||||||
num_rational::BigRational::from_float(self)
|
num_rational::BigRational::from_float(self)
|
||||||
|
@ -375,6 +376,23 @@ macro_rules! impl_try_truncate_into {
|
||||||
.and_then(|val| $to_primitive(&val))
|
.and_then(|val| $to_primitive(&val))
|
||||||
.ok_or(TrapKind::InvalidConversionToInt)
|
.ok_or(TrapKind::InvalidConversionToInt)
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
||||||
|
// Casting from a float to an integer will round the float towards zero
|
||||||
|
// NOTE: currently this will cause Undefined Behavior if the rounded value cannot be represented by the
|
||||||
|
// target integer type. This includes Inf and NaN. This is a bug and will be fixed.
|
||||||
|
if self.is_nan() || self.is_infinite() {
|
||||||
|
return Err(TrapKind::InvalidConversionToInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// range check
|
||||||
|
let result = self as $into;
|
||||||
|
if result as $from != self.trunc() {
|
||||||
|
return Err(TrapKind::InvalidConversionToInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(self as $into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(@wrapped $from:ident, $intermediate:ident, $into:ident) => {
|
(@wrapped $from:ident, $intermediate:ident, $into:ident) => {
|
||||||
|
@ -819,15 +837,6 @@ impl_integer!(u32);
|
||||||
impl_integer!(i64);
|
impl_integer!(i64);
|
||||||
impl_integer!(u64);
|
impl_integer!(u64);
|
||||||
|
|
||||||
// Use std float functions in std environment.
|
|
||||||
// And libm's implementation in no_std
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
macro_rules! call_math {
|
|
||||||
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
|
||||||
$fXX::$op($e)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
macro_rules! call_math {
|
macro_rules! call_math {
|
||||||
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
||||||
::libm::$FXXExt::$op($e)
|
::libm::$FXXExt::$op($e)
|
||||||
|
|
Loading…
Reference in New Issue