1use crate::{
2 wasm_extern_t,
3 wasm_foreign_t,
4 wasm_func_t,
5 wasm_global_t,
6 wasm_instance_t,
7 wasm_memory_t,
8 wasm_module_t,
9 wasm_table_t,
10 wasm_trap_t,
11};
12use alloc::boxed::Box;
13use core::{ffi::c_void, ptr, unimplemented};
14use wasmi::{ExternRef, Func, Ref, Val};
15
16#[derive(Clone)]
29pub struct wasm_ref_t {
30 pub(crate) inner: WasmRef,
31}
32
33wasmi_c_api_macros::declare_own!(wasm_ref_t);
34
35#[derive(Clone)]
36pub(crate) enum WasmRef {
37 Func(Ref<Func>),
38 Extern(Ref<ExternRef>),
39}
40
41impl From<WasmRef> for Val {
42 fn from(value: WasmRef) -> Self {
43 match value {
44 WasmRef::Func(r) => Self::FuncRef(r),
45 WasmRef::Extern(r) => Self::ExternRef(r),
46 }
47 }
48}
49
50impl WasmRef {
51 pub fn is_func(&self) -> bool {
53 matches!(self, Self::Func(_))
54 }
55
56 pub fn is_null(&self) -> bool {
58 match self {
59 WasmRef::Func(r) => r.is_null(),
60 WasmRef::Extern(r) => r.is_null(),
61 }
62 }
63}
64
65impl wasm_ref_t {
66 pub(crate) fn new(r: WasmRef) -> Option<Box<wasm_ref_t>> {
68 if r.is_null() || !r.is_func() {
69 None
70 } else {
71 Some(Box::new(wasm_ref_t { inner: r }))
72 }
73 }
74}
75
76pub(crate) fn ref_to_val(r: &wasm_ref_t) -> Val {
82 match r.inner {
83 WasmRef::Func(r) => Val::FuncRef(r),
84 WasmRef::Extern(r) => Val::ExternRef(r),
85 }
86}
87
88#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
92#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
93pub extern "C" fn wasm_ref_copy(r: Option<&wasm_ref_t>) -> Option<Box<wasm_ref_t>> {
94 r.map(|r| Box::new(r.clone()))
95}
96
97#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
103#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
104pub extern "C" fn wasm_ref_same(_a: Option<&wasm_ref_t>, _b: Option<&wasm_ref_t>) -> bool {
105 unimplemented!("wasm_ref_same")
108}
109
110#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
116#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
117pub extern "C" fn wasm_ref_get_host_info(_ref: Option<&wasm_ref_t>) -> *mut c_void {
118 ptr::null_mut()
119}
120
121#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
127#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
128pub extern "C" fn wasm_ref_set_host_info(_ref: Option<&wasm_ref_t>, _info: *mut c_void) {
129 unimplemented!("wasm_ref_set_host_info")
130}
131
132#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
140#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
141pub extern "C" fn wasm_ref_set_host_info_with_finalizer(
142 _ref: Option<&wasm_ref_t>,
143 _info: *mut c_void,
144 _finalizer: Option<extern "C" fn(*mut c_void)>,
145) {
146 unimplemented!("wasm_ref_set_host_info_with_finalizer")
147}
148
149#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
155#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
156pub extern "C" fn wasm_ref_as_extern(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_extern_t> {
157 unimplemented!("wasm_ref_as_extern")
158}
159
160#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
166#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
167pub extern "C" fn wasm_ref_as_extern_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_extern_t> {
168 unimplemented!("wasm_ref_as_extern_const")
169}
170
171#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
177#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
178pub extern "C" fn wasm_ref_as_foreign(
179 _ref: Option<&mut wasm_ref_t>,
180) -> Option<&mut wasm_foreign_t> {
181 unimplemented!("wasm_ref_as_foreign")
182}
183
184#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
190#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
191pub extern "C" fn wasm_ref_as_foreign_const(
192 _ref: Option<&wasm_ref_t>,
193) -> Option<&crate::wasm_foreign_t> {
194 unimplemented!("wasm_ref_as_foreign_const")
195}
196
197#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
203#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
204pub extern "C" fn wasm_ref_as_func(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_func_t> {
205 unimplemented!("wasm_ref_as_func")
206}
207
208#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
214#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
215pub extern "C" fn wasm_ref_as_func_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_func_t> {
216 unimplemented!("wasm_ref_as_func_const")
217}
218
219#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
225#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
226pub extern "C" fn wasm_ref_as_global(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_global_t> {
227 unimplemented!("wasm_ref_as_global")
228}
229
230#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
236#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
237pub extern "C" fn wasm_ref_as_global_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_global_t> {
238 unimplemented!("wasm_ref_as_global_const")
239}
240
241#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
247#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
248pub extern "C" fn wasm_ref_as_instance(
249 _ref: Option<&mut wasm_ref_t>,
250) -> Option<&mut wasm_instance_t> {
251 unimplemented!("wasm_ref_as_instance")
252}
253
254#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
260#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
261pub extern "C" fn wasm_ref_as_instance_const(
262 _ref: Option<&wasm_ref_t>,
263) -> Option<&wasm_instance_t> {
264 unimplemented!("wasm_ref_as_instance_const")
265}
266
267#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
273#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
274pub extern "C" fn wasm_ref_as_memory(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_memory_t> {
275 unimplemented!("wasm_ref_as_memory")
276}
277
278#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
284#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
285pub extern "C" fn wasm_ref_as_memory_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_memory_t> {
286 unimplemented!("wasm_ref_as_memory_const")
287}
288
289#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
295#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
296pub extern "C" fn wasm_ref_as_module(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_module_t> {
297 unimplemented!("wasm_ref_as_module")
298}
299
300#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
306#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
307pub extern "C" fn wasm_ref_as_module_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_module_t> {
308 unimplemented!("wasm_ref_as_module_const")
309}
310
311#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
317#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
318pub extern "C" fn wasm_ref_as_table(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_table_t> {
319 unimplemented!("wasm_ref_as_table")
320}
321
322#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
328#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
329pub extern "C" fn wasm_ref_as_table_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_table_t> {
330 unimplemented!("wasm_ref_as_table_const")
331}
332
333#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
339#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
340pub extern "C" fn wasm_ref_as_trap(_ref: Option<&mut wasm_ref_t>) -> Option<&mut wasm_trap_t> {
341 unimplemented!("wasm_ref_as_trap")
342}
343
344#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
350#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
351pub extern "C" fn wasm_ref_as_trap_const(_ref: Option<&wasm_ref_t>) -> Option<&wasm_trap_t> {
352 unimplemented!("wasm_ref_as_trap_const")
353}