Merge branch 'master' into feat-runtime-core-cleanup-typed-func

This commit is contained in:
Syrus Akbary
2020-02-17 13:00:13 -08:00
committed by GitHub
3 changed files with 76 additions and 89 deletions

View File

@ -0,0 +1,32 @@
<p align="center">
<a href="https://wasmer.io" target="_blank" rel="noopener noreferrer">
<img width="300" src="https://raw.githubusercontent.com/wasmerio/wasmer/master/logo.png" alt="Wasmer logo">
</a>
</p>
<p align="center">
<a href="https://dev.azure.com/wasmerio/wasmer/_build/latest?definitionId=3&branchName=master">
<img src="https://img.shields.io/azure-devops/build/wasmerio/wasmer/3.svg?style=flat-square" alt="Build Status">
</a>
<a href="https://github.com/wasmerio/wasmer/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square" alt="License">
</a>
<a href="https://spectrum.chat/wasmer">
<img src="https://withspectrum.github.io/badge/badge.svg" alt="Join the Wasmer Community">
</a>
<a href="https://crates.io/crates/wasmer-interface-types">
<img src="https://img.shields.io/crates/d/wasmer-interface-types.svg?style=flat-square" alt="Number of downloads from crates.io">
</a>
<a href="https://docs.rs/wasmer-interface-types">
<img src="https://docs.rs/wasmer-interface-types/badge.svg" alt="Read our API documentation">
</a>
</p>
# 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).

View File

@ -314,6 +314,7 @@ macro_rules! impl_traits {
where where
$( $x: WasmExternType ),*; $( $x: WasmExternType ),*;
#[allow(unused_parens)]
impl< $( $x ),* > WasmTypeList for ( $( $x ),* ) impl< $( $x ),* > WasmTypeList for ( $( $x ),* )
where where
$( $x: WasmExternType ),* $( $x: WasmExternType ),*
@ -384,6 +385,7 @@ macro_rules! impl_traits {
} }
} }
#[allow(unused_parens)]
impl< $( $x, )* Rets, Trap, FN > HostFunction<ExplicitVmCtx, ( $( $x ),* ), Rets> for FN impl< $( $x, )* Rets, Trap, FN > HostFunction<ExplicitVmCtx, ( $( $x ),* ), Rets> for FN
where where
$( $x: WasmExternType, )* $( $x: WasmExternType, )*
@ -499,6 +501,7 @@ macro_rules! impl_traits {
} }
} }
#[allow(unused_parens)]
impl< $( $x, )* Rets, Trap, FN > HostFunction<ImplicitVmCtx, ( $( $x ),* ), Rets> for FN impl< $( $x, )* Rets, Trap, FN > HostFunction<ImplicitVmCtx, ( $( $x ),* ), Rets> for FN
where where
$( $x: WasmExternType, )* $( $x: WasmExternType, )*
@ -611,6 +614,7 @@ macro_rules! impl_traits {
} }
} }
#[allow(unused_parens)]
impl<'a $( , $x )*, Rets> Func<'a, ( $( $x ),* ), Rets, Wasm> impl<'a $( , $x )*, Rets> Func<'a, ( $( $x ),* ), Rets, Wasm>
where where
$( $x: WasmExternType, )* $( $x: WasmExternType, )*

View File

@ -104,44 +104,57 @@ where
{ {
/// Type for this `NativeWasmType`. /// Type for this `NativeWasmType`.
const TYPE: Type; const TYPE: Type;
/// Convert from u64 bites to self. /// Convert from u64 bites to self.
fn from_binary(bits: u64) -> Self; fn from_binary(bits: u64) -> Self;
/// Convert self to u64 binary representation. /// Convert self to u64 binary representation.
fn to_binary(self) -> u64; fn to_binary(self) -> u64;
} }
unsafe impl NativeWasmType for i32 { unsafe impl NativeWasmType for i32 {
const TYPE: Type = Type::I32; const TYPE: Type = Type::I32;
fn from_binary(bits: u64) -> Self { fn from_binary(bits: u64) -> Self {
bits as _ bits as _
} }
fn to_binary(self) -> u64 { fn to_binary(self) -> u64 {
self as _ self as _
} }
} }
unsafe impl NativeWasmType for i64 { unsafe impl NativeWasmType for i64 {
const TYPE: Type = Type::I64; const TYPE: Type = Type::I64;
fn from_binary(bits: u64) -> Self { fn from_binary(bits: u64) -> Self {
bits as _ bits as _
} }
fn to_binary(self) -> u64 { fn to_binary(self) -> u64 {
self as _ self as _
} }
} }
unsafe impl NativeWasmType for f32 { unsafe impl NativeWasmType for f32 {
const TYPE: Type = Type::F32; const TYPE: Type = Type::F32;
fn from_binary(bits: u64) -> Self { fn from_binary(bits: u64) -> Self {
f32::from_bits(bits as u32) f32::from_bits(bits as u32)
} }
fn to_binary(self) -> u64 { fn to_binary(self) -> u64 {
self.to_bits() as _ self.to_bits() as _
} }
} }
unsafe impl NativeWasmType for f64 { unsafe impl NativeWasmType for f64 {
const TYPE: Type = Type::F64; const TYPE: Type = Type::F64;
fn from_binary(bits: u64) -> Self { fn from_binary(bits: u64) -> Self {
f64::from_bits(bits) f64::from_bits(bits)
} }
fn to_binary(self) -> u64 { fn to_binary(self) -> u64 {
self.to_bits() self.to_bits()
} }
@ -154,103 +167,41 @@ where
{ {
/// Native wasm type for this `WasmExternType`. /// Native wasm type for this `WasmExternType`.
type Native: NativeWasmType; type Native: NativeWasmType;
/// Convert from given `Native` type to self. /// Convert from given `Native` type to self.
fn from_native(native: Self::Native) -> Self; fn from_native(native: Self::Native) -> Self;
/// Convert self to `Native` type. /// Convert self to `Native` type.
fn to_native(self) -> Self::Native; fn to_native(self) -> Self::Native;
} }
unsafe impl WasmExternType for i8 { macro_rules! wasm_extern_type {
type Native = i32; ($type:ty => $native_type:ty) => {
fn from_native(native: Self::Native) -> Self { unsafe impl WasmExternType for $type {
native as _ type Native = $native_type;
}
fn to_native(self) -> Self::Native { fn from_native(native: Self::Native) -> Self {
self as _ native as _
} }
}
unsafe impl WasmExternType for u8 { fn to_native(self) -> Self::Native {
type Native = i32; self as _
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
}
} }
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 // pub trait IntegerAtomic
// where // where
// Self: Sized // Self: Sized