From d1429fb18b48dbcd537f5a24baf306fd9202d95c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 4 Jun 2020 16:41:57 -0700 Subject: [PATCH] Fix up macro issue --- lib/api/src/lib.rs | 1 - lib/api/src/native.rs | 77 ++++--------------------- lib/wasm-common/src/lib.rs | 1 - lib/wasm-common/src/native.rs | 104 ---------------------------------- 4 files changed, 12 insertions(+), 171 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 46601340d..fa0bb3eeb 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -1,5 +1,4 @@ //! Wasmer API -#![feature(trace_macros)] #![deny(intra_doc_link_resolution_failure)] mod exports; diff --git a/lib/api/src/native.rs b/lib/api/src/native.rs index e2e37fc39..2fa2abc24 100644 --- a/lib/api/src/native.rs +++ b/lib/api/src/native.rs @@ -1,13 +1,7 @@ // Native Funcs // use wasmer_runtime::ExportFunction; use std::marker::PhantomData; -use wasm_common::{WasmExternType, WasmTypeList}; -// pub trait NativeHostFunction -// where -// Args: WasmTypeList, -// Rets: WasmTypeList, -// { -// } +use wasm_common::{Func, WasmExternType, WasmTypeList}; #[derive(Clone)] pub struct UnprovidedArgs; @@ -30,85 +24,38 @@ impl<'a, Args, Rets> NativeFunc<'a, Args, Rets> { } } -// #[allow (unused_parens)] -// impl <'a, A1, Rets > NativeFunc <'a, (A1,), Rets > -// where -// A1 : WasmExternType, -// Rets : WasmTypeList, -// { -// /// Call the typed func and return results. -// pub fn calla(&self, A1:A1,) -> Result { -// unimplemented!(""); -// } -// } +/*impl<'a, Args, Rets> From> for Func +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + fn from(other: NativeFunc<'a, Args, Rets>) -> Func { + Func { -// #[allow (unused_parens)] -// impl <'a, A1, A2, Rets > NativeFunc <'a, (A1, A2), Rets > -// where -// A1 : WasmExternType, -// A2 : WasmExternType, -// Rets : WasmTypeList, -// { -// /// Call the typed func and return results. -// pub fn calla(&self, A1:A1, A2: A2,) -> Result { -// unimplemented!(""); -// } -// } + } + } +}*/ macro_rules! impl_native_traits { ( $( $x:ident ),* ) => { #[allow(unused_parens)] - impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x ),* ), Rets> + impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x, )* ), Rets> where $( $x: WasmExternType, )* Rets: WasmTypeList, { /// Call the typed func and return results. pub fn call(&self, $( $x: $x, )* ) -> Result { - trace_macros!(false); unimplemented!(""); - trace_macros!(true); } } - // impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x ),* ), Rets> - // where - // $( $x: WasmExternType, )* - // Rets: WasmTypeList, - // { - // /// Call the typed func and return results. - // #[allow(non_snake_case, clippy::too_many_arguments)] - // pub fn call(&self, $( $x: $x, )* ) -> Result { - // unimplemented!(""); - // // use std::mem; - // // use std::cell::RefCell; - // // let vmctx = self.exported.vmctx; - // // let callee_address = self.exported.address; - // // #[allow(unused_parens)] - // // unsafe { - // // let result: RefCell> = RefCell::new(None); - // // catch_traps(vmctx, || { - // // let func_result = mem::transmute::< - // // *const VMFunctionBody, - // // unsafe extern "C" fn(*mut VMContext, *mut VMContext, $( $x ),* ) -> Rets::CStruct, - // // >(callee_address)(vmctx, std::ptr::null_mut() as *mut VMContext, $( $x ),* ); - - // // *result.borrow_mut() = Some(func_result); - // // }); - // // Ok(result.into_inner().unwrap()) - // // } - // } - // } }; } -trace_macros!(true); - // impl_native_traits!(); impl_native_traits!(A1); impl_native_traits!(A1, A2); -trace_macros!(false); - // impl_native_traits!(A1, A2, A3); diff --git a/lib/wasm-common/src/lib.rs b/lib/wasm-common/src/lib.rs index 8ff6ec90e..3c9b79354 100644 --- a/lib/wasm-common/src/lib.rs +++ b/lib/wasm-common/src/lib.rs @@ -4,7 +4,6 @@ //! This crate provides common structures such as `Type` or `Value`, type indexes //! and native function wrappers with `Func`. -#![feature(trace_macros)] #![deny(missing_docs, unused_extern_crates)] #![warn(unused_import_braces)] #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] diff --git a/lib/wasm-common/src/native.rs b/lib/wasm-common/src/native.rs index be668853e..325057033 100644 --- a/lib/wasm-common/src/native.rs +++ b/lib/wasm-common/src/native.rs @@ -705,107 +705,3 @@ mod test_func { // assert_eq!(result.is_err(), true); } } - -#[derive(Clone)] -pub struct UnprovidedArgs; -#[derive(Clone)] -pub struct UnprovidedRets; - -pub struct NativeFunc<'a, Args = UnprovidedArgs, Rets = UnprovidedRets> { - // exported: ExportFunction, - _phantom: PhantomData<(&'a (), Args, Rets)>, -} - -unsafe impl<'a, Args, Rets> Send for NativeFunc<'a, Args, Rets> {} - -impl<'a, Args, Rets> NativeFunc<'a, Args, Rets> { - fn from_export() -> Self { - Self { - // exported, - _phantom: PhantomData, - } - } -} - -// #[allow (unused_parens)] -// impl <'a, A1, Rets > NativeFunc <'a, (A1,), Rets > -// where -// A1 : WasmExternType, -// Rets : WasmTypeList, -// { -// /// Call the typed func and return results. -// pub fn calla(&self, A1:A1,) -> Result { -// unimplemented!(""); -// } -// } - -// #[allow (unused_parens)] -// impl <'a, A1, A2, Rets > NativeFunc <'a, (A1, A2), Rets > -// where -// A1 : WasmExternType, -// A2 : WasmExternType, -// Rets : WasmTypeList, -// { -// /// Call the typed func and return results. -// pub fn calla(&self, A1:A1, A2: A2,) -> Result { -// unimplemented!(""); -// } -// } - -macro_rules! impl_native_traits { - ( $( $x:ident ),* ) => { - #[allow(unused_parens)] - impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x ),* ), Rets> - where - $( $x: WasmExternType, )* - Rets: WasmTypeList, - { - /// Call the typed func and return results. - pub fn call(&self, $( $x: $x, )* ) -> Result { - trace_macros!(false); - unimplemented!(""); - trace_macros!(true); - } - } - // impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x ),* ), Rets> - // where - // $( $x: WasmExternType, )* - // Rets: WasmTypeList, - // { - // /// Call the typed func and return results. - // #[allow(non_snake_case, clippy::too_many_arguments)] - // pub fn call(&self, $( $x: $x, )* ) -> Result { - // unimplemented!(""); - // // use std::mem; - // // use std::cell::RefCell; - // // let vmctx = self.exported.vmctx; - // // let callee_address = self.exported.address; - // // #[allow(unused_parens)] - // // unsafe { - // // let result: RefCell> = RefCell::new(None); - // // catch_traps(vmctx, || { - // // let func_result = mem::transmute::< - // // *const VMFunctionBody, - // // unsafe extern "C" fn(*mut VMContext, *mut VMContext, $( $x ),* ) -> Rets::CStruct, - // // >(callee_address)(vmctx, std::ptr::null_mut() as *mut VMContext, $( $x ),* ); - - // // *result.borrow_mut() = Some(func_result); - // // }); - // // Ok(result.into_inner().unwrap()) - // // } - // } - // } - - - }; -} - -trace_macros!(true); - -// impl_native_traits!(); -impl_native_traits!(A1); -impl_native_traits!(A1, A2); - -trace_macros!(false); - -// impl_native_traits!(A1, A2, A3);