mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
feat(api) Rewrite the wasm_extern_type macro to avoid repetition.
This commit is contained in:
50
lib/api/src/externals/function.rs
vendored
50
lib/api/src/externals/function.rs
vendored
@@ -501,34 +501,38 @@ mod inner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wasm_extern_type {
|
macro_rules! wasm_extern_type {
|
||||||
($type:ty => $native_type:ty) => {
|
( $( $type:ty => $native_type:ty ),* ) => {
|
||||||
#[allow(clippy::use_self)]
|
$(
|
||||||
unsafe impl WasmExternType for $type {
|
#[allow(clippy::use_self)]
|
||||||
type Native = $native_type;
|
unsafe impl WasmExternType for $type {
|
||||||
|
type Native = $native_type;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_native(native: Self::Native) -> Self {
|
fn from_native(native: Self::Native) -> Self {
|
||||||
native as _
|
native as _
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_native(self) -> Self::Native {
|
fn to_native(self) -> Self::Native {
|
||||||
self as _
|
self as _
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)*
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_extern_type!(i8 => i32);
|
wasm_extern_type!(
|
||||||
wasm_extern_type!(u8 => i32);
|
i8 => i32,
|
||||||
wasm_extern_type!(i16 => i32);
|
u8 => i32,
|
||||||
wasm_extern_type!(u16 => i32);
|
i16 => i32,
|
||||||
wasm_extern_type!(i32 => i32);
|
u16 => i32,
|
||||||
wasm_extern_type!(u32 => i32);
|
i32 => i32,
|
||||||
wasm_extern_type!(i64 => i64);
|
u32 => i32,
|
||||||
wasm_extern_type!(u64 => i64);
|
i64 => i64,
|
||||||
wasm_extern_type!(f32 => f32);
|
u64 => i64,
|
||||||
wasm_extern_type!(f64 => f64);
|
f32 => f32,
|
||||||
|
f64 => f64
|
||||||
|
);
|
||||||
|
|
||||||
/// Represents a list of WebAssembly values.
|
/// Represents a list of WebAssembly values.
|
||||||
pub trait WasmTypeList {
|
pub trait WasmTypeList {
|
||||||
@@ -918,7 +922,7 @@ mod inner {
|
|||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_func {
|
mod test_function {
|
||||||
use super::*;
|
use super::*;
|
||||||
use wasm_common::Type;
|
use wasm_common::Type;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user