wasmtime: Implement table.fill

Part of #929
This commit is contained in:
Nick Fitzgerald
2020-07-02 16:56:02 -07:00
parent d87ada209c
commit 3555f97906
5 changed files with 97 additions and 13 deletions

View File

@@ -265,6 +265,41 @@ pub unsafe extern "C" fn wasmtime_table_grow(
}
}
/// Implementation of `table.fill`.
pub unsafe extern "C" fn wasmtime_table_fill(
vmctx: *mut VMContext,
table_index: u32,
dst: u32,
// NB: we don't know whether this is a `VMExternRef` or a pointer to a
// `VMCallerCheckedAnyfunc` until we look at the table's element type.
val: *mut u8,
len: u32,
) {
let result = {
let instance = (&mut *vmctx).instance();
let table_index = TableIndex::from_u32(table_index);
let table = instance.get_table(table_index);
match table.element_type() {
TableElementType::Func => {
let val = val as *mut VMCallerCheckedAnyfunc;
table.fill(dst, val.into(), len)
}
TableElementType::Val(ty) => {
debug_assert_eq!(ty, crate::ref_type());
let val = if val.is_null() {
None
} else {
Some(VMExternRef::clone_from_raw(val))
};
table.fill(dst, val.into(), len)
}
}
};
if let Err(trap) = result {
raise_lib_trap(trap);
}
}
/// Implementation of `table.copy`.
pub unsafe extern "C" fn wasmtime_table_copy(
vmctx: *mut VMContext,