mute/mute-interpreter/src/macros.rs

22 lines
606 B
Rust
Raw Normal View History

2024-05-10 22:56:21 +00:00
// TODO: argument count checking should happen at parse time, not at runtime
2024-02-18 03:16:51 +00:00
#[macro_export]
macro_rules! arg_count {
($expected:expr, $given:expr) => {
if $expected != $given {
2024-05-10 22:56:21 +00:00
return Node::Error(format!("expected {} arg(s), got {}", $expected, $given));
2024-02-18 03:16:51 +00:00
}
};
(modulo: $modulo:expr, $given:expr) => {
2024-03-09 13:10:02 +00:00
if $given % $modulo != 0 {
return Node::Error(format!(
2024-05-10 22:56:21 +00:00
"expected {} arg(s), got {}",
2024-03-09 13:10:02 +00:00
($given / $modulo) * $modulo + $modulo,
$given,
));
2024-03-09 13:10:02 +00:00
}
};
2024-02-18 03:16:51 +00:00
}
pub(crate) use arg_count;