-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from notJoon/add-gc-algorithms
Add TriColorGC and MarkAndSweep garbage collectors
- Loading branch information
Showing
9 changed files
with
244 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::fmt; | ||
|
||
use crate::{controller::PIController, vm::VirtualMachine}; | ||
|
||
pub trait GarbageCollector { | ||
fn collect(&self, vm: &mut VirtualMachine); | ||
fn ty(&self) -> GCType; | ||
fn new_instance(&self) -> Box<dyn GarbageCollector>; | ||
fn adjust_confidence(&mut self, vm: &mut VirtualMachine); | ||
fn trigger_gc(&mut self, vm: &mut VirtualMachine); | ||
} | ||
|
||
pub struct TriColorGC { | ||
pub color: TriColor, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum GCType { | ||
MarkAndSweep, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum TriColor { | ||
White, | ||
Gray, | ||
Black, | ||
} | ||
|
||
impl fmt::Display for TriColor { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
TriColor::White => write!(f, "White: Not visited"), | ||
TriColor::Gray => write!(f, "Gray: Visiting"), | ||
TriColor::Black => write!(f, "Black: Visited"), | ||
} | ||
} | ||
} | ||
|
||
pub struct MarkAndSweep { | ||
pub pi: PIController, | ||
} | ||
|
||
// impl GarbageCollector for MarkAndSweep { | ||
// fn collect(&self, vm: &mut VM) { | ||
|
||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::collections::BTreeSet; | ||
|
||
// #[derive(Debug, PartialEq, Clone, Default)] | ||
// pub struct Heap { | ||
// pub roots: BTreeSet<> | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod controller; | ||
pub mod mem; | ||
pub mod object; | ||
pub mod types; | ||
pub mod vm; | ||
pub mod gc; | ||
pub mod heap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.