Skip to content

Commit

Permalink
All tests now passing for cp 29
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyboyC committed Mar 25, 2020
1 parent b329df6 commit 8e05613
Show file tree
Hide file tree
Showing 25 changed files with 902 additions and 688 deletions.
590 changes: 583 additions & 7 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions spacelox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ edition = "2018"
[lib]
name = "spacelox_core"
path = "src/lib.rs"

[dependencies]
spacelox_interner = { path = "../spacelox_interner" }
2 changes: 1 addition & 1 deletion spacelox_core/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub enum ByteCode {
/// Create a class
Class(u8),

/// Access this classes super
/// Access this classes super
GetSuper(u8),

/// Add inheritance to class
Expand Down
30 changes: 15 additions & 15 deletions spacelox_core/src/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
cell::Cell,
fmt,
hash::{Hash, Hasher},
mem,
ops::{Deref, DerefMut},
ptr::{self, NonNull},
};
Expand All @@ -14,13 +13,16 @@ pub trait Trace {
}

/// An entity that can be managed and collected by the garbage collector.
/// This trait provided debugging capabilities for the type being managed
/// This trait provided debugging capabilities and statistics for the gc.
pub trait Manage: Trace {
/// What allocation type is
fn alloc_type(&self) -> &str;

/// What allocation type is
fn debug(&self) -> String;

/// What is the size of this allocation
fn size(&self) -> usize;
}

/// The header of an allocation indicate meta data about the object
Expand All @@ -35,7 +37,7 @@ pub struct Allocation<T: 'static + Trace + ?Sized> {
data: T,
}

impl<T: 'static + Trace> Allocation<T> {
impl<T: 'static + Manage> Allocation<T> {
pub fn new(data: T) -> Self {
Self {
data,
Expand All @@ -46,13 +48,13 @@ impl<T: 'static + Trace> Allocation<T> {
}

pub fn size(&self) -> usize {
mem::size_of::<T>()
self.data.size()
}
}

impl Allocation<dyn Manage> {
pub fn size(&self) -> usize {
mem::size_of_val(&self.data)
self.data.size()
}
}

Expand Down Expand Up @@ -119,10 +121,8 @@ impl<T: 'static + Manage> Manage for Managed<T> {
fn debug(&self) -> String {
self.obj().data.debug()
}
}

impl Managed<dyn Manage> {
pub fn size(&self) -> usize {
fn size(&self) -> usize {
self.obj().size()
}
}
Expand All @@ -142,6 +142,10 @@ impl Manage for Managed<dyn Manage> {
fn debug(&self) -> String {
self.obj().data.debug()
}

fn size(&self) -> usize {
self.obj().size()
}
}

impl<T: 'static + Manage + ?Sized> From<NonNull<Allocation<T>>> for Managed<T> {
Expand Down Expand Up @@ -171,16 +175,12 @@ impl<T: 'static + Manage> DerefMut for Managed<T> {
}
}

impl<T: 'static + PartialEq + Manage> PartialEq for Managed<T> {
impl<T: 'static + Manage> PartialEq for Managed<T> {
fn eq(&self, other: &Managed<T>) -> bool {
let left_inner: &T = &*self;
let right_inner: &T = &*other;

if ptr::eq(left_inner, right_inner) {
return true;
}

left_inner.eq(right_inner)
ptr::eq(left_inner, right_inner)
}
}

Expand All @@ -189,7 +189,7 @@ impl<T: 'static + Eq + Manage> Eq for Managed<T> {}
impl<T: 'static + Hash + Manage> Hash for Managed<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
let inner: &T = &*self;
inner.hash(state);
ptr::hash(inner, state)
}
}

Expand Down

0 comments on commit 8e05613

Please sign in to comment.