fix(vm): get rid of unused origin-reliant refcounts
This commit is contained in:
parent
a05ebb7f1e
commit
db88aa1f3f
|
@ -1,4 +1,3 @@
|
|||
use core::marker::PhantomData;
|
||||
use fogtix_bytecode::{Atom, Instr, Parse, Pointer, Value as BcValue};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -24,7 +23,7 @@ pub struct InstrPtr {
|
|||
pub pos: usize,
|
||||
}
|
||||
|
||||
fn next_instr<'a>(m: &'a Module, pos: usize) -> Option<Result<(usize, Instr<'_>), &[u8]>> {
|
||||
fn next_instr(m: &Module, pos: usize) -> Option<Result<(usize, Instr<'_>), &[u8]>> {
|
||||
m.as_slice()
|
||||
.get(pos..)
|
||||
.map(|nxti_arr| match Instr::parse(nxti_arr) {
|
||||
|
@ -47,35 +46,12 @@ impl InstrPtr {
|
|||
|
||||
pub trait Origin: Send + Sync + core::fmt::Debug {
|
||||
fn call(&self, p: &Pointer, a: &Atom, stack: &mut Vec<StackEntValue>) -> InstrPtr;
|
||||
fn incr_refcount(&self, p: &Pointer);
|
||||
fn decr_refcount(&self, p: &Pointer);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WrappedPointer {
|
||||
orig: Arc<dyn Origin>,
|
||||
p: Pointer,
|
||||
_h: PhantomData<*const StackEntValue>,
|
||||
}
|
||||
|
||||
unsafe impl Send for WrappedPointer {}
|
||||
unsafe impl Sync for WrappedPointer {}
|
||||
|
||||
impl Clone for WrappedPointer {
|
||||
fn clone(&self) -> Self {
|
||||
self.orig.incr_refcount(&self.p);
|
||||
Self {
|
||||
orig: Arc::clone(&self.orig),
|
||||
p: self.p,
|
||||
_h: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WrappedPointer {
|
||||
fn drop(&mut self) {
|
||||
self.orig.decr_refcount(&self.p);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -266,7 +242,6 @@ impl Process {
|
|||
BcValue::Pointer(p) => StackEntValue::Pointer(WrappedPointer {
|
||||
orig: Arc::clone(&*NOOP_ORIGIN),
|
||||
p,
|
||||
_h: PhantomData,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ impl Origin for NoopOrigin {
|
|||
pos: 0,
|
||||
}
|
||||
}
|
||||
fn incr_refcount(&self, _p: &Pointer) {}
|
||||
fn decr_refcount(&self, _p: &Pointer) {}
|
||||
}
|
||||
|
||||
pub static NOOP_ORIGIN: Lazy<Arc<dyn Origin>> = Lazy::new(|| Arc::new(NoopOrigin));
|
||||
|
|
Loading…
Reference in a new issue