wasmer/entities/store/
obj.rs1use wasmer_types::StoreId;
2
3use crate::{BackendStore, macros::backend::match_rt};
4
5#[derive(Debug)]
7pub enum StoreObjects {
8 #[cfg(feature = "sys")]
9 Sys(crate::backend::sys::store::StoreObjects),
11
12 #[cfg(feature = "wamr")]
13 Wamr(crate::backend::wamr::store::StoreObjects),
15
16 #[cfg(feature = "wasmi")]
17 Wasmi(crate::backend::wasmi::store::StoreObjects),
19
20 #[cfg(feature = "v8")]
21 V8(crate::backend::v8::store::StoreObjects),
23
24 #[cfg(feature = "js")]
25 Js(crate::backend::js::store::StoreObjects),
27
28 #[cfg(feature = "jsc")]
29 Jsc(crate::backend::jsc::store::StoreObjects),
31}
32
33impl StoreObjects {
34 #[inline]
37 pub fn same(a: &Self, b: &Self) -> bool {
38 match (a, b) {
39 #[cfg(feature = "sys")]
40 (Self::Sys(a), Self::Sys(b)) => a.id() == b.id(),
41 #[cfg(feature = "wamr")]
42 (Self::Wamr(a), Self::Wamr(b)) => a.id() == b.id(),
43 #[cfg(feature = "v8")]
44 (Self::V8(a), Self::V8(b)) => a.id() == b.id(),
45 #[cfg(feature = "js")]
46 (Self::Js(a), Self::Js(b)) => a.id() == b.id(),
47
48 #[cfg(feature = "jsc")]
49 (Self::Jsc(a), Self::Jsc(b)) => a.id() == b.id(),
50
51 _ => panic!(
52 "Incompatible `StoreObjects` instance: {}, {}!",
53 a.id(),
54 b.id()
55 ),
56 }
57 }
58
59 #[inline]
61 pub fn id(&self) -> StoreId {
62 match_rt!(on self => s {
63 s.id()
64 })
65 }
66
67 #[inline]
68 pub(crate) fn from_store_ref(store: &BackendStore) -> Self {
69 match store {
70 #[cfg(feature = "sys")]
71 BackendStore::Sys(_) => Self::Sys(Default::default()),
72 #[cfg(feature = "wamr")]
73 BackendStore::Wamr(_) => Self::Wamr(Default::default()),
74 #[cfg(feature = "wasmi")]
75 BackendStore::Wasmi(_) => Self::Wasmi(Default::default()),
76 #[cfg(feature = "v8")]
77 BackendStore::V8(_) => Self::V8(Default::default()),
78 #[cfg(feature = "js")]
79 BackendStore::Js(_) => Self::Js(Default::default()),
80 #[cfg(feature = "jsc")]
81 BackendStore::Jsc(_) => Self::Jsc(Default::default()),
82 }
83 }
84
85 #[inline]
87 pub fn as_u128_globals(&self) -> Vec<u128> {
88 match_rt!(on self => s {
89 s.as_u128_globals()
90 })
91 }
92
93 #[inline]
97 pub fn set_global_unchecked(&self, idx: usize, val: u128) {
98 match_rt!(on self => s {
99 s.set_global_unchecked(idx, val)
100 })
101 }
102}