Add unused global type

This commit is contained in:
Lachlan Sneff 2019-01-28 11:02:53 -08:00
parent 9b491ec95d
commit 1be20b19e7
2 changed files with 8 additions and 9 deletions

View File

@ -2,11 +2,11 @@ use crate::{
types::{GlobalDesc, Type, Value}, types::{GlobalDesc, Type, Value},
vm, vm,
}; };
use std::{cell::UnsafeCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
pub struct Global { pub struct Global {
desc: GlobalDesc, desc: GlobalDesc,
storage: Rc<UnsafeCell<vm::LocalGlobal>>, storage: Rc<RefCell<vm::LocalGlobal>>,
} }
impl Global { impl Global {
@ -35,7 +35,7 @@ impl Global {
Self { Self {
desc, desc,
storage: Rc::new(UnsafeCell::new(local_global)) storage: Rc::new(RefCell::new(local_global))
} }
} }
@ -43,7 +43,7 @@ impl Global {
self.desc self.desc
} }
pub fn set(&mut self, value: Value) { pub fn set(&self, value: Value) {
if self.desc.mutable { if self.desc.mutable {
if self.desc.ty == value.ty() { if self.desc.ty == value.ty() {
let local_global = vm::LocalGlobal { let local_global = vm::LocalGlobal {
@ -54,9 +54,7 @@ impl Global {
Value::F64(x) => x.to_bits(), Value::F64(x) => x.to_bits(),
}, },
}; };
unsafe { *self.storage.borrow_mut() = local_global;
(*self.storage.get()) = local_global;
}
} else { } else {
panic!("Wrong type for setting this global") panic!("Wrong type for setting this global")
} }
@ -66,7 +64,7 @@ impl Global {
} }
pub fn get(&self) -> Value { pub fn get(&self) -> Value {
let data = unsafe { (*self.storage.get()).data }; let data = self.storage.borrow().data;
match self.desc.ty { match self.desc.ty {
Type::I32 => Value::I32(data as i32), Type::I32 => Value::I32(data as i32),
@ -77,7 +75,7 @@ impl Global {
} }
pub(crate) fn vm_local_global(&mut self) -> *mut vm::LocalGlobal { pub(crate) fn vm_local_global(&mut self) -> *mut vm::LocalGlobal {
&mut *unsafe { &mut *self.storage.get() } &mut *self.storage.borrow_mut()
} }
} }

View File

@ -11,6 +11,7 @@ pub mod error;
pub mod export; pub mod export;
pub mod import; pub mod import;
pub mod instance; pub mod instance;
pub mod global;
pub mod memory; pub mod memory;
pub mod module; pub mod module;
mod sig_registry; mod sig_registry;