mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-04 23:02:14 +00:00
Fix argument type conversion
This commit is contained in:
parent
29d053cb29
commit
dbd0f99514
@ -13,7 +13,7 @@ fn main() -> Result<()> {
|
|||||||
"print_i32",
|
"print_i32",
|
||||||
export_func!(
|
export_func!(
|
||||||
print_num,
|
print_num,
|
||||||
[I32] -> [I32]
|
[i32] -> [i32]
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -12,14 +12,14 @@ macro_rules! export_func {
|
|||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
|
|
||||||
let func: extern fn( $( $crate::__export_func_convert_type!($params), )* &mut vm::Ctx) -> ($( $crate::__export_func_convert_type!($returns) )*) = $func;
|
let func: extern fn( $( $params, )* &mut vm::Ctx) -> ($( $returns )*) = $func;
|
||||||
|
|
||||||
Export::Function {
|
Export::Function {
|
||||||
func: unsafe { FuncPointer::new(func as _) },
|
func: unsafe { FuncPointer::new(func as _) },
|
||||||
ctx: Context::Internal,
|
ctx: Context::Internal,
|
||||||
signature: FuncSig {
|
signature: FuncSig {
|
||||||
params: vec![$(Type::$params,)*],
|
params: vec![$($crate::__export_func_convert_type!($params),)*],
|
||||||
returns: vec![$(Type::$params,)*],
|
returns: vec![$($crate::__export_func_convert_type!($params),)*],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
@ -28,16 +28,25 @@ macro_rules! export_func {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
macro_rules! __export_func_convert_type {
|
macro_rules! __export_func_convert_type {
|
||||||
(I32) => {
|
(i32) => {
|
||||||
i32
|
Type::I32
|
||||||
};
|
};
|
||||||
(I64) => {
|
(u32) => {
|
||||||
i64
|
Type::I32
|
||||||
};
|
};
|
||||||
(F32) => {
|
(i64) => {
|
||||||
f32
|
Type::I64
|
||||||
};
|
};
|
||||||
(F64) => {
|
(u64) => {
|
||||||
f64
|
Type::I32
|
||||||
};
|
};
|
||||||
}
|
(f32) => {
|
||||||
|
Type::F32
|
||||||
|
};
|
||||||
|
(f64) => {
|
||||||
|
Type::F64
|
||||||
|
};
|
||||||
|
($x:ty) => {
|
||||||
|
compile_error!("Only `i32`, `u32`, `i64`, `u64`, `f32`, and `f64` are supported for argument and return types")
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user