Rename anyref to externref across the board

This commit is contained in:
Nick Fitzgerald
2020-05-20 11:55:30 -07:00
parent 5c39b74eb8
commit f28b3738ee
25 changed files with 151 additions and 130 deletions

View File

@@ -1,7 +1,7 @@
use crate::{handle_result, wasm_func_t, wasm_ref_t, wasmtime_error_t};
use crate::{wasm_extern_t, wasm_store_t, wasm_tabletype_t, ExternHost};
use std::ptr;
use wasmtime::{AnyRef, HostRef, Table, Val};
use wasmtime::{ExternRef, HostRef, Table, Val};
#[derive(Clone)]
#[repr(transparent)]
@@ -28,8 +28,8 @@ impl wasm_table_t {
}
}
fn anyref(&self) -> wasmtime::AnyRef {
self.table().anyref()
fn externref(&self) -> wasmtime::ExternRef {
self.table().externref()
}
}
@@ -41,7 +41,7 @@ pub extern "C" fn wasm_table_new(
) -> Option<Box<wasm_table_t>> {
let init: Val = match init {
Some(init) => init.r.into(),
None => Val::AnyRef(AnyRef::Null),
None => Val::ExternRef(ExternRef::Null),
};
let table = Table::new(&store.store.borrow(), tt.ty().ty.clone(), init).ok()?;
Some(Box::new(wasm_table_t {
@@ -60,7 +60,7 @@ pub extern "C" fn wasmtime_funcref_table_new(
) -> Option<Box<wasmtime_error_t>> {
let init: Val = match init {
Some(val) => Val::FuncRef(val.func().borrow().clone()),
None => Val::AnyRef(AnyRef::Null),
None => Val::ExternRef(ExternRef::Null),
};
handle_result(
Table::new(&store.store.borrow(), tt.ty().ty.clone(), init),
@@ -84,7 +84,7 @@ pub extern "C" fn wasm_table_type(t: &wasm_table_t) -> Box<wasm_tabletype_t> {
pub extern "C" fn wasm_table_get(t: &wasm_table_t, index: wasm_table_size_t) -> *mut wasm_ref_t {
match t.table().borrow().get(index) {
Some(val) => into_funcref(val),
None => into_funcref(Val::AnyRef(AnyRef::Null)),
None => into_funcref(Val::ExternRef(ExternRef::Null)),
}
}
@@ -99,7 +99,7 @@ pub extern "C" fn wasmtime_funcref_table_get(
*ptr = match val {
// TODO: what do do about creating new `HostRef` handles here?
Val::FuncRef(f) => Box::into_raw(Box::new(HostRef::new(f).into())),
Val::AnyRef(AnyRef::Null) => ptr::null_mut(),
Val::ExternRef(ExternRef::Null) => ptr::null_mut(),
_ => return false,
};
}
@@ -127,20 +127,20 @@ pub extern "C" fn wasmtime_funcref_table_set(
) -> Option<Box<wasmtime_error_t>> {
let val = match val {
Some(val) => Val::FuncRef(val.func().borrow().clone()),
None => Val::AnyRef(AnyRef::Null),
None => Val::ExternRef(ExternRef::Null),
};
handle_result(t.table().borrow().set(index, val), |()| {})
}
fn into_funcref(val: Val) -> *mut wasm_ref_t {
if let Val::AnyRef(AnyRef::Null) = val {
if let Val::ExternRef(ExternRef::Null) = val {
return ptr::null_mut();
}
let anyref = match val.anyref() {
Some(anyref) => anyref,
let externref = match val.externref() {
Some(externref) => externref,
None => return ptr::null_mut(),
};
let r = Box::new(wasm_ref_t { r: anyref });
let r = Box::new(wasm_ref_t { r: externref });
Box::into_raw(r)
}
@@ -148,7 +148,7 @@ unsafe fn from_funcref(r: *mut wasm_ref_t) -> Val {
if !r.is_null() {
Box::from_raw(r).r.into()
} else {
Val::AnyRef(AnyRef::Null)
Val::ExternRef(ExternRef::Null)
}
}
@@ -176,7 +176,7 @@ pub extern "C" fn wasmtime_funcref_table_grow(
) -> Option<Box<wasmtime_error_t>> {
let val = match init {
Some(val) => Val::FuncRef(val.func().borrow().clone()),
None => Val::AnyRef(AnyRef::Null),
None => Val::ExternRef(ExternRef::Null),
};
handle_result(t.table().borrow().grow(delta, val), |prev| {
if let Some(ptr) = prev_size {