use wasmer_types::{NativeWasmType, Type};
use crate::js::Function;
use super::store::AsStoreMut;
pub trait NativeWasmTypeInto: NativeWasmType + Sized {
#[doc(hidden)]
fn into_abi(self, store: &mut impl AsStoreMut) -> Self::Abi;
#[doc(hidden)]
unsafe fn from_abi(store: &mut impl AsStoreMut, abi: Self::Abi) -> Self;
fn into_raw(self, store: &mut impl AsStoreMut) -> f64;
unsafe fn from_raw(store: &mut impl AsStoreMut, raw: f64) -> Self;
}
impl NativeWasmTypeInto for i32 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}
#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}
#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
self.into()
}
#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
raw as _
}
}
impl NativeWasmTypeInto for i64 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}
#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}
#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
self as _
}
#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
raw as _
}
}
impl NativeWasmTypeInto for f32 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}
#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}
#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
self as _
}
#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
raw as _
}
}
impl NativeWasmTypeInto for f64 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}
#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}
#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
self
}
#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
raw
}
}
impl NativeWasmTypeInto for u128 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}
#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}
#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
self as _
}
#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
raw as _
}
}
impl NativeWasmType for Function {
const WASM_TYPE: Type = Type::FuncRef;
type Abi = f64;
}