mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-23 11:41:58 +00:00
division fix
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
target
|
target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.vscode
|
@ -613,7 +613,7 @@ impl Interpreter {
|
|||||||
.value_stack_mut()
|
.value_stack_mut()
|
||||||
.pop_pair_as::<T>()
|
.pop_pair_as::<T>()
|
||||||
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
||||||
.map(|(left, right)| left.div(right))
|
.map(|(left, right)| left.div(right))?
|
||||||
.map(|v| v.transmute_into())
|
.map(|v| v.transmute_into())
|
||||||
.map(|v| context.value_stack_mut().push(v.into()))
|
.map(|v| context.value_stack_mut().push(v.into()))
|
||||||
.map(|_| InstructionOutcome::RunNextInstruction)
|
.map(|_| InstructionOutcome::RunNextInstruction)
|
||||||
@ -625,7 +625,7 @@ impl Interpreter {
|
|||||||
.value_stack_mut()
|
.value_stack_mut()
|
||||||
.pop_pair_as::<T>()
|
.pop_pair_as::<T>()
|
||||||
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
||||||
.map(|(left, right)| left.rem(right))
|
.map(|(left, right)| left.rem(right))?
|
||||||
.map(|v| v.transmute_into())
|
.map(|v| v.transmute_into())
|
||||||
.map(|v| context.value_stack_mut().push(v.into()))
|
.map(|v| context.value_stack_mut().push(v.into()))
|
||||||
.map(|_| InstructionOutcome::RunNextInstruction)
|
.map(|_| InstructionOutcome::RunNextInstruction)
|
||||||
|
@ -68,7 +68,7 @@ pub trait ArithmeticOps<T> {
|
|||||||
/// Multiply two values.
|
/// Multiply two values.
|
||||||
fn mul(self, other: T) -> T;
|
fn mul(self, other: T) -> T;
|
||||||
/// Divide two values.
|
/// Divide two values.
|
||||||
fn div(self, other: T) -> T;
|
fn div(self, other: T) -> Result<T, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Integer value.
|
/// Integer value.
|
||||||
@ -84,7 +84,7 @@ pub trait Integer<T>: ArithmeticOps<T> {
|
|||||||
/// Get right bit rotation result.
|
/// Get right bit rotation result.
|
||||||
fn rotr(self, other: T) -> T;
|
fn rotr(self, other: T) -> T;
|
||||||
/// Get division remainder.
|
/// Get division remainder.
|
||||||
fn rem(self, other: T) -> T;
|
fn rem(self, other: T) -> Result<T, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Float-point value.
|
/// Float-point value.
|
||||||
@ -541,7 +541,10 @@ macro_rules! impl_integer_arithmetic_ops {
|
|||||||
fn add(self, other: $type) -> $type { self.wrapping_add(other) }
|
fn add(self, other: $type) -> $type { self.wrapping_add(other) }
|
||||||
fn sub(self, other: $type) -> $type { self.wrapping_sub(other) }
|
fn sub(self, other: $type) -> $type { self.wrapping_sub(other) }
|
||||||
fn mul(self, other: $type) -> $type { self.wrapping_mul(other) }
|
fn mul(self, other: $type) -> $type { self.wrapping_mul(other) }
|
||||||
fn div(self, other: $type) -> $type { self.wrapping_div(other) }
|
fn div(self, other: $type) -> Result<$type, Error> {
|
||||||
|
if other == 0 { Err(Error::Value("Division by zero".to_owned())) }
|
||||||
|
else { Ok(self.wrapping_div(other)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,7 +560,7 @@ macro_rules! impl_float_arithmetic_ops {
|
|||||||
fn add(self, other: $type) -> $type { self + other }
|
fn add(self, other: $type) -> $type { self + other }
|
||||||
fn sub(self, other: $type) -> $type { self - other }
|
fn sub(self, other: $type) -> $type { self - other }
|
||||||
fn mul(self, other: $type) -> $type { self * other }
|
fn mul(self, other: $type) -> $type { self * other }
|
||||||
fn div(self, other: $type) -> $type { self / other }
|
fn div(self, other: $type) -> Result<$type, Error> { Ok(self / other) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -573,7 +576,10 @@ macro_rules! impl_integer {
|
|||||||
fn count_ones(self) -> $type { self.count_ones() as $type }
|
fn count_ones(self) -> $type { self.count_ones() as $type }
|
||||||
fn rotl(self, other: $type) -> $type { self.rotate_left(other as u32) }
|
fn rotl(self, other: $type) -> $type { self.rotate_left(other as u32) }
|
||||||
fn rotr(self, other: $type) -> $type { self.rotate_right(other as u32) }
|
fn rotr(self, other: $type) -> $type { self.rotate_right(other as u32) }
|
||||||
fn rem(self, other: $type) -> $type { self.wrapping_rem(other) }
|
fn rem(self, other: $type) -> Result<$type, Error> {
|
||||||
|
if other == 0 { Err(Error::Value("Division by zero".to_owned())) }
|
||||||
|
else { Ok(self.wrapping_rem(other)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user