2019-01-08 12:09:47 -05:00
|
|
|
macro_rules! debug {
|
|
|
|
($fmt:expr) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt), line!()) });
|
|
|
|
($fmt:expr, $($arg:tt)*) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt, "\n"), line!(), $($arg)*) });
|
|
|
|
}
|
2019-01-21 14:43:04 -08:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! export_func {
|
|
|
|
($func:ident, [ $( $params:ident ),* ] -> [ $( $returns:ident ),* ]) => {{
|
|
|
|
use wasmer_runtime::{
|
|
|
|
export::{Context, Export, FuncPointer},
|
|
|
|
types::{FuncSig, Type},
|
2019-01-21 15:10:07 -08:00
|
|
|
vm,
|
2019-01-21 14:43:04 -08:00
|
|
|
};
|
|
|
|
|
2019-01-21 15:10:07 -08:00
|
|
|
let func: extern fn( $( $crate::__export_func_convert_type!($params), )* &mut vm::Ctx) -> ($( $crate::__export_func_convert_type!($returns) )*) = $func;
|
|
|
|
|
2019-01-21 14:43:04 -08:00
|
|
|
Export::Function {
|
2019-01-21 15:10:07 -08:00
|
|
|
func: unsafe { FuncPointer::new(func as _) },
|
2019-01-21 14:43:04 -08:00
|
|
|
ctx: Context::Internal,
|
|
|
|
signature: FuncSig {
|
|
|
|
params: vec![$(Type::$params,)*],
|
|
|
|
returns: vec![$(Type::$params,)*],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
2019-01-21 15:10:07 -08:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
#[doc(hidden)]
|
|
|
|
macro_rules! __export_func_convert_type {
|
|
|
|
(I32) => {
|
|
|
|
i32
|
|
|
|
};
|
|
|
|
(I64) => {
|
|
|
|
i64
|
|
|
|
};
|
|
|
|
(F32) => {
|
|
|
|
f32
|
|
|
|
};
|
|
|
|
(F64) => {
|
|
|
|
f64
|
|
|
|
};
|
|
|
|
}
|