fix naughty macros

This commit is contained in:
Nikolay Volf 2016-02-25 02:05:59 +03:00
parent ccaa194681
commit 0794049d18

View File

@ -53,6 +53,12 @@ macro_rules! impl_map_from {
#[cfg(not(all(feature="dev", target_arch = "x86_64")))] #[cfg(not(all(feature="dev", target_arch = "x86_64")))]
macro_rules! uint_overflowing_add { macro_rules! uint_overflowing_add {
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({
uint_overflowing_add_reg!($name, $n_words, $self_expr, $other)
})
}
macro_rules! uint_overflowing_add_reg {
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({ ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({
let $name(ref me) = $self_expr; let $name(ref me) = $self_expr;
let $name(ref you) = $other; let $name(ref you) = $other;
@ -82,6 +88,7 @@ macro_rules! uint_overflowing_add {
}) })
} }
#[cfg(all(feature="dev", target_arch = "x86_64"))] #[cfg(all(feature="dev", target_arch = "x86_64"))]
macro_rules! uint_overflowing_add { macro_rules! uint_overflowing_add {
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
@ -106,7 +113,7 @@ macro_rules! uint_overflowing_add {
(U256(result), overflow != 0) (U256(result), overflow != 0)
}); });
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => (
overflowing_add_regular!($name, $n_words, $self_expr, $other) uint_overflowing_add_reg!($name, $n_words, $self_expr, $other)
) )
} }
@ -142,9 +149,11 @@ macro_rules! uint_overflowing_sub {
} }
(U256(result), overflow != 0) (U256(result), overflow != 0)
}); });
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( ($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
overflowing_add_regular!($name, $n_words, $self_expr, $other) let res = overflowing!((!$other).overflowing_add(From::from(1u64)));
) let res = overflowing!($self_expr.overflowing_add(res));
(res, $self_expr < $other)
})
} }
#[cfg(all(feature="dev", target_arch = "x86_64"))] #[cfg(all(feature="dev", target_arch = "x86_64"))]
@ -241,12 +250,18 @@ macro_rules! uint_overflowing_mul {
(U256(result), overflow > 0) (U256(result), overflow > 0)
}); });
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => (
overflowing_mul_regular!($name, $n_words, $self_expr, $other) uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other)
) )
} }
#[cfg(not(all(feature="dev", target_arch = "x86_64")))] #[cfg(not(all(feature="dev", target_arch = "x86_64")))]
macro_rules! uint_overflowing_mul { macro_rules! uint_overflowing_mul {
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other)
})
}
macro_rules! uint_overflowing_mul_reg {
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({ ($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
let mut res = $name::from(0u64); let mut res = $name::from(0u64);
let mut overflow = false; let mut overflow = false;