-
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 #4 from notJoon:gc
Gc
- Loading branch information
Showing
10 changed files
with
205 additions
and
43 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
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
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
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 |
---|---|---|
|
@@ -53,4 +53,4 @@ mod alloc_tests { | |
assert_eq!(result, Some(1)); | ||
assert_eq!(heap.free_list.to_vec(), vec![(1, 1)]); | ||
} | ||
} | ||
} |
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,41 @@ | ||
#[cfg(test)] | ||
mod marker_tests { | ||
use gc_simulator::{vm::VirtualMachine, gc::{GarbageCollector, TriColor}, object::{Object, ObjectTrait, TypeValue}}; | ||
|
||
fn vm_setup() -> VirtualMachine { | ||
VirtualMachine::new(10, 0.5, 100, 8).unwrap() | ||
} | ||
|
||
fn gc_setup() -> GarbageCollector { | ||
GarbageCollector::default() | ||
} | ||
|
||
#[test] | ||
fn test_initialization_of_objects() { | ||
let mut vm = vm_setup(); | ||
let mut gc = gc_setup(); | ||
|
||
assert_eq!(vm.heap.objects.values().all(|o| o.header.marked == TriColor::White), true); | ||
|
||
gc.initialize_colors(&mut vm); | ||
|
||
assert!(vm.heap.objects.values().all(|o| o.header.marked == TriColor::White)); | ||
} | ||
|
||
#[test] | ||
fn test_update_color() { | ||
let mut vm = vm_setup(); | ||
let gc = gc_setup(); | ||
|
||
let obj1 = Object::new("obj1".to_string(), TypeValue::Int(42)); | ||
let obj2 = Object::new("obj2".to_string(), TypeValue::Int(42)); | ||
|
||
vm.push(obj1).unwrap(); | ||
vm.push(obj2).unwrap(); | ||
|
||
let obj1_addr = vm.stack[0].get_address(); | ||
gc.update_color(obj1_addr, TriColor::Gray, &mut vm); | ||
|
||
assert_eq!(vm.stack[0].header.marked, TriColor::Gray); | ||
} | ||
} |
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.