Browse Source

Merge pull request #953 from peterhuene/implement-wasm-func-type

Implement wasm_func_type in the C API.
pull/956/head
Peter Huene 5 years ago
committed by GitHub
parent
commit
2fd3a31c06
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      crates/c-api/src/lib.rs

25
crates/c-api/src/lib.rs

@ -257,6 +257,7 @@ pub struct wasm_importtype_t {
ty: ImportType, ty: ImportType,
module_cache: Option<wasm_name_t>, module_cache: Option<wasm_name_t>,
name_cache: Option<wasm_name_t>, name_cache: Option<wasm_name_t>,
type_cache: Option<wasm_externtype_t>,
} }
declare_vec!(wasm_importtype_vec_t, *mut wasm_importtype_t); declare_vec!(wasm_importtype_vec_t, *mut wasm_importtype_t);
@ -835,6 +836,7 @@ pub unsafe extern "C" fn wasm_module_new(
ty: i.clone(), ty: i.clone(),
module_cache: None, module_cache: None,
name_cache: None, name_cache: None,
type_cache: None,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let exports = module let exports = module
@ -1073,11 +1075,14 @@ pub unsafe extern "C" fn wasm_importtype_name(it: *const wasm_importtype_t) -> *
pub unsafe extern "C" fn wasm_importtype_type( pub unsafe extern "C" fn wasm_importtype_type(
it: *const wasm_importtype_t, it: *const wasm_importtype_t,
) -> *const wasm_externtype_t { ) -> *const wasm_externtype_t {
let ty = Box::new(wasm_externtype_t { if (*it).type_cache.is_none() {
ty: (*it).ty.ty().clone(), let it = (it as *mut wasm_importtype_t).as_mut().unwrap();
cache: wasm_externtype_t_type_cache::Empty, it.type_cache = Some(wasm_externtype_t {
}); ty: (*it).ty.ty().clone(),
Box::into_raw(ty) cache: wasm_externtype_t_type_cache::Empty,
});
}
(*it).type_cache.as_ref().unwrap()
} }
#[no_mangle] #[no_mangle]
@ -1230,6 +1235,16 @@ pub unsafe extern "C" fn wasm_externtype_kind(et: *const wasm_externtype_t) -> w
} }
} }
#[no_mangle]
pub unsafe extern "C" fn wasm_func_type(f: *const wasm_func_t) -> *mut wasm_functype_t {
let ft = Box::new(wasm_functype_t {
functype: (*f).func().borrow().ty().clone(),
params_cache: None,
returns_cache: None,
});
Box::into_raw(ft)
}
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasm_func_param_arity(f: *const wasm_func_t) -> usize { pub unsafe extern "C" fn wasm_func_param_arity(f: *const wasm_func_t) -> usize {
(*f).func().borrow().param_arity() (*f).func().borrow().param_arity()

Loading…
Cancel
Save