Changes all around - objects and GC

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-16 18:46:09 -04:00
parent a15dde0fc2
commit d5cf39108b
15 changed files with 223 additions and 203 deletions

View File

@@ -1,40 +1,31 @@
use crate::{
mem::{gc::Gc, ptr::DynRef, BasicGc},
obj::Sym,
mem::{gc::Gc, BasicGc},
obj::prelude::*,
};
use std::collections::BTreeMap;
pub type DefaultGc = BasicGc;
pub struct ObjCtx<G = DefaultGc>
pub struct ObjCtx<'g, 'n, G>
where
G: Gc,
G: Gc + 'g,
{
gc: G,
globals: BTreeMap<Sym, DynRef>,
gc: &'g mut G,
ns: &'n mut Ns,
}
impl<G> ObjCtx<G>
impl<'g, 'n, G> ObjCtx<'g, 'n, G>
where
G: Gc,
G: Gc + 'g,
{
pub fn new(gc: G) -> Self {
ObjCtx { gc, globals: Default::default() }
pub fn new(gc: &'g mut G, ns: &'n mut Ns) -> Self {
ObjCtx { gc, ns }
}
pub fn gc(&self) -> &G {
&self.gc
pub fn gc_mut(&'g mut self) -> &'g mut G {
self.gc
}
pub fn gc_mut(&mut self) -> &mut G {
&mut self.gc
}
pub fn globals(&self) -> &BTreeMap<Sym, DynRef> {
&self.globals
}
pub fn globals_mut(&mut self) -> &mut BTreeMap<Sym, DynRef> {
&mut self.globals
pub fn ns_mut(&'n mut self) -> &'n mut Ns {
self.ns
}
}