Merge branch 'master' of http://github.com/mthom/rusty-wam into develop

This commit is contained in:
Mark Thom
2018-05-01 20:36:27 -06:00
5 changed files with 32 additions and 37 deletions

View File

@@ -29,9 +29,10 @@ macro_rules! try_or_fail {
// used by '$skip_max_list'.
enum CycleSearchResult {
EmptyList,
NotList,
PartialOrProperList(usize, usize), // returns the list length (up to max), and an offset into the heap.
UntouchedList(usize) // return the offset of an uniterated Addr::Lis(offset).
NotList,
PartialList(usize, usize), // the list length (up to max), and an offset into the heap.
ProperList(usize), // the list length.
UntouchedList(usize) // the address of an uniterated Addr::Lis(address).
}
impl MachineState {
@@ -1686,8 +1687,7 @@ impl MachineState {
// detect cycles.
match self.detect_cycles(usize::max_value(), a1.clone()) {
CycleSearchResult::PartialOrProperList(_, h)
if self.store(self.deref(self.heap[h].as_addr(h))).is_empty_list() => {},
CycleSearchResult::ProperList(_) => {},
_ => return Err(functor!("type_error", 2, [heap_atom!("list"), HeapCellValue::Addr(a1)]))
};
@@ -1752,7 +1752,7 @@ impl MachineState {
loop {
if steps == max_steps {
return CycleSearchResult::PartialOrProperList(steps, hare);
return CycleSearchResult::PartialList(steps, hare);
}
match self.heap[hare].clone() {
@@ -1768,13 +1768,8 @@ impl MachineState {
}
},
HeapCellValue::Addr(Addr::Con(Constant::EmptyList)) =>
return CycleSearchResult::PartialOrProperList(steps, hare),
HeapCellValue::Addr(Addr::HeapCell(hc)) if hc == hare =>
return CycleSearchResult::PartialOrProperList(steps, hare),
HeapCellValue::Addr(ref sc @ Addr::StackCell(..))
if *sc == self.store(self.deref(sc.clone())) =>
return CycleSearchResult::PartialOrProperList(steps, hare),
_ => return CycleSearchResult::NotList
return CycleSearchResult::ProperList(steps),
_ => return CycleSearchResult::PartialList(steps, hare)
}
}
}
@@ -1788,17 +1783,7 @@ impl MachineState {
self.unify(addr, xs);
}
}
/*
'$skip_max_list'(N, Max, Xs0, Xs):
valid modes: Max is always +Max (a non-negative integer), Xs, Xs0 and N are all ?_.
Modes | Conditions for success
======================================================================================
?N, -Xs0 : N = 0, Xs = Xs0.
?N, +Xs0 : Xs0 is a proper or partial list, Xs0 = [X1, X2, ..., XN | Xs], N = Max,
if |Xs0| >= Max, or, Xs = [] and N = |Xs0|.
*/
pub(super) fn skip_max_list(&mut self) {
let max = self.store(self.deref(self[temp_v!(2)].clone()));
@@ -1822,10 +1807,14 @@ impl MachineState {
self.finalize_skip_max_list(0, Addr::Lis(l)),
CycleSearchResult::EmptyList =>
self.finalize_skip_max_list(0, Addr::Con(Constant::EmptyList)),
CycleSearchResult::PartialOrProperList(n, hc) =>
CycleSearchResult::PartialList(n, hc) =>
self.finalize_skip_max_list(n, Addr::HeapCell(hc)),
CycleSearchResult::NotList =>
self.fail = true
CycleSearchResult::ProperList(n) =>
self.finalize_skip_max_list(n, Addr::Con(Constant::EmptyList)),
CycleSearchResult::NotList => {
let xs0 = self[temp_v!(3)].clone();
self.finalize_skip_max_list(0, xs0);
}
}
}
}