style(semantics): move macro impls to specific modules
This commit is contained in:
parent
b517043d0e
commit
55b7cdd075
5 changed files with 127 additions and 122 deletions
|
|
@ -2,9 +2,82 @@ use argus_core::expr::BoolExpr;
|
|||
use argus_core::prelude::*;
|
||||
|
||||
use crate::eval::NumExprEval;
|
||||
use crate::utils::{signal_bool_op_impl, signal_cmp_op_impl};
|
||||
use crate::{Semantics, Trace};
|
||||
|
||||
macro_rules! signal_cmp_op_impl {
|
||||
($lhs:ident, $rhs:ident, $op:ident, [$( $type:ident ),*]) => {
|
||||
paste::paste!{
|
||||
{
|
||||
use argus_core::signals::traits::SignalPartialOrd;
|
||||
use argus_core::prelude::*;
|
||||
use AnySignal::*;
|
||||
match ($lhs, $rhs) {
|
||||
(Bool(_), _) | (ConstBool(_), _) | (_, Bool(_)) | (_, ConstBool(_)) => panic!("cannot perform comparison operation ({}) for boolean arguments", stringify!($op)),
|
||||
$(
|
||||
([<$type >](lhs), [< $type >](rhs)) => lhs.$op(&rhs).map(AnySignal::from),
|
||||
([<$type >](lhs), [< Const $type >](rhs)) => lhs.$op(&rhs).map(AnySignal::from),
|
||||
([<Const $type >](lhs), [< $type >](rhs)) => lhs.$op(&rhs).map(AnySignal::from),
|
||||
([<Const $type >](lhs), [< Const $type >](rhs)) => lhs.$op(&rhs).map(AnySignal::from),
|
||||
)*
|
||||
_ => panic!("mismatched argument types for comparison operation ({})", stringify!($op)),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($lhs:ident < $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_lt, [Int, UInt, Float])
|
||||
};
|
||||
|
||||
($lhs:ident <= $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_le, [Int, UInt, Float])
|
||||
};
|
||||
|
||||
($lhs:ident > $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_gt, [Int, UInt, Float])
|
||||
};
|
||||
($lhs:ident >= $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_ge, [Int, UInt, Float])
|
||||
};
|
||||
|
||||
($lhs:ident == $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_eq, [Int, UInt, Float])
|
||||
};
|
||||
|
||||
($lhs:ident != $rhs:ident) => {
|
||||
signal_cmp_op_impl!($lhs, $rhs, signal_ne, [Int, UInt, Float])
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! signal_bool_op_impl {
|
||||
// Unary bool opeartions
|
||||
(! $signal:ident) => {{
|
||||
use argus_core::prelude::*;
|
||||
use AnySignal::*;
|
||||
match $signal {
|
||||
Bool(sig) => AnySignal::from(!(&sig)),
|
||||
ConstBool(sig) => AnySignal::from(!(&sig)),
|
||||
_ => panic!("cannot perform unary operation (!) on numeric signals"),
|
||||
}
|
||||
}};
|
||||
|
||||
($lhs:ident $op:tt $rhs:ident) => {
|
||||
paste::paste! {
|
||||
{
|
||||
use argus_core::prelude::*;
|
||||
use AnySignal::*;
|
||||
match ($lhs, $rhs) {
|
||||
(Bool(lhs), Bool(rhs)) => AnySignal::from(&lhs $op &rhs),
|
||||
(Bool(lhs), ConstBool(rhs)) => AnySignal::from(&lhs $op &rhs),
|
||||
(ConstBool(lhs), Bool(rhs)) => AnySignal::from(&lhs $op &rhs),
|
||||
(ConstBool(lhs), ConstBool(rhs)) => AnySignal::from(&lhs $op &rhs),
|
||||
_ => panic!("mismatched argument types for {} operation", stringify!($op)),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Boolean semantics of Argus expressions
|
||||
pub struct BooleanSemantics;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue