snarkvm_synthesizer_program

Macro instruction

Source
macro_rules! instruction {
    ($object:expr, |$input:ident| $operation:block) => { ... };
    ($object:expr, |$input:ident| $operation:expr) => { ... };
    ($macro_:ident, $object:expr, |$input:ident| $operation:block) => { ... };
    ($macro_:ident, $object:expr, |$input:ident| $operation:expr) => { ... };
    ($macro_:ident!($object:expr, $input:ident)) => { ... };
    ($object:expr, |InstructionMember| $operation:block, { $( $variant:ident, )+ }) => { ... };
    ($object:expr, |InstructionMember| $operation:expr, { $( $variant:ident, )+ }) => { ... };
    ($object:expr, |$instruction:ident| $operation:block, { $( $variant:ident, )+ }) => { ... };
    ($object:expr, |$instruction:ident| $operation:expr, { $( $variant:ident, )+ }) => { ... };
}
Expand description

Creates a match statement that applies the given operation for each instruction.

§Example

This example will print the opcode and the instruction to the given stream.

instruction!(self, |instruction| write!(f, "{} {};", self.opcode(), instruction))

The above example is equivalent to the following logic:

    match self {
        Self::Add(instruction) => write!(f, "{} {};", self.opcode(), instruction),
        Self::Sub(instruction) => write!(f, "{} {};", self.opcode(), instruction),
        Self::Mul(instruction) => write!(f, "{} {};", self.opcode(), instruction),
        Self::Div(instruction) => write!(f, "{} {};", self.opcode(), instruction),
    }
)