-
Notifications
You must be signed in to change notification settings - Fork 596
Open
Labels
Description
What happened?
Source
Screenshot
Code Snippet
// Helper macro for defining instructions without having to have tons of
// exhaustive `match` statements to update
macro_rules! def_instruction {
(
$( #[$enum_attr:meta] )*
pub enum Instruction<'a> {
$(
$( #[$attr:meta] )*
$variant:ident $( {
$($field:ident : $field_ty:ty $(,)* )*
} )?
:
[$num_popped:expr] => [$num_pushed:expr],
)*
}
) => {
$( #[$enum_attr] )*
pub enum Instruction<'a> {
$(
$( #[$attr] )*
$variant $( {
$(
$field : $field_ty,
)*
} )? ,
)*
}
impl Instruction<'_> {
/// How many operands does this instruction pop from the stack?
#[allow(unused_variables)]
pub fn operands_len(&self) -> usize {
match self {
$(
Self::$variant $( {
$(
$field,
)*
} )? => $num_popped,
)*
}
}
/// How many results does this instruction push onto the stack?
#[allow(unused_variables)]
pub fn results_len(&self) -> usize {
match self {
$(
Self::$variant $( {
$(
$field,
)*
} )? => $num_pushed,
)*
}
}
}
};
}