snarkvm_synthesizer/vm/helpers/
macros.rs#[macro_export]
macro_rules! cast_ref {
(($variable:expr) as $object:ident<$($traits:path),+>) => {{
(&$variable as &dyn std::any::Any)
.downcast_ref::<$object<$($traits),+>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($variable)))?
}};
($variable:ident as $object:ident<$($traits:path),+>) => {{
(&$variable as &dyn std::any::Any)
.downcast_ref::<$object<$($traits),+>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($variable)))?
}};
(&$variable:ident as $object:ident<$($traits:path),+>) => {{
($variable as &dyn std::any::Any)
.downcast_ref::<$object<$($traits),+>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($variable)))?
}};
}
#[macro_export]
macro_rules! cast_mut_ref {
(($variable:expr) as $object:ident<$($traits:path),+>) => {{
(&mut $variable as &mut dyn std::any::Any)
.downcast_mut::<$object<$($traits),+>>()
.ok_or_else(|| anyhow!("Failed to downcast mut {}", stringify!($variable)))?
}};
($variable:ident as $object:ident<$($traits:path),+>) => {{
(&mut $variable as &mut dyn std::any::Any)
.downcast_mut::<$object<$($traits),+>>()
.ok_or_else(|| anyhow!("Failed to downcast mut {}", stringify!($variable)))?
}};
}
#[macro_export]
macro_rules! convert {
($logic:ident) => {{
match N::ID {
console::network::MainnetV0::ID => {
$logic!(console::network::MainnetV0, circuit::AleoV0)
}
console::network::TestnetV0::ID => {
$logic!(console::network::TestnetV0, circuit::AleoTestnetV0)
}
console::network::CanaryV0::ID => {
$logic!(console::network::CanaryV0, circuit::AleoCanaryV0)
}
_ => bail!("Unsupported VM configuration for network: {}", N::ID),
}
}};
}
#[macro_export]
macro_rules! process {
($self:ident, $logic:ident) => {{
match N::ID {
console::network::MainnetV0::ID => {
let process = (&$self.process as &dyn std::any::Any)
.downcast_ref::<Arc<RwLock<Process<console::network::MainnetV0>>>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($self.process)))?;
$logic!(process.read(), console::network::MainnetV0, circuit::AleoV0)
}
console::network::TestnetV0::ID => {
let process = (&$self.process as &dyn std::any::Any)
.downcast_ref::<Arc<RwLock<Process<console::network::TestnetV0>>>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($self.process)))?;
$logic!(process.read(), console::network::TestnetV0, circuit::AleoTestnetV0)
}
console::network::CanaryV0::ID => {
let process = (&$self.process as &dyn std::any::Any)
.downcast_ref::<Arc<RwLock<Process<console::network::CanaryV0>>>>()
.ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($self.process)))?;
$logic!(process.read(), console::network::CanaryV0, circuit::AleoCanaryV0)
}
_ => bail!("Unsupported VM configuration for network: {}", N::ID),
}
}};
}