1use crate::{
2 wasm_externkind_t,
3 wasm_externtype_t,
4 wasm_func_t,
5 wasm_global_t,
6 wasm_memory_t,
7 wasm_table_t,
8 WasmStoreRef,
9};
10use alloc::boxed::Box;
11use wasmi::Extern;
12
13#[derive(Clone)]
17pub struct wasm_extern_t {
18 pub(crate) store: WasmStoreRef,
19 pub(crate) which: Extern,
20}
21
22wasmi_c_api_macros::declare_ref!(wasm_extern_t);
23
24#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
26#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
27pub extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
28 match e.which {
29 Extern::Func(_) => wasm_externkind_t::WASM_EXTERN_FUNC,
30 Extern::Global(_) => wasm_externkind_t::WASM_EXTERN_GLOBAL,
31 Extern::Table(_) => wasm_externkind_t::WASM_EXTERN_TABLE,
32 Extern::Memory(_) => wasm_externkind_t::WASM_EXTERN_MEMORY,
33 }
34}
35
36#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
43#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
44pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externtype_t> {
45 Box::new(wasm_externtype_t::from_extern_type(
46 e.which.ty(e.store.context()),
47 ))
48}
49
50#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
54#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
55pub extern "C" fn wasm_extern_as_func(e: &mut wasm_extern_t) -> Option<&mut wasm_func_t> {
56 wasm_func_t::try_from_mut(e)
57}
58
59#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
63#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
64pub extern "C" fn wasm_extern_as_func_const(e: &wasm_extern_t) -> Option<&wasm_func_t> {
65 wasm_func_t::try_from(e)
66}
67
68#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
72#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
73pub extern "C" fn wasm_extern_as_global(e: &mut wasm_extern_t) -> Option<&mut wasm_global_t> {
74 wasm_global_t::try_from_mut(e)
75}
76
77#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
81#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
82pub extern "C" fn wasm_extern_as_global_const(e: &wasm_extern_t) -> Option<&wasm_global_t> {
83 wasm_global_t::try_from(e)
84}
85
86#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
90#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
91pub extern "C" fn wasm_extern_as_table(e: &mut wasm_extern_t) -> Option<&mut wasm_table_t> {
92 wasm_table_t::try_from_mut(e)
93}
94
95#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
99#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
100pub extern "C" fn wasm_extern_as_table_const(e: &wasm_extern_t) -> Option<&wasm_table_t> {
101 wasm_table_t::try_from(e)
102}
103
104#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
108#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
109pub extern "C" fn wasm_extern_as_memory(e: &mut wasm_extern_t) -> Option<&mut wasm_memory_t> {
110 wasm_memory_t::try_from_mut(e)
111}
112
113#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
117#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
118pub extern "C" fn wasm_extern_as_memory_const(e: &wasm_extern_t) -> Option<&wasm_memory_t> {
119 wasm_memory_t::try_from(e)
120}