use crate::{store::MaybeInstanceOwned, vmcontext::VMGlobalDefinition};
use std::{cell::UnsafeCell, ptr::NonNull};
use wasmer_types::GlobalType;
#[derive(Debug)]
pub struct VMGlobal {
ty: GlobalType,
vm_global_definition: MaybeInstanceOwned<VMGlobalDefinition>,
}
impl VMGlobal {
pub fn new(global_type: GlobalType) -> Self {
Self {
ty: global_type,
vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
VMGlobalDefinition::new(),
))),
}
}
pub fn ty(&self) -> &GlobalType {
&self.ty
}
pub fn vmglobal(&self) -> NonNull<VMGlobalDefinition> {
self.vm_global_definition.as_ptr()
}
pub fn copy_on_write(&self) -> Self {
unsafe {
Self {
ty: self.ty,
vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
self.vm_global_definition.as_ptr().as_ref().clone(),
))),
}
}
}
}