Remove BaseObj and fix Object::equals

* BaseObj felt a bit redundant. For everything that BaseObj did, we use
  Obj instead.
* Object::equals was a little weird. It was used for giving back
  equality, except when it wasn't. It's a little better defined now,
  here's what I'm shooting for:
    * *In general*, Object::equals will return true when two objects
      refer to the same object.
    * The exception to this rule is for "constant" objects, or "copy on
      write" objects. These include, but are not limited to: Int, Float,
      Bool, Nil, Str. Their base values are immutable and are the heart
      of object equality.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-10-10 20:30:24 -07:00
parent 6143437626
commit 3fd0ba3a0b
9 changed files with 114 additions and 209 deletions

View File

@@ -5,12 +5,12 @@ use gc::{Finalize, Trace};
use crate::obj::macros::*;
use crate::obj::prelude::*;
use crate::obj::BaseObj;
use crate::obj::Obj;
use crate::vm::Chunk;
#[derive(Trace, Finalize)]
pub struct Module {
base: BaseObj,
base: Obj,
#[unsafe_ignore_trace]
path: Rc<String>,
#[unsafe_ignore_trace]
@@ -66,15 +66,6 @@ impl Display for Module {
}
impl Object for Module {
fn equals(&self, other: &dyn Object) -> bool {
if let Some(other) = other.as_any().downcast_ref::<Module>() {
// only referential identity
std::ptr::addr_eq(self, other)
} else {
false
}
}
impl_base_obj!(Module);
}