feat(c-api) Implement wasm_func_type.

This patch creates a `wasm_functype_t::new` constructor, that is used
by the new `wasm_func_type` function, and the existing
`wasm_functype_new_inner` function.
This commit is contained in:
Ivan Enderlin
2020-10-15 15:05:26 +02:00
parent 193d7c8ce1
commit ffff0441bc
2 changed files with 17 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
use super::super::store::wasm_store_t; use super::super::store::wasm_store_t;
use super::super::trap::wasm_trap_t; use super::super::trap::wasm_trap_t;
use super::super::types::{wasm_functype_t, wasm_valkind_enum}; use super::super::types::{wasm_functype_t, wasm_functype_t, wasm_valkind_enum};
use super::super::value::{wasm_val_inner, wasm_val_t}; use super::super::value::{wasm_val_inner, wasm_val_t};
use std::convert::TryInto; use std::convert::TryInto;
use std::ffi::c_void; use std::ffi::c_void;
@@ -154,3 +154,8 @@ pub unsafe extern "C" fn wasm_func_param_arity(func: &wasm_func_t) -> usize {
pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize { pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize {
func.inner.ty().results().len() func.inner.ty().results().len()
} }
#[no_mangle]
pub extern "C" fn wasm_func_type(func: &wasm_func_t) -> Box<wasm_functype_t> {
Box::new(wasm_functype_t::new(func.inner.ty().clone()))
}

View File

@@ -17,6 +17,14 @@ impl wasm_functype_t {
unreachable!("data corruption: `wasm_functype_t` does not contain a function") unreachable!("data corruption: `wasm_functype_t` does not contain a function")
} }
} }
pub(crate) fn new(function_type: FunctionType) -> Self {
Self {
extern_: wasm_externtype_t {
inner: ExternType::Function(function_type),
},
}
}
} }
wasm_declare_vec!(functype); wasm_declare_vec!(functype);
@@ -52,10 +60,9 @@ unsafe fn wasm_functype_new_inner(
.map(Into::into) .map(Into::into)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let extern_ = wasm_externtype_t { Some(Box::new(wasm_functype_t::new(FunctionType::new(
inner: ExternType::Function(FunctionType::new(params, results)), params, results,
}; ))))
Some(Box::new(wasm_functype_t { extern_ }))
} }
#[no_mangle] #[no_mangle]