-#[cfg(test)]
-pub(crate) use crate::machine::gc::{IteratorUMP, StacklessPreOrderHeapIter};
+pub(crate) use crate::machine::gc::{CycleDetectorUMP, IteratorUMP, StacklessPreOrderHeapIter};
use crate::atom_table::*;
use crate::machine::heap::*;
}
}
-#[cfg(test)]
#[inline(always)]
pub(crate) fn stackless_preorder_iter(
heap: &mut Vec<HeapCellValue>,
- cell: HeapCellValue,
+ start: usize,
) -> StacklessPreOrderHeapIter<IteratorUMP> {
- StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, cell)
+ StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, start)
+}
+
+
+pub(crate) fn cycle_detecting_stackless_preorder_iter(
+ heap: &mut Heap,
+ start: usize,
+) -> StacklessPreOrderHeapIter<CycleDetectorUMP> {
+ StacklessPreOrderHeapIter::<CycleDetectorUMP>::new(heap, start)
}
+
#[inline(always)]
pub(crate) fn stackful_preorder_iter<'a, ElideLists: ListElisionPolicy>(
heap: &'a mut Vec<HeapCellValue>,
#[inline]
pub(crate) fn stackless_post_order_iter<'a>(
heap: &'a mut Heap,
- cell: HeapCellValue,
+ start: usize,
) -> RightistPostOrderHeapIter<'a> {
- PostOrderIterator::new(stackless_preorder_iter(heap, cell))
+ PostOrderIterator::new(stackless_preorder_iter(heap, start))
}
#[cfg(test)]
.heap
.extend(functor!(f_atom, [atom(a_atom), atom(b_atom)]));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
+
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
]
));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
+
for _ in 0..20 {
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 5);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
));
for _ in 0..200000 {
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
{
wam.machine_st.heap.push(heap_loc_as_cell!(0));
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.push(empty_list_as_cell!());
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(
assert_eq!(wam.machine_st.heap[0], pstr_cell);
assert_eq!(wam.machine_st.heap[1], heap_loc_as_cell!(1));
- wam.machine_st.heap.pop();
- wam.machine_st.heap.push(pstr_loc_as_cell!(2));
+ wam.machine_st.heap[1] = pstr_loc_as_cell!(3);
let pstr_second_var_cell =
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- heap_loc_as_cell!(3),
+ heap_loc_as_cell!(4),
);
assert!(iter.next().is_none());
}
assert_eq!(wam.machine_st.heap[0], pstr_cell);
- assert_eq!(wam.machine_st.heap[1], pstr_loc_as_cell!(2));
- assert_eq!(wam.machine_st.heap[2], pstr_second_cell);
- assert_eq!(wam.machine_st.heap[3], heap_loc_as_cell!(3));
+ assert_eq!(wam.machine_st.heap[1], pstr_loc_as_cell!(3));
+ assert_eq!(wam.machine_st.heap[2], pstr_loc_as_cell!(0));
+ assert_eq!(wam.machine_st.heap[3], pstr_second_cell);
+ assert_eq!(wam.machine_st.heap[4], heap_loc_as_cell!(4));
wam.machine_st.heap.pop();
- wam.machine_st.heap.push(pstr_loc_as_cell!(4));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(5));
wam.machine_st.heap.push(pstr_offset_as_cell!(0));
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(2)));
+ wam.machine_st.heap[2] = heap_loc_as_cell!(4);
+
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(4));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
let pstr_offset_cell = pstr_offset_as_cell!(0);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
+ assert_eq!(unmark_cell_bits!(iter.next().unwrap()), fixnum_as_cell!(Fixnum::build_with(2)));
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
+ pstr_loc_as_cell!(3)
);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ unmark_cell_bits!(wam.machine_st.heap[4]),
+ pstr_loc_as_cell!(5)
);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[4]),
+ unmark_cell_bits!(wam.machine_st.heap[5]),
pstr_offset_as_cell!(0)
);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[5]),
+ unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
.heap
.push(fixnum_as_cell!(Fixnum::build_with(0i64)));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 6);
let pstr_offset_cell = pstr_offset_as_cell!(0);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
- assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_loc_as_cell!(4));
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
+ assert_eq!(unmark_cell_bits!(iter.next().unwrap()), fixnum_as_cell!(Fixnum::build_with(0)));
assert_eq!(iter.next(), None);
}
all_cells_unmarked(&wam.machine_st.heap);
- wam.machine_st.heap.pop();
- wam.machine_st
- .heap
- .push(fixnum_as_cell!(Fixnum::build_with(1i64)));
+ wam.machine_st.heap[5] = fixnum_as_cell!(Fixnum::build_with(1i64));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 6);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
- assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_loc_as_cell!(4));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
);
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ fixnum_as_cell!(Fixnum::build_with(1))
+ );
assert_eq!(iter.next(), None);
-
- assert_eq!(iter.heap[4], pstr_offset_as_cell!(0));
- assert_eq!(iter.heap[5], fixnum_as_cell!(Fixnum::build_with(1i64)));
}
+ assert_eq!(wam.machine_st.heap[4], pstr_offset_as_cell!(0));
+ assert_eq!(wam.machine_st.heap[5], fixnum_as_cell!(Fixnum::build_with(1i64)));
+
all_cells_unmarked(&wam.machine_st.heap);
wam.machine_st.heap.clear();
wam.machine_st.heap.extend(functor);
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(f_atom, 3)
);
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(a_atom)
- );
-
assert_eq!(iter.next(), None);
}
all_cells_unmarked(&wam.machine_st.heap);
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
assert_eq!(wam.machine_st.heap[4], empty_list_as_cell!());
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap[4] = list_loc_as_cell!(1);
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(f_atom, 3)
);
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(a_atom)
- );
-
assert_eq!(iter.next(), None);
}
wam.machine_st.heap.push(heap_loc_as_cell!(2));
wam.machine_st.heap.push(heap_loc_as_cell!(3));
wam.machine_st.heap.push(heap_loc_as_cell!(3));
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 4);
assert_eq!(iter.next().unwrap(), heap_loc_as_cell!(3));
-
assert_eq!(iter.next(), None);
}
wam.machine_st.heap.push(list_loc_as_cell!(1));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
assert_eq!(
);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
- // this is what happens! this next line! We would like it not to happen though.
- assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
-
assert_eq!(iter.next(), None);
}
wam.machine_st.heap.push(attr_var_as_cell!(11)); // linked from 7.
wam.machine_st.heap.push(heap_loc_as_cell!(12));
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 13);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
let clpz_atom = atom!("clpz");
let p_atom = atom!("p");
+ wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st.heap.push(heap_loc_as_cell!(13)); // 12
wam.machine_st.heap.push(empty_list_as_cell!()); // 21
wam.machine_st.heap.push(atom_as_cell!(p_atom, 1)); // 22
wam.machine_st.heap.push(heap_loc_as_cell!(23)); // 23
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 24);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
wam.machine_st.heap.clear();
{
- let mut iter = stackless_preorder_iter(
- &mut wam.machine_st.heap,
- fixnum_as_cell!(Fixnum::build_with(0)),
- );
+ wam.machine_st.heap.push(fixnum_as_cell!(Fixnum::build_with(0)));
+
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
all_cells_unmarked(&wam.machine_st.heap);
- assert_eq!(wam.machine_st.heap.len(), 0);
-
wam.machine_st.heap.clear();
wam.machine_st.heap.push(str_loc_as_cell!(1));
wam.machine_st.heap.push(atom_as_cell!(atom!("y")));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(1));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(atom!("y"))
);
- assert_eq!(unmark_cell_bits!(iter.next().unwrap()), str_loc_as_cell!(1));
+ assert_eq!(unmark_cell_bits!(iter.next().unwrap()), heap_loc_as_cell!(0));
assert!(iter.next().is_none());
}
wam.machine_st.heap.push(atom_as_cell!(atom!("g"), 2));
wam.machine_st.heap.push(str_loc_as_cell!(0));
wam.machine_st.heap.push(atom_as_cell!(atom!("y")));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.push(empty_list_as_cell!());
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(7));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 7);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.push(atom_as_cell!(atom!("f"), 2));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
{
- let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.clear();
// representation of one of the heap terms as in issue #1384.
- /*
- wam.machine_st.heap.push(list_loc_as_cell!(7));
- wam.machine_st.heap.push(heap_loc_as_cell!(0));
- wam.machine_st.heap.push(list_loc_as_cell!(3));
- wam.machine_st.heap.push(list_loc_as_cell!(5));
- wam.machine_st.heap.push(empty_list_as_cell!());
- wam.machine_st.heap.push(heap_loc_as_cell!(2));
- wam.machine_st.heap.push(heap_loc_as_cell!(2));
- wam.machine_st.heap.push(empty_list_as_cell!());
- wam.machine_st.heap.push(heap_loc_as_cell!(3));
-
- {
- let mut iter = stackless_preorder_iter(
- &mut wam.machine_st.heap,
- heap_loc_as_cell!(0),
- );
+ wam.machine_st.heap.push(list_loc_as_cell!(7)); // 0
+ wam.machine_st.heap.push(heap_loc_as_cell!(0)); // 1
+ wam.machine_st.heap.push(list_loc_as_cell!(3)); // 2
+ wam.machine_st.heap.push(list_loc_as_cell!(5)); // 3
+ wam.machine_st.heap.push(empty_list_as_cell!()); // 4
+ wam.machine_st.heap.push(heap_loc_as_cell!(2)); // 5
+ wam.machine_st.heap.push(heap_loc_as_cell!(2)); // 6
+ wam.machine_st.heap.push(empty_list_as_cell!()); // 7
+ wam.machine_st.heap.push(heap_loc_as_cell!(3)); // 8
- while let Some(_) = iter.next() {
- print_heap_terms(iter.heap.iter(), 0);
- println!("");
- }
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
- /*
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(atom!("f"), 2)
- );
+ {
+ let mut iter = stackless_preorder_iter(
+ &mut wam.machine_st.heap,
+ 9,
+ );
- assert!(iter.next().is_none());
- */
- }
- */
+ /*
+ while let Some(_) = iter.next() {
+ print_heap_terms(iter.heap.iter(), 0);
+ println!("");
+ }
+ */
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ list_loc_as_cell!(7)
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ list_loc_as_cell!(5)
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ heap_loc_as_cell!(2)
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ list_loc_as_cell!(3)
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ empty_list_as_cell!()
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ heap_loc_as_cell!(2)
+ );
+
+ assert_eq!(
+ unmark_cell_bits!(iter.next().unwrap()),
+ empty_list_as_cell!()
+ );
+
+ assert_eq!(iter.next(), None);
+ }
}
#[test]
.heap
.extend(functor!(f_atom, [atom(a_atom), atom(b_atom)]));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
+
{
- let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
]
));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
+
for _ in 0..20 {
- let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 5);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), str_loc_as_cell!(0));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
{
let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
{
let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ stackless_post_order_iter(&mut wam.machine_st.heap, 0);
// the cycle will be iterated twice before being detected.
assert_eq!(
{
let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ stackless_post_order_iter(&mut wam.machine_st.heap, 0);
// cut the iteration short to check that all cells are
// unmarked and unforwarded by the Drop instance of
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ stackless_post_order_iter(&mut wam.machine_st.heap, 2);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
assert_eq!(iter.next(), None);
}
+ wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 4);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
.heap
.push(fixnum_as_cell!(Fixnum::build_with(0)));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 7);
let mut pstr_loc_cell = pstr_loc_as_cell!(0);
pstr_loc_cell.set_forwarding_bit(true);
// assert_eq!(iter.next().unwrap(), fixnum_as_cell!(Fixnum::build_with(0i64)));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- pstr_offset_as_cell!(0)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- pstr_offset_as_cell!(0)
+ heap_loc_as_cell!(3)
);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
all_cells_unmarked(&wam.machine_st.heap);
+ wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(1)));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(0));
+
{
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 7);
//assert_eq!(iter.next().unwrap(), fixnum_as_cell!(Fixnum::build_with(1)));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- pstr_offset_as_cell!(0)
+ heap_loc_as_cell!(3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- pstr_offset_as_cell!(0)
+ pstr_second_cell
);
-
- assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
-
assert_eq!(iter.next(), None);
}
wam.machine_st.heap.extend(functor);
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
+
{
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 9);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(3)
);
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(a_atom)
- );
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(f_atom, 3)
wam.machine_st.heap[4] = list_loc_as_cell!(1);
{
- let mut iter =
- stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(b_atom)
- );
- assert_eq!(
- unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(a_atom)
+ atom_as_cell!(f_atom, 3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
- atom_as_cell!(f_atom, 3)
+ list_loc_as_cell!(1)
);
- assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
-
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(3)
#[cfg(test)]
use crate::heap_iter::{FocusedHeapIter, HeapOrStackTag, IterStackLoc};
-use core::marker::PhantomData;
-
pub(crate) trait UnmarkPolicy {
- fn unmark(heap: &mut [HeapCellValue], current: usize);
- fn mark(heap: &mut [HeapCellValue], current: usize);
fn forward_attr_var(iter: &mut StacklessPreOrderHeapIter<Self>) -> Option<HeapCellValue>
where
Self: Sized;
+ fn invert_marker(iter: &mut StacklessPreOrderHeapIter<Self>) where Self: Sized;
+ fn cycle_detected(&mut self) where Self: Sized;
+ fn mark_phase(&self) -> bool;
+ fn report_list(&mut self, list_loc: usize);
+}
+
+pub(crate) struct IteratorUMP {
+ mark_phase: bool,
}
-pub(crate) struct IteratorUMP;
+fn invert_marker<UMP: UnmarkPolicy>(iter: &mut StacklessPreOrderHeapIter<UMP>) {
+ if iter.heap[iter.start].get_forwarding_bit() {
+ while !iter.backward() {}
+ }
+
+ iter.heap[iter.start].set_forwarding_bit(true);
+
+ iter.next = iter.heap[iter.start].get_value();
+ iter.current = iter.start;
+
+ while let Some(_) = iter.forward() {}
+}
impl UnmarkPolicy for IteratorUMP {
#[inline(always)]
- fn unmark(heap: &mut [HeapCellValue], current: usize) {
- heap[current].set_mark_bit(false);
+ fn forward_attr_var(iter: &mut StacklessPreOrderHeapIter<Self>) -> Option<HeapCellValue> {
+ iter.forward_var()
+ }
+
+ #[inline]
+ fn invert_marker(iter: &mut StacklessPreOrderHeapIter<Self>) {
+ iter.iter_state.mark_phase = false;
+ invert_marker(iter);
}
#[inline(always)]
- fn mark(_heap: &mut [HeapCellValue], _current: usize) {}
+ fn cycle_detected(&mut self) {}
+
+ #[inline]
+ fn mark_phase(&self) -> bool {
+ self.mark_phase
+ }
+ #[inline(always)]
+ fn report_list(&mut self, _list_loc: usize) {}
+}
+
+pub(crate) struct CycleDetectorUMP {
+ mark_phase: bool,
+ cycle_detected: bool,
+ list_locs: Vec<usize>,
+}
+
+impl UnmarkPolicy for CycleDetectorUMP {
#[inline(always)]
fn forward_attr_var(iter: &mut StacklessPreOrderHeapIter<Self>) -> Option<HeapCellValue> {
iter.forward_var()
}
-}
-struct MarkerUMP {}
+ #[inline]
+ fn invert_marker(iter: &mut StacklessPreOrderHeapIter<Self>) {
+ iter.iter_state.mark_phase = false;
+ invert_marker(iter);
+ }
-impl UnmarkPolicy for MarkerUMP {
- #[inline(always)]
- fn unmark(_heap: &mut [HeapCellValue], _current: usize) {}
+ #[inline]
+ fn cycle_detected(&mut self) {
+ self.cycle_detected = true;
+ }
#[inline(always)]
- fn mark(heap: &mut [HeapCellValue], current: usize) {
- heap[current].set_mark_bit(true);
+ fn mark_phase(&self) -> bool {
+ self.mark_phase
+ }
+
+ #[inline]
+ fn report_list(&mut self, list_loc: usize) {
+ self.list_locs.push(list_loc);
}
+}
+struct MarkerUMP {}
+
+impl UnmarkPolicy for MarkerUMP {
#[inline(always)]
fn forward_attr_var(iter: &mut StacklessPreOrderHeapIter<Self>) -> Option<HeapCellValue> {
if iter.heap[iter.current + 1].get_forwarding_bit() {
iter.heap[iter.current].set_forwarding_bit(true); // forward the attr vars list.
None
}
+
+ fn invert_marker(_iter: &mut StacklessPreOrderHeapIter<Self>) {}
+
+ #[inline(always)]
+ fn mark_phase(&self) -> bool {
+ true
+ }
+
+ #[inline(always)]
+ fn cycle_detected(&mut self) {}
+
+ #[inline(always)]
+ fn report_list(&mut self, _list_loc: usize) {}
}
#[derive(Debug)]
pub(crate) struct StacklessPreOrderHeapIter<'a, UMP: UnmarkPolicy> {
- pub(crate) heap: &'a mut Vec<HeapCellValue>,
- orig_heap_len: usize,
+ pub(crate) heap: &'a mut [HeapCellValue],
start: usize,
current: usize,
next: u64,
- _marker: PhantomData<UMP>,
+ iter_state: UMP,
}
#[cfg(test)]
impl<'a, UMP: UnmarkPolicy> Drop for StacklessPreOrderHeapIter<'a, UMP> {
fn drop(&mut self) {
+ UMP::invert_marker(self);
+
if self.current == self.start {
- self.heap.truncate(self.orig_heap_len);
return;
}
while !self.backward() {}
-
- self.heap.truncate(self.orig_heap_len);
}
}
impl<'a> StacklessPreOrderHeapIter<'a, MarkerUMP> {
- pub(crate) fn new(heap: &'a mut Vec<HeapCellValue>, cell: HeapCellValue) -> Self {
- let orig_heap_len = heap.len();
- let start = orig_heap_len;
+ pub(crate) fn new(heap: &'a mut [HeapCellValue], start: usize) -> Self {
+ heap[start].set_forwarding_bit(true);
+ let next = heap[start].get_value();
- heap.push(cell);
+ Self {
+ heap,
+ start,
+ current: start,
+ next,
+ iter_state: MarkerUMP {},
+ }
+ }
+}
+impl<'a> StacklessPreOrderHeapIter<'a, CycleDetectorUMP> {
+ pub(crate) fn new(heap: &'a mut [HeapCellValue], start: usize) -> Self {
heap[start].set_forwarding_bit(true);
let next = heap[start].get_value();
Self {
heap,
- orig_heap_len,
start,
current: start,
next,
- _marker: PhantomData,
+ iter_state: CycleDetectorUMP {
+ mark_phase: true,
+ cycle_detected: false,
+ list_locs: vec![],
+ },
}
}
-}
-impl<'a> StacklessPreOrderHeapIter<'a, IteratorUMP> {
- #[cfg(test)]
- pub(crate) fn new(heap: &'a mut Vec<HeapCellValue>, cell: HeapCellValue) -> Self {
- let orig_heap_len = heap.len();
- let start = orig_heap_len + 1;
+ #[inline]
+ pub(crate) fn found_cycle(&self) -> bool {
+ self.iter_state.cycle_detected
+ }
- heap.push(cell);
- heap.push(heap_loc_as_cell!(orig_heap_len));
+ #[inline]
+ pub(crate) fn list_locs(mut self) -> Vec<usize> {
+ std::mem::replace(&mut self.iter_state.list_locs, vec![])
+ }
+}
+impl<'a> StacklessPreOrderHeapIter<'a, IteratorUMP> {
+ pub(crate) fn new(heap: &'a mut [HeapCellValue], start: usize) -> Self {
heap[start].set_forwarding_bit(true);
let next = heap[start].get_value();
Self {
heap,
- orig_heap_len,
start,
current: start,
next,
- _marker: PhantomData,
+ iter_state: IteratorUMP {
+ mark_phase: true,
+ },
}
}
}
impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
- fn backward_and_return(&mut self) -> Option<HeapCellValue> {
- let current = self.current;
+ fn backward_and_return(&mut self) -> HeapCellValue {
+ let mut current = self.heap[self.current];
+ current.set_value(self.next);
if self.backward() {
// set the f and m bits on the heap cell at start
// so we invoke backward() and return None next call.
self.heap[self.current].set_forwarding_bit(true);
- self.heap[self.current].set_mark_bit(true);
+ self.heap[self.current].set_mark_bit(self.iter_state.mark_phase());
}
- Some(self.heap[current])
+ current
}
fn forward_var(&mut self) -> Option<HeapCellValue> {
if self.heap[self.next as usize].get_forwarding_bit() {
- return self.backward_and_return();
+ return Some(self.backward_and_return());
}
let temp = self.heap[self.next as usize].get_value();
fn forward(&mut self) -> Option<HeapCellValue> {
loop {
- if !self.heap[self.current].get_mark_bit() {
- self.heap[self.current].set_mark_bit(true);
+ if self.heap[self.current].get_mark_bit() != self.iter_state.mark_phase() {
+ self.heap[self.current].set_mark_bit(self.iter_state.mark_phase());
match self.heap[self.current].get_tag() {
HeapCellValueTag::AttrVar => {
+ let next = self.next;
+
if let Some(cell) = UMP::forward_attr_var(self) {
return Some(cell);
}
- if self.heap[self.next as usize].get_mark_bit() {
- return Some(attr_var_as_cell!(self.current));
+ if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
+ let tag = HeapCellValueTag::AttrVar;
+ return Some(HeapCellValue::build_with(tag, next));
}
}
HeapCellValueTag::Var => {
+ let next = self.next;
+
if let Some(cell) = self.forward_var() {
return Some(cell);
}
- if self.heap[self.next as usize].get_mark_bit() {
- return Some(heap_loc_as_cell!(self.current));
+ if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
+ let tag = HeapCellValueTag::Var;
+ return Some(HeapCellValue::build_with(tag, next));
}
}
HeapCellValueTag::Str => {
if self.heap[self.next as usize + 1].get_forwarding_bit() {
- return self.backward_and_return();
+ self.iter_state.cycle_detected();
+ return Some(self.backward_and_return());
}
let h = self.next as usize;
let last_cell_loc = self.next as usize + 1;
if self.heap[last_cell_loc].get_forwarding_bit() {
- return self.backward_and_return();
+ self.iter_state.cycle_detected();
+ return Some(self.backward_and_return());
}
- self.heap[last_cell_loc].set_forwarding_bit(true);
-
self.next = self.heap[last_cell_loc].get_value();
self.heap[last_cell_loc].set_value(self.current as u64);
self.current = last_cell_loc;
+ self.heap[last_cell_loc].set_forwarding_bit(true);
+
+ if self.heap[last_cell_loc].get_mark_bit() == self.iter_state.mark_phase() {
+ if self.heap[last_cell_loc-1].get_mark_bit() == self.iter_state.mark_phase() {
+ self.iter_state.report_list(last_cell_loc - 1);
+ }
+ }
+
return Some(list_loc_as_cell!(last_cell_loc - 1));
}
HeapCellValueTag::PStrLoc => {
let h = self.next as usize;
- let cell = self.heap[h];
if self.heap[h + 1].get_forwarding_bit() {
- return self.backward_and_return();
+ self.iter_state.cycle_detected();
+ return Some(self.backward_and_return());
}
- if self.heap[h].get_tag() == HeapCellValueTag::PStr {
- let last_cell_loc = h + 1;
- self.heap[last_cell_loc].set_forwarding_bit(true);
-
- self.next = self.heap[last_cell_loc].get_value();
- self.heap[last_cell_loc].set_value(self.current as u64);
- self.current = last_cell_loc;
- } else {
- debug_assert!(self.heap[h].get_tag() == HeapCellValueTag::PStrOffset);
+ let cell = self.heap[h];
- self.next = self.heap[h].get_value();
- self.heap[h].set_value(self.current as u64);
- self.current = h;
+ let last_cell_loc = h + 1;
+ self.heap[last_cell_loc].set_forwarding_bit(true);
- if self.heap[h].get_mark_bit() {
- continue;
- }
- }
+ self.next = self.heap[last_cell_loc].get_value();
+ self.heap[last_cell_loc].set_value(self.current as u64);
+ self.current = last_cell_loc;
return Some(cell);
}
let h = self.next as usize;
let cell = self.heap[h];
- // mark the Fixnum offset.
- UMP::mark(self.heap, self.current + 1);
-
let last_cell_loc = h + 1;
if self.heap[last_cell_loc].get_forwarding_bit() {
- return self.backward_and_return();
+ self.iter_state.cycle_detected();
+ return Some(self.backward_and_return());
}
if self.heap[h].get_tag() == HeapCellValueTag::PStr {
let arity = AtomCell::from_bytes(cell.into_bytes()).get_arity();
if arity == 0 {
- return self.backward_and_return();
+ return Some(self.backward_and_return());
} else if self.backward() {
return None;
}
}
}
_ => {
- return self.backward_and_return();
+ return Some(self.backward_and_return());
}
}
} else {
while !self.heap[self.current].get_forwarding_bit() {
let temp = self.heap[self.current].get_value();
- UMP::unmark(self.heap, self.current);
-
self.heap[self.current].set_value(self.next);
+
self.next = self.current as u64;
self.current = temp as usize;
}
self.heap[self.current].set_forwarding_bit(false);
- UMP::unmark(self.heap, self.current);
if self.current == self.start {
return true;
}
}
-pub fn mark_cells(heap: &mut Heap, cell: HeapCellValue) {
- let mut iter = StacklessPreOrderHeapIter::<MarkerUMP>::new(heap, cell);
+pub fn mark_cells(heap: &mut Heap, start: usize) {
+ let mut iter = StacklessPreOrderHeapIter::<MarkerUMP>::new(heap, start);
while let Some(_) = iter.forward() {}
}
let a_atom = atom!("a");
let b_atom = atom!("b");
+ wam.machine_st.heap.push(str_loc_as_cell!(1));
+
wam.machine_st
.heap
.extend(functor!(f_atom, [atom(a_atom), atom(b_atom)]));
- mark_cells(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[0]),
- atom_as_cell!(f_atom, 2)
+ str_loc_as_cell!(1)
);
+
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[1]),
- atom_as_cell!(a_atom)
+ atom_as_cell!(f_atom, 2)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[2]),
+ atom_as_cell!(a_atom)
+ );
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[3]),
atom_as_cell!(b_atom)
);
wam.machine_st.heap.clear();
+ wam.machine_st.heap.push(str_loc_as_cell!(1));
+
wam.machine_st.heap.extend(functor!(
f_atom,
[
atom(a_atom),
atom(b_atom),
atom(a_atom),
- cell(str_loc_as_cell!(0))
+ cell(str_loc_as_cell!(1))
]
));
- mark_cells(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[0]),
- atom_as_cell!(f_atom, 4)
+ str_loc_as_cell!(1)
);
+
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[1]),
- atom_as_cell!(a_atom)
+ atom_as_cell!(f_atom, 4)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[2]),
- atom_as_cell!(b_atom)
+ atom_as_cell!(a_atom)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[3]),
- atom_as_cell!(a_atom)
+ atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
- str_loc_as_cell!(0)
+ atom_as_cell!(a_atom)
+ );
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[5]),
+ str_loc_as_cell!(1)
);
for cell in &mut wam.machine_st.heap {
}
// make the structure doubly cyclic.
- wam.machine_st.heap[2] = str_loc_as_cell!(0);
+ wam.machine_st.heap[2] = str_loc_as_cell!(1);
- mark_cells(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
]
));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(heap_loc_as_cell!(0));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(atom_as_cell!(b_atom));
wam.machine_st.heap.push(empty_list_as_cell!());
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
// now make the list cyclic.
wam.machine_st.heap.push(heap_loc_as_cell!(0));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
// make the list doubly cyclic.
wam.machine_st.heap[3] = heap_loc_as_cell!(0);
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(stream_cell);
wam.machine_st.heap.push(empty_list_as_cell!());
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(heap_loc_as_cell!(3));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
// two-part complete string, then a three-part cyclic string
// involving an uncompacted list of chars.
- let pstr_var_cell =
- put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
+ wam.machine_st.heap.push(pstr_loc_as_cell!(1));
+
+ let pstr_var_cell = put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_loc_as_cell!(1));
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- heap_loc_as_cell!(1)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ heap_loc_as_cell!(2)
);
wam.machine_st.heap.pop();
cell.set_mark_bit(false);
}
- wam.machine_st.heap.push(pstr_loc_as_cell!(2));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(3));
let pstr_second_var_cell =
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- heap_loc_as_cell!(3)
+ unmark_cell_bits!(wam.machine_st.heap[4]),
+ heap_loc_as_cell!(4)
);
for cell in &mut wam.machine_st.heap {
}
wam.machine_st.heap.pop();
- wam.machine_st.heap.push(pstr_loc_as_cell!(4));
- wam.machine_st.heap.push(pstr_offset_as_cell!(0));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(5));
+ wam.machine_st.heap.push(pstr_offset_as_cell!(1));
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(2)));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(5));
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(4));
+ mark_cells(&mut wam.machine_st.heap, 7);
- all_cells_marked_and_unforwarded(&wam.machine_st.heap);
+ all_cells_marked_and_unforwarded(&wam.machine_st.heap[1 ..]);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
- pstr_offset_as_cell!(0)
+ pstr_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
- fixnum_as_cell!(Fixnum::build_with(2))
- );
-
- for cell in &mut wam.machine_st.heap {
- cell.set_mark_bit(false);
- }
-
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(3));
-
- all_cells_marked_and_unforwarded(&wam.machine_st.heap);
-
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ pstr_offset_as_cell!(1)
);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[4]),
- pstr_offset_as_cell!(0)
+ unmark_cell_bits!(wam.machine_st.heap[6]),
+ fixnum_as_cell!(Fixnum::build_with(2))
);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[5]),
- fixnum_as_cell!(Fixnum::build_with(2))
+ unmark_cell_bits!(wam.machine_st.heap[7]),
+ pstr_loc_as_cell!(5)
);
for cell in &mut wam.machine_st.heap {
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(2));
+ wam.machine_st.heap[7] = heap_loc_as_cell!(2);
- all_cells_marked_and_unforwarded(&wam.machine_st.heap);
+ mark_cells(&mut wam.machine_st.heap, 7);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ all_cells_marked_and_unforwarded(&wam.machine_st.heap[1..]);
+
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
- pstr_offset_as_cell!(0)
+ pstr_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
+ pstr_offset_as_cell!(1)
+ );
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[7]),
+ heap_loc_as_cell!(2)
+ );
for cell in &mut wam.machine_st.heap {
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(1));
+ wam.machine_st.heap[7] = pstr_loc_as_cell!(1);
- all_cells_marked_and_unforwarded(&wam.machine_st.heap);
+ mark_cells(&mut wam.machine_st.heap, 7);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ all_cells_marked_and_unforwarded(&wam.machine_st.heap[1..]);
+
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
- pstr_offset_as_cell!(0)
+ pstr_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
+ pstr_offset_as_cell!(1)
+ );
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[7]),
+ pstr_loc_as_cell!(1)
+ );
for cell in &mut wam.machine_st.heap {
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
+ wam.machine_st.heap[7] = heap_loc_as_cell!(0);
- all_cells_marked_and_unforwarded(&wam.machine_st.heap);
+ mark_cells(&mut wam.machine_st.heap, 7);
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ all_cells_marked_and_unforwarded(&wam.machine_st.heap[1..]);
+
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(4)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
- pstr_offset_as_cell!(0)
+ pstr_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
+ pstr_offset_as_cell!(1)
+ );
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[7]),
+ heap_loc_as_cell!(0)
+ );
wam.machine_st.heap.truncate(4);
wam.machine_st
.heap
.push(atom_as_cell!(atom!("irrelevant stuff")));
- wam.machine_st.heap.push(pstr_offset_as_cell!(0));
+ wam.machine_st.heap.push(pstr_offset_as_cell!(1));
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(2)));
- wam.machine_st.heap[3] = pstr_loc_as_cell!(5);
+ // this is at index 7
+ wam.machine_st.heap.push(pstr_loc_as_cell!(5));
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(5));
+ mark_cells(&mut wam.machine_st.heap, 7);
- assert!(wam.machine_st.heap[0].get_mark_bit());
+ assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
assert!(wam.machine_st.heap[2].get_mark_bit());
assert!(wam.machine_st.heap[3].get_mark_bit());
- assert!(!wam.machine_st.heap[4].get_mark_bit());
+ assert!(wam.machine_st.heap[4].get_mark_bit());
assert!(wam.machine_st.heap[5].get_mark_bit());
assert!(wam.machine_st.heap[6].get_mark_bit());
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
- assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[1]),
- pstr_loc_as_cell!(2)
- );
- assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[1]), pstr_cell);
assert_eq!(
- unmark_cell_bits!(wam.machine_st.heap[3]),
- pstr_loc_as_cell!(5)
+ unmark_cell_bits!(wam.machine_st.heap[2]),
+ pstr_loc_as_cell!(3)
);
+ assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
atom_as_cell!(atom!("irrelevant stuff"))
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
- pstr_offset_as_cell!(0)
+ pstr_offset_as_cell!(1)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
+ assert_eq!(
+ unmark_cell_bits!(wam.machine_st.heap[7]),
+ pstr_loc_as_cell!(5)
+ );
wam.machine_st.heap.clear();
.heap
.push(fixnum_as_cell!(Fixnum::build_with(2)));
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(7));
+ wam.machine_st.heap.push(pstr_loc_as_cell!(7));
+
+ mark_cells(&mut wam.machine_st.heap, 9);
assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(5));
+ wam.machine_st.heap[9] = heap_loc_as_cell!(5);
+
+ mark_cells(&mut wam.machine_st.heap, 9);
assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(4));
+ wam.machine_st.heap[9] = pstr_loc_as_cell!(4);
+
+ mark_cells(&mut wam.machine_st.heap, 9);
assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(2));
+ mark_cells(&mut wam.machine_st.heap, 9);
+
+ wam.machine_st.heap[9] = heap_loc_as_cell!(2);
assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
cell.set_mark_bit(false);
}
- mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(1));
+ wam.machine_st.heap[9] = pstr_loc_as_cell!(1);
+
+ mark_cells(&mut wam.machine_st.heap, 9);
assert!(!wam.machine_st.heap[0].get_mark_bit());
assert!(wam.machine_st.heap[1].get_mark_bit());
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
wam.machine_st.heap.push(empty_list_as_cell!());
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(4));
+ mark_cells(&mut wam.machine_st.heap, 4);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
wam.machine_st.heap.push(heap_loc_as_cell!(4));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(4));
+ mark_cells(&mut wam.machine_st.heap, 4);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(heap_loc_as_cell!(3));
wam.machine_st.heap.push(heap_loc_as_cell!(3));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(list_loc_as_cell!(1));
wam.machine_st.heap.push(list_loc_as_cell!(1));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(attr_var_as_cell!(11)); // linked from 7.
wam.machine_st.heap.push(heap_loc_as_cell!(12));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(atom_as_cell!(p_atom, 1)); // 22
wam.machine_st.heap.push(heap_loc_as_cell!(23)); // 23
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(heap_loc_as_cell!(5));
wam.machine_st.heap.push(list_loc_as_cell!(5));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&mut wam.machine_st.heap[0..24]);
.heap
.push(fixnum_as_cell!(Fixnum::build_with(0)));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
assert_eq!(wam.machine_st.heap.len(), 1);
wam.machine_st.heap.push(str_loc_as_cell!(4));
wam.machine_st.heap.push(empty_list_as_cell!());
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(7));
+ mark_cells(&mut wam.machine_st.heap, 7);
assert_eq!(wam.machine_st.heap.len(), 10);
wam.machine_st.heap.push(atom_as_cell!(atom!("f"), 2));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
+ wam.machine_st.heap.push(str_loc_as_cell!(0));
- mark_cells(&mut wam.machine_st.heap, str_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 3);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(empty_list_as_cell!());
wam.machine_st.heap.push(heap_loc_as_cell!(2));
- mark_cells(&mut wam.machine_st.heap, list_loc_as_cell!(5));
+ wam.machine_st.heap.push(list_loc_as_cell!(5));
+
+ mark_cells(&mut wam.machine_st.heap, 7);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);
wam.machine_st.heap.push(heap_loc_as_cell!(2));
wam.machine_st.heap.push(empty_list_as_cell!()); // C = [[]|B].
wam.machine_st.heap.push(heap_loc_as_cell!(3));
+ wam.machine_st.heap.push(heap_loc_as_cell!(0));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 9);
assert!(wam.machine_st.heap[0].get_mark_bit());
assert!(!wam.machine_st.heap[1].get_mark_bit());
.heap
.push(fixnum_as_cell!(Fixnum::build_with(4)));
- mark_cells(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
+ mark_cells(&mut wam.machine_st.heap, 0);
all_cells_marked_and_unforwarded(&wam.machine_st.heap);