mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Fix up macro issue
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
//! Wasmer API
|
//! Wasmer API
|
||||||
#![feature(trace_macros)]
|
|
||||||
#![deny(intra_doc_link_resolution_failure)]
|
#![deny(intra_doc_link_resolution_failure)]
|
||||||
|
|
||||||
mod exports;
|
mod exports;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
// Native Funcs
|
// Native Funcs
|
||||||
// use wasmer_runtime::ExportFunction;
|
// use wasmer_runtime::ExportFunction;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use wasm_common::{WasmExternType, WasmTypeList};
|
use wasm_common::{Func, WasmExternType, WasmTypeList};
|
||||||
// pub trait NativeHostFunction<Args, Rets>
|
|
||||||
// where
|
|
||||||
// Args: WasmTypeList,
|
|
||||||
// Rets: WasmTypeList,
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UnprovidedArgs;
|
pub struct UnprovidedArgs;
|
||||||
@@ -30,85 +24,38 @@ impl<'a, Args, Rets> NativeFunc<'a, Args, Rets> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[allow (unused_parens)]
|
/*impl<'a, Args, Rets> From<NativeFunc<'a, Args, Rets>> for Func
|
||||||
// impl <'a, A1, Rets > NativeFunc <'a, (A1,), Rets >
|
where
|
||||||
// where
|
Args: WasmTypeList,
|
||||||
// A1 : WasmExternType,
|
Rets: WasmTypeList,
|
||||||
// Rets : WasmTypeList,
|
{
|
||||||
// {
|
fn from(other: NativeFunc<'a, Args, Rets>) -> Func {
|
||||||
// /// Call the typed func and return results.
|
Func {
|
||||||
// pub fn calla(&self, A1:A1,) -> Result <Rets, ()>{
|
|
||||||
// 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 <Rets, ()>{
|
|
||||||
// unimplemented!("");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
macro_rules! impl_native_traits {
|
macro_rules! impl_native_traits {
|
||||||
( $( $x:ident ),* ) => {
|
( $( $x:ident ),* ) => {
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x ),* ), Rets>
|
impl<'a $( , $x )*, Rets> NativeFunc<'a, ( $( $x, )* ), Rets>
|
||||||
where
|
where
|
||||||
$( $x: WasmExternType, )*
|
$( $x: WasmExternType, )*
|
||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
/// Call the typed func and return results.
|
/// Call the typed func and return results.
|
||||||
pub fn call(&self, $( $x: $x, )* ) -> Result<Rets, ()> {
|
pub fn call(&self, $( $x: $x, )* ) -> Result<Rets, ()> {
|
||||||
trace_macros!(false);
|
|
||||||
unimplemented!("");
|
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<Rets::CStruct, RuntimeError> {
|
|
||||||
// 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<Option<Rets::CStruct>> = 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!();
|
||||||
impl_native_traits!(A1);
|
impl_native_traits!(A1);
|
||||||
impl_native_traits!(A1, A2);
|
impl_native_traits!(A1, A2);
|
||||||
|
|
||||||
trace_macros!(false);
|
|
||||||
|
|
||||||
// impl_native_traits!(A1, A2, A3);
|
// impl_native_traits!(A1, A2, A3);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
//! This crate provides common structures such as `Type` or `Value`, type indexes
|
//! This crate provides common structures such as `Type` or `Value`, type indexes
|
||||||
//! and native function wrappers with `Func`.
|
//! and native function wrappers with `Func`.
|
||||||
|
|
||||||
#![feature(trace_macros)]
|
|
||||||
#![deny(missing_docs, unused_extern_crates)]
|
#![deny(missing_docs, unused_extern_crates)]
|
||||||
#![warn(unused_import_braces)]
|
#![warn(unused_import_braces)]
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
|
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
|
||||||
|
|||||||
@@ -705,107 +705,3 @@ mod test_func {
|
|||||||
// assert_eq!(result.is_err(), true);
|
// 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 <Rets, ()>{
|
|
||||||
// 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 <Rets, ()>{
|
|
||||||
// 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<Rets, ()> {
|
|
||||||
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<Rets::CStruct, RuntimeError> {
|
|
||||||
// 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<Option<Rets::CStruct>> = 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);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user