test out better debugging

This commit is contained in:
nora 2022-04-23 17:03:17 +02:00
parent 6a8eb89381
commit 5f9ca90fd5
13 changed files with 422 additions and 145 deletions

View file

@ -18,6 +18,13 @@ pub struct Gc<T: ?Sized> {
ptr: NonNull<T>,
}
#[cfg(feature = "_debug")]
impl<T: ?Sized> dbg_pls::DebugPls for Gc<T> {
fn fmt(&self, f: dbg_pls::Formatter<'_>) {
todo!()
}
}
impl<T: ?Sized> Deref for Gc<T> {
type Target = T;
@ -30,21 +37,6 @@ impl<T: ?Sized> Deref for Gc<T> {
}
}
#[cfg(feature = "_debug")]
impl<T: debug2::Debug> debug2::Debug for Gc<T> {
fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result {
T::fmt(&*self, f)
}
}
#[cfg(feature = "_debug")]
impl debug2::Debug for Gc<str> {
fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result {
let str = self.deref();
debug2::Debug::fmt(&str, f)
}
}
impl<T: Debug + ?Sized> Debug for Gc<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
T::fmt(self, f)
@ -61,7 +53,7 @@ impl<T: ?Sized> Copy for Gc<T> {}
/// An reference to an interned String. Hashing and Equality are O(1) and just look at the pointer address
#[derive(Clone, Copy)]
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
pub struct Symbol {
gc: Gc<str>,
}
@ -74,20 +66,18 @@ type ObjectMap = HashMap<Symbol, Value>;
/// ```
/// This is inside the local x now.
#[derive(Clone, Copy)]
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
pub struct Object {
gc: Gc<HeapObject>,
}
#[derive(Debug)]
#[repr(C)]
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
struct HeapObject {
kind: HeapObjectKind,
}
#[derive(Debug)]
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
enum HeapObjectKind {
String(Gc<str>),
Object(ObjectMap),