Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/builtin/functions/hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn add(ctx: &mut TulispContext) {
)
.with_trace(args.clone()));
}
let table = Shared::new_any(HashTable {
let table = Shared::new(HashTable {
inner: SharedMut::new(HashMap::new()),
});
Ok(table.into())
Expand Down
2 changes: 1 addition & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ctx.add_special_form("make_any", |_ctx, args| {
destruct_bind!((inp) = args);
let inp: i64 = inp.try_into()?;

let any_obj = Shared::new_any(TestStruct { value: inp });
let any_obj = Shared::new(TestStruct { value: inp });

Ok(any_obj.into())
});
Expand Down
42 changes: 4 additions & 38 deletions src/object/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub mod generic {
}

impl Shared<dyn TulispAny> {
pub fn new_tulisp_fn(val: impl TulispFn) -> Shared<dyn TulispFn> {
pub(crate) fn new_tulisp_fn(val: impl TulispFn) -> Shared<dyn TulispFn> {
Shared(std::rc::Rc::new(val))
}

pub fn new_any(val: impl TulispAny) -> Shared<dyn TulispAny> {
pub fn new(val: impl TulispAny) -> Shared<dyn TulispAny> {
Shared(std::rc::Rc::new(val))
}

Expand All @@ -51,16 +51,6 @@ pub mod generic {
}
}

impl<T> Shared<T> {
pub fn new(val: T) -> Self {
Shared(std::rc::Rc::new(val))
}

pub fn ptr_eq(&self, other: &Self) -> bool {
std::rc::Rc::ptr_eq(&self.0, &other.0)
}
}

impl<T: ?Sized> Deref for Shared<T> {
type Target = T;

Expand All @@ -69,12 +59,6 @@ pub mod generic {
}
}

impl<T: ?Sized> std::ops::DerefMut for Shared<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
std::rc::Rc::get_mut(&mut self.0).expect("Multiple references exist")
}
}

#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct SharedMut<T>(std::rc::Rc<std::cell::RefCell<T>>);
Expand Down Expand Up @@ -104,14 +88,6 @@ pub mod generic {
}
}

impl<T> Deref for SharedMut<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
todo!()
}
}

pub trait TulispFn:
Fn(&mut TulispContext, &TulispObject) -> Result<TulispObject, Error> + 'static
{
Expand Down Expand Up @@ -152,11 +128,11 @@ pub mod generic {
}

impl Shared<dyn TulispAny> {
pub fn new_tulisp_fn(val: impl TulispFn) -> Shared<dyn TulispFn> {
pub(crate) fn new_tulisp_fn(val: impl TulispFn) -> Shared<dyn TulispFn> {
Shared(std::sync::Arc::new(val))
}

pub fn new_any(val: impl TulispAny) -> Shared<dyn TulispAny> {
pub fn new(val: impl TulispAny) -> Shared<dyn TulispAny> {
Shared(std::sync::Arc::new(val))
}

Expand All @@ -173,16 +149,6 @@ pub mod generic {
}
}

impl<T> Shared<T> {
pub fn new(val: T) -> Self {
Shared(std::sync::Arc::new(val))
}

pub fn ptr_eq(&self, other: &Self) -> bool {
std::sync::Arc::ptr_eq(&self.0, &other.0)
}
}

impl<T: ?Sized> Deref for Shared<T> {
type Target = T;

Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ fn test_any() -> Result<(), Error> {

ctx.add_special_form("make_any", |ctx, args| {
destruct_eval_bind!(ctx, (inp) = args);
let res: Shared<dyn TulispAny> = Shared::new_any(TestStruct {
let res: Shared<dyn TulispAny> = Shared::new(TestStruct {
value: inp.try_into()?,
});

Expand Down