From d6cd1fa6c44abe0b372fd01f113aeb92713509e8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 17 Feb 2020 14:48:58 +0100 Subject: [PATCH 1/3] doc(interface-types) Add a `README.md` file. --- lib/interface-types/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/interface-types/README.md 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 logo + +

+ +

+ + Build Status + + + License + + + Join the Wasmer Community + + + Number of downloads from crates.io + + + Read our API documentation + +

+ +# 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). From 9088f6b9e2a91bd7615b1fd841fae52a0a3f7256 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 21 Nov 2019 15:16:30 +0100 Subject: [PATCH 2/3] feat(runtime-core) Simplify `WasmExternType` implementations with macros. --- lib/runtime-core/src/types.rs | 129 +++++++++++----------------------- 1 file changed, 40 insertions(+), 89 deletions(-) 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 From ff154999f396277debadf9097a08b1b70e054087 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 17 Feb 2020 15:20:21 +0100 Subject: [PATCH 3/3] fix(runtime-core) Remove warnings. Because we can use the `impl_traits!` macro with only one identifier, a warning is emitted saying the parenthesis are useless for this specific usecase. They are required for all the other usecases though. We can safely ignore this warning. --- lib/runtime-core/src/typed_func.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 513ede7fb..f30f6998c 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -310,6 +310,7 @@ macro_rules! impl_traits { where $( $x: WasmExternType ),*; + #[allow(unused_parens)] impl< $( $x ),* > WasmTypeList for ( $( $x ),* ) where $( $x: WasmExternType ),* @@ -380,6 +381,7 @@ macro_rules! impl_traits { } } + #[allow(unused_parens)] impl< $( $x, )* Rets, Trap, FN > ExternalFunction for FN where $( $x: WasmExternType, )* @@ -495,6 +497,7 @@ macro_rules! impl_traits { } } + #[allow(unused_parens)] impl< $( $x, )* Rets, Trap, FN > ExternalFunction for FN where $( $x: WasmExternType, )* @@ -607,6 +610,7 @@ macro_rules! impl_traits { } } + #[allow(unused_parens)] impl<'a $( , $x )*, Rets> Func<'a, ( $( $x ),* ), Rets, Wasm> where $( $x: WasmExternType, )*