use crate::global::Global;
use crate::instance::InstanceRef;
use crate::memory::{Memory, MemoryStyle};
use crate::table::{Table, TableStyle};
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline};
use std::sync::Arc;
use wasmer_types::{FunctionType, MemoryType, TableType};
#[derive(Debug)]
pub enum VMExport {
Function(VMExportFunction),
Table(VMExportTable),
Memory(VMExportMemory),
Global(VMExportGlobal),
}
#[derive(Debug, Clone, PartialEq)]
pub struct VMExportFunction {
pub address: *const VMFunctionBody,
pub vmctx: VMFunctionEnvironment,
pub signature: FunctionType,
pub kind: VMFunctionKind,
pub call_trampoline: Option<VMTrampoline>,
pub instance_ref: Option<InstanceRef>,
}
unsafe impl Send for VMExportFunction {}
unsafe impl Sync for VMExportFunction {}
impl From<VMExportFunction> for VMExport {
fn from(func: VMExportFunction) -> Self {
Self::Function(func)
}
}
#[derive(Debug, Clone)]
pub struct VMExportTable {
pub from: Arc<dyn Table>,
pub instance_ref: Option<InstanceRef>,
}
unsafe impl Send for VMExportTable {}
unsafe impl Sync for VMExportTable {}
impl VMExportTable {
pub fn ty(&self) -> &TableType {
self.from.ty()
}
pub fn style(&self) -> &TableStyle {
self.from.style()
}
pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from)
}
}
impl From<VMExportTable> for VMExport {
fn from(table: VMExportTable) -> Self {
Self::Table(table)
}
}
#[derive(Debug, Clone)]
pub struct VMExportMemory {
pub from: Arc<dyn Memory>,
pub instance_ref: Option<InstanceRef>,
}
unsafe impl Send for VMExportMemory {}
unsafe impl Sync for VMExportMemory {}
impl VMExportMemory {
pub fn ty(&self) -> &MemoryType {
self.from.ty()
}
pub fn style(&self) -> &MemoryStyle {
self.from.style()
}
pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from)
}
}
impl From<VMExportMemory> for VMExport {
fn from(memory: VMExportMemory) -> Self {
Self::Memory(memory)
}
}
#[derive(Debug, Clone)]
pub struct VMExportGlobal {
pub from: Arc<Global>,
pub instance_ref: Option<InstanceRef>,
}
unsafe impl Send for VMExportGlobal {}
unsafe impl Sync for VMExportGlobal {}
impl VMExportGlobal {
pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from)
}
}
impl From<VMExportGlobal> for VMExport {
fn from(global: VMExportGlobal) -> Self {
Self::Global(global)
}
}