diff --git a/lib/interface-types/README.md b/lib/interface-types/README.md
new file mode 100644
index 000000000..8dcf3ffc8
--- /dev/null
+++ b/lib/interface-types/README.md
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Wasmer Interface Types
+
+Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully
+compatible with WASI, Emscripten, Rust and Go. [Learn
+more](https://github.com/wasmerio/wasmer).
+
+This crate is an implementation of [the living WebAssembly Interface
+Types standard](https://github.com/WebAssembly/interface-types).
diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs
index 405853a5d..ad4b5078e 100644
--- a/lib/runtime-core/src/typed_func.rs
+++ b/lib/runtime-core/src/typed_func.rs
@@ -314,6 +314,7 @@ macro_rules! impl_traits {
where
$( $x: WasmExternType ),*;
+ #[allow(unused_parens)]
impl< $( $x ),* > WasmTypeList for ( $( $x ),* )
where
$( $x: WasmExternType ),*
@@ -384,6 +385,7 @@ macro_rules! impl_traits {
}
}
+ #[allow(unused_parens)]
impl< $( $x, )* Rets, Trap, FN > HostFunction for FN
where
$( $x: WasmExternType, )*
@@ -499,6 +501,7 @@ macro_rules! impl_traits {
}
}
+ #[allow(unused_parens)]
impl< $( $x, )* Rets, Trap, FN > HostFunction for FN
where
$( $x: WasmExternType, )*
@@ -611,6 +614,7 @@ macro_rules! impl_traits {
}
}
+ #[allow(unused_parens)]
impl<'a $( , $x )*, Rets> Func<'a, ( $( $x ),* ), Rets, Wasm>
where
$( $x: WasmExternType, )*
diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs
index 1b19bbc3d..615964bb0 100644
--- a/lib/runtime-core/src/types.rs
+++ b/lib/runtime-core/src/types.rs
@@ -104,44 +104,57 @@ where
{
/// Type for this `NativeWasmType`.
const TYPE: Type;
+
/// Convert from u64 bites to self.
fn from_binary(bits: u64) -> Self;
+
/// Convert self to u64 binary representation.
fn to_binary(self) -> u64;
}
unsafe impl NativeWasmType for i32 {
const TYPE: Type = Type::I32;
+
fn from_binary(bits: u64) -> Self {
bits as _
}
+
fn to_binary(self) -> u64 {
self as _
}
}
+
unsafe impl NativeWasmType for i64 {
const TYPE: Type = Type::I64;
+
fn from_binary(bits: u64) -> Self {
bits as _
}
+
fn to_binary(self) -> u64 {
self as _
}
}
+
unsafe impl NativeWasmType for f32 {
const TYPE: Type = Type::F32;
+
fn from_binary(bits: u64) -> Self {
f32::from_bits(bits as u32)
}
+
fn to_binary(self) -> u64 {
self.to_bits() as _
}
}
+
unsafe impl NativeWasmType for f64 {
const TYPE: Type = Type::F64;
+
fn from_binary(bits: u64) -> Self {
f64::from_bits(bits)
}
+
fn to_binary(self) -> u64 {
self.to_bits()
}
@@ -154,103 +167,41 @@ where
{
/// Native wasm type for this `WasmExternType`.
type Native: NativeWasmType;
+
/// Convert from given `Native` type to self.
fn from_native(native: Self::Native) -> Self;
+
/// Convert self to `Native` type.
fn to_native(self) -> Self::Native;
}
-unsafe impl WasmExternType for i8 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for u8 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for i16 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for u16 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for i32 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native
- }
- fn to_native(self) -> Self::Native {
- self
- }
-}
-unsafe impl WasmExternType for u32 {
- type Native = i32;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for i64 {
- type Native = i64;
- fn from_native(native: Self::Native) -> Self {
- native
- }
- fn to_native(self) -> Self::Native {
- self
- }
-}
-unsafe impl WasmExternType for u64 {
- type Native = i64;
- fn from_native(native: Self::Native) -> Self {
- native as _
- }
- fn to_native(self) -> Self::Native {
- self as _
- }
-}
-unsafe impl WasmExternType for f32 {
- type Native = f32;
- fn from_native(native: Self::Native) -> Self {
- native
- }
- fn to_native(self) -> Self::Native {
- self
- }
-}
-unsafe impl WasmExternType for f64 {
- type Native = f64;
- fn from_native(native: Self::Native) -> Self {
- native
- }
- fn to_native(self) -> Self::Native {
- self
- }
+macro_rules! wasm_extern_type {
+ ($type:ty => $native_type:ty) => {
+ unsafe impl WasmExternType for $type {
+ type Native = $native_type;
+
+ fn from_native(native: Self::Native) -> Self {
+ native as _
+ }
+
+ fn to_native(self) -> Self::Native {
+ self as _
+ }
+ }
+ };
}
+wasm_extern_type!(i8 => i32);
+wasm_extern_type!(u8 => i32);
+wasm_extern_type!(i16 => i32);
+wasm_extern_type!(u16 => i32);
+wasm_extern_type!(i32 => i32);
+wasm_extern_type!(u32 => i32);
+wasm_extern_type!(i64 => i64);
+wasm_extern_type!(u64 => i64);
+wasm_extern_type!(f32 => f32);
+wasm_extern_type!(f64 => f64);
+
// pub trait IntegerAtomic
// where
// Self: Sized