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 = "v8")]
13 V8(crate::backend::v8::store::StoreObjects),
15
16 #[cfg(feature = "js")]
17 Js(crate::backend::js::store::StoreObjects),
19}
20
21impl StoreObjects {
22 #[inline]
25 pub fn same(a: &Self, b: &Self) -> bool {
26 match (a, b) {
27 #[cfg(feature = "sys")]
28 (Self::Sys(a), Self::Sys(b)) => a.id() == b.id(),
29 #[cfg(feature = "v8")]
30 (Self::V8(a), Self::V8(b)) => a.id() == b.id(),
31 #[cfg(feature = "js")]
32 (Self::Js(a), Self::Js(b)) => a.id() == b.id(),
33
34 _ => panic!(
35 "Incompatible `StoreObjects` instance: {}, {}!",
36 a.id(),
37 b.id()
38 ),
39 }
40 }
41
42 #[inline]
44 pub fn id(&self) -> StoreId {
45 match_rt!(on self => s {
46 s.id()
47 })
48 }
49
50 #[inline]
51 pub(crate) fn from_store_ref(store: &BackendStore) -> Self {
52 match store {
53 #[cfg(feature = "sys")]
54 BackendStore::Sys(_) => Self::Sys(Default::default()),
55 #[cfg(feature = "v8")]
56 BackendStore::V8(_) => Self::V8(Default::default()),
57 #[cfg(feature = "js")]
58 BackendStore::Js(_) => Self::Js(Default::default()),
59 }
60 }
61
62 #[inline]
64 pub fn as_u128_globals(&self) -> Vec<u128> {
65 match_rt!(on self => s {
66 s.as_u128_globals()
67 })
68 }
69
70 #[inline]
74 pub fn set_global_unchecked(&self, idx: usize, val: u128) {
75 match_rt!(on self => s {
76 s.set_global_unchecked(idx, val)
77 })
78 }
79
80 #[cfg(all(unix, feature = "experimental-host-interrupt"))]
81 pub fn interrupter(&self) -> Interrupter {
83 match self {
84 #[cfg(feature = "sys")]
85 Self::Sys(s) => Interrupter(InterrupterInner::Sys(
86 crate::backend::sys::store::Interrupter::new(s.id()),
87 )),
88 _ => panic!("Interrupters can only be built for stores from the sys backend"),
89 }
90 }
91}
92
93#[cfg(all(unix, feature = "experimental-host-interrupt"))]
95#[derive(Clone)]
96pub struct Interrupter(InterrupterInner);
97
98#[cfg(all(unix, feature = "experimental-host-interrupt"))]
99impl Interrupter {
100 pub fn interrupt(&self) {
102 self.0.interrupt()
103 }
104}
105
106#[cfg(all(unix, feature = "experimental-host-interrupt"))]
108#[derive(Clone)]
109pub enum InterrupterInner {
110 #[cfg(feature = "sys")]
111 Sys(crate::backend::sys::store::Interrupter),
113}
114
115#[cfg(all(unix, feature = "experimental-host-interrupt"))]
116impl InterrupterInner {
117 pub fn interrupt(&self) {
119 match self {
120 #[cfg(feature = "sys")]
121 Self::Sys(i) => i.interrupt(),
122 }
123 }
124}