use wasmer_types::StoreId;
use crate::{macros::backend::match_rt, BackendStore};
#[derive(Debug)]
pub enum StoreObjects {
#[cfg(feature = "sys")]
Sys(crate::backend::sys::store::StoreObjects),
#[cfg(feature = "wamr")]
Wamr(crate::backend::wamr::store::StoreObjects),
#[cfg(feature = "wasmi")]
Wasmi(crate::backend::wasmi::store::StoreObjects),
#[cfg(feature = "v8")]
V8(crate::backend::v8::store::StoreObjects),
#[cfg(feature = "js")]
Js(crate::backend::js::store::StoreObjects),
#[cfg(feature = "jsc")]
Jsc(crate::backend::jsc::store::StoreObjects),
}
impl StoreObjects {
#[inline]
pub fn same(a: &Self, b: &Self) -> bool {
match (a, b) {
#[cfg(feature = "sys")]
(Self::Sys(ref a), Self::Sys(ref b)) => a.id() == b.id(),
#[cfg(feature = "wamr")]
(Self::Wamr(ref a), Self::Wamr(ref b)) => a.id() == b.id(),
#[cfg(feature = "v8")]
(Self::V8(ref a), Self::V8(ref b)) => a.id() == b.id(),
#[cfg(feature = "js")]
(Self::Js(ref a), Self::Js(ref b)) => a.id() == b.id(),
#[cfg(feature = "jsc")]
(Self::Jsc(ref a), Self::Jsc(ref b)) => a.id() == b.id(),
_ => panic!(
"Incompatible `StoreObjects` instance: {}, {}!",
a.id(),
b.id()
),
}
}
#[inline]
pub fn id(&self) -> StoreId {
match_rt!(on self => s {
s.id()
})
}
#[inline]
pub(crate) fn from_store_ref(store: &BackendStore) -> Self {
match store {
#[cfg(feature = "sys")]
BackendStore::Sys(_) => Self::Sys(Default::default()),
#[cfg(feature = "wamr")]
BackendStore::Wamr(_) => Self::Wamr(Default::default()),
#[cfg(feature = "wasmi")]
BackendStore::Wasmi(_) => Self::Wasmi(Default::default()),
#[cfg(feature = "v8")]
BackendStore::V8(_) => Self::V8(Default::default()),
#[cfg(feature = "js")]
BackendStore::Js(_) => Self::Js(Default::default()),
#[cfg(feature = "jsc")]
BackendStore::Jsc(_) => Self::Jsc(Default::default()),
}
}
#[inline]
pub fn as_u128_globals(&self) -> Vec<u128> {
match_rt!(on self => s {
s.as_u128_globals()
})
}
#[inline]
pub fn set_global_unchecked(&self, idx: usize, val: u128) {
match_rt!(on self => s {
s.set_global_unchecked(idx, val)
})
}
}