Skip to content

Commit

Permalink
Fix argument type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlansneff committed Jan 21, 2019
1 parent 29d053c commit dbd0f99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/runtime/examples/simple/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> Result<()> {
"print_i32",
export_func!(
print_num,
[I32] -> [I32]
[i32] -> [i32]
),
);

Expand Down
33 changes: 21 additions & 12 deletions lib/runtime/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ macro_rules! export_func {
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 {
func: unsafe { FuncPointer::new(func as _) },
ctx: Context::Internal,
signature: FuncSig {
params: vec![$(Type::$params,)*],
returns: vec![$(Type::$params,)*],
params: vec![$($crate::__export_func_convert_type!($params),)*],
returns: vec![$($crate::__export_func_convert_type!($params),)*],
},
}
}};
Expand All @@ -28,16 +28,25 @@ macro_rules! export_func {
#[macro_export]
#[doc(hidden)]
macro_rules! __export_func_convert_type {
(I32) => {
i32
(i32) => {
Type::I32
};
(I64) => {
i64
(u32) => {
Type::I32
};
(F32) => {
f32
(i64) => {
Type::I64
};
(F64) => {
f64
(u64) => {
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")
};
}

0 comments on commit dbd0f99

Please sign in to comment.