Moved ExternRef and FuncRef into crate::vm for unification

This commit is contained in:
Syrus Akbary
2023-02-14 18:07:05 -08:00
parent 3e7552abc3
commit e9b8868b63
10 changed files with 60 additions and 68 deletions

View File

@@ -6,6 +6,7 @@ use crate::store::{AsStoreMut, AsStoreRef};
use crate::js::extern_ref as extern_ref_imp;
#[cfg(feature = "sys")]
use crate::sys::extern_ref as extern_ref_imp;
use crate::vm::VMExternRef;
#[derive(Debug, Clone)]
#[repr(transparent)]
@@ -29,13 +30,13 @@ impl ExternRef {
self.0.downcast(store)
}
pub(crate) fn vm_externref(&self) -> extern_ref_imp::VMExternRef {
pub(crate) fn vm_externref(&self) -> VMExternRef {
self.0.vm_externref()
}
pub(crate) unsafe fn from_vm_externref(
store: &mut impl AsStoreMut,
vm_externref: extern_ref_imp::VMExternRef,
vm_externref: VMExternRef,
) -> Self {
ExternRef(extern_ref_imp::ExternRef::from_vm_externref(
store,

View File

@@ -1,12 +1,12 @@
use crate::exports::{ExportError, Exportable};
use crate::store::{AsStoreMut, AsStoreRef};
use crate::RuntimeError;
use crate::value::Value;
use crate::vm::VMExtern;
use crate::vm::VMExternGlobal;
use crate::Extern;
use crate::GlobalType;
use crate::Mutability;
use crate::vm::VMExtern;
use crate::RuntimeError;
#[cfg(feature = "js")]
use crate::js::externals::global as global_impl;

View File

@@ -1,25 +1,9 @@
use std::any::Any;
use crate::js::vm::VMExternRef;
use crate::store::{AsStoreMut, AsStoreRef};
use wasmer_types::RawValue;
pub(crate) struct VMExternRef;
impl VMExternRef {
/// Converts the `VMExternRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
unimplemented!();
}
/// Extracts a `VMExternRef` from a `RawValue`.
///
/// # Safety
/// `raw` must be a valid `VMExternRef` instance.
pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
unimplemented!();
}
}
#[derive(Debug, Clone)]
#[repr(transparent)]
pub struct ExternRef;

View File

@@ -13,33 +13,10 @@ use js_sys::{Array, Function as JSFunction};
use std::iter::FromIterator;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasmer_types::RawValue;
use crate::js::vm::VMFunction;
use crate::js::vm::{VMFuncRef, VMFunction, VMFunctionBody};
use std::fmt;
#[repr(C)]
pub struct VMFunctionBody(u8);
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct VMFuncRef;
impl VMFuncRef {
/// Converts the `VMFuncRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
unimplemented!()
}
/// Extracts a `VMFuncRef` from a `RawValue`.
///
/// # Safety
/// `raw.funcref` must be a valid pointer.
pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
unimplemented!();
}
}
#[inline]
fn result_to_js(val: &Value) -> JsValue {
match val {
@@ -860,7 +837,7 @@ mod inner {
/// Writes the contents of a C struct to an array of `f64`.
///
/// # Safety
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, ptr: *mut f64);
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, ptr: *mut RawValue);
/// Get the Wasm types for the tuple (list) of currently
/// represented values.
@@ -1122,7 +1099,7 @@ mod inner {
(
$(
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(_store, $x.into()))
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(_store, $x))
),*
)
}
@@ -1142,7 +1119,7 @@ mod inner {
}
#[allow(non_snake_case)]
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, _ptr: *mut f64) {
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, _ptr: *mut RawValue) {
// Unpack items of the tuple.
let $c_struct_name( $( $x ),* ) = c_struct;
@@ -1349,7 +1326,7 @@ mod inner {
self
}
unsafe fn write_c_struct_to_ptr(_: Self::CStruct, _: *mut f64) {}
unsafe fn write_c_struct_to_ptr(_: Self::CStruct, _: *mut RawValue) {}
fn wasm_types() -> &'static [Type] {
&[]

View File

@@ -16,6 +16,7 @@ use std::fmt;
#[cfg(feature = "tracing")]
use tracing::trace;
use wasm_bindgen::{JsCast, JsValue};
use wasmer_types::RawValue;
use wasmer_types::{
ExternType, FunctionType, GlobalType, MemoryError, MemoryType, Pages, TableType, WASM_PAGE_SIZE,
};
@@ -212,6 +213,45 @@ impl VMFunctionEnvironment {
}
}
pub(crate) struct VMExternRef;
impl VMExternRef {
/// Converts the `VMExternRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
unimplemented!();
}
/// Extracts a `VMExternRef` from a `RawValue`.
///
/// # Safety
/// `raw` must be a valid `VMExternRef` instance.
pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
unimplemented!();
}
}
#[repr(C)]
pub struct VMFunctionBody(u8);
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct VMFuncRef;
impl VMFuncRef {
/// Converts the `VMFuncRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
unimplemented!()
}
/// Extracts a `VMFuncRef` from a `RawValue`.
///
/// # Safety
/// `raw.funcref` must be a valid pointer.
pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
unimplemented!();
}
}
pub(crate) type VMExternTable = VMTable;
pub(crate) type VMExternMemory = VMMemory;
pub(crate) type VMExternGlobal = VMGlobal;

View File

@@ -3,12 +3,7 @@
use wasmer_types::{NativeWasmType, RawValue, Type};
#[cfg(feature = "js")]
use crate::js::extern_ref::VMExternRef;
#[cfg(feature = "js")]
use crate::js::externals::function::VMFuncRef;
#[cfg(feature = "sys")]
use wasmer_vm::{VMExternRef, VMFuncRef};
use crate::vm::{VMExternRef, VMFuncRef};
use crate::{ExternRef, Function, TypedFunction, WasmTypeList};

View File

@@ -1,6 +1,5 @@
use std::any::Any;
pub use wasmer_vm::VMExternRef;
use wasmer_vm::VMExternRef;
use wasmer_vm::{StoreHandle, VMExternObj};
use crate::store::{AsStoreMut, AsStoreRef};

View File

@@ -20,7 +20,8 @@ pub(crate) mod vm {
//! The `vm` module re-exports wasmer-vm types.
use wasmer_vm::InternalStoreHandle;
pub(crate) use wasmer_vm::{
VMExtern, VMFunction, VMFunctionEnvironment, VMGlobal, VMMemory, VMTable,
VMExtern, VMExternRef, VMFuncRef, VMFunction, VMFunctionEnvironment, VMGlobal, VMMemory,
VMTable,
};
pub(crate) type VMExternTable = InternalStoreHandle<VMTable>;

View File

@@ -4,12 +4,7 @@ use std::string::{String, ToString};
use wasmer_types::Type;
#[cfg(feature = "js")]
use crate::js::extern_ref::VMExternRef;
#[cfg(feature = "js")]
use crate::js::externals::function::VMFuncRef;
#[cfg(feature = "sys")]
use wasmer_vm::{VMExternRef, VMFuncRef};
use crate::vm::{VMExternRef, VMFuncRef};
use crate::ExternRef;
use crate::Function;

View File

@@ -2,14 +2,14 @@
#[cfg(feature = "js")]
pub(crate) use crate::js::vm::{
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternTable, VMFunction,
VMFunctionEnvironment, VMGlobal, VMMemory, VMTable,
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternRef, VMExternTable,
VMFuncRef, VMFunction, VMFunctionEnvironment, VMGlobal, VMMemory, VMTable,
};
#[cfg(feature = "sys")]
pub(crate) use crate::sys::vm::{
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternTable,
VMFunctionEnvironment,
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternRef, VMExternTable,
VMFuncRef, VMFunctionEnvironment,
};
// Needed for tunables customization