pub enum CycleSearchResult {
Cyclic(usize),
EmptyList,
- NotList,
+ NotList(usize, HeapCellValue), // the list length until the second argument in the heap
PartialList(usize, Ref), // the list length (up to max), and an offset into the heap.
ProperList(usize), // the list length.
PStrLocation(usize, usize), // list length (up to max), the heap address of the PStrOffset
let err = self.instantiation_error();
return Err(self.error_form(err, stub_gen()))
}
- CycleSearchResult::NotList => {
+ CycleSearchResult::NotList(..) => {
let err = self.type_error(ValidType::List, list);
return Err(self.error_form(err, stub_gen()));
}
};
match BrentAlgState::detect_cycles(&self.heap, sorted) {
- CycleSearchResult::NotList if !sorted.is_var() => {
+ CycleSearchResult::NotList(..) if !sorted.is_var() => {
let err = self.type_error(ValidType::List, sorted);
Err(self.error_form(err, stub_gen()))
}
let stub_gen = || functor_stub(atom!("keysort"), 2);
match BrentAlgState::detect_cycles(&self.heap, list) {
- CycleSearchResult::NotList if !list.is_var() => {
+ CycleSearchResult::NotList(..) if !list.is_var() => {
let err = self.type_error(ValidType::List, list);
Err(self.error_form(err, stub_gen()))
}
let err = self.instantiation_error();
Err(self.error_form(err, stub_gen()))
}
- CycleSearchResult::NotList => {
+ CycleSearchResult::NotList(..) => {
let err = self.type_error(ValidType::List, pairs);
Err(self.error_form(err, stub_gen()))
}
return if name == atom!("[]") && arity == 0 {
CycleSearchResult::ProperList(self.num_steps())
} else {
- CycleSearchResult::NotList
+ CycleSearchResult::NotList(self.num_steps(), heap[self.hare])
};
}
(HeapCellValueTag::Lis, l) => {
return CycleSearchResult::UntouchedList(self.num_steps(), l);
}
_ => {
- return CycleSearchResult::NotList;
+ return CycleSearchResult::NotList(self.num_steps(), heap[self.hare]);
}
);
}
return if name == atom!(".") && arity == 2 {
self.step(s+2)
} else {
- Some(CycleSearchResult::NotList)
+ Some(CycleSearchResult::NotList(self.num_steps(), value))
};
}
(HeapCellValueTag::Atom, (name, arity)) => {
return if name == atom!("[]") {
Some(CycleSearchResult::ProperList(self.num_steps()))
} else {
- Some(CycleSearchResult::NotList)
+ Some(CycleSearchResult::NotList(self.num_steps(), value))
};
}
(HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h) => {
self.hare = h;
}
_ => {
- return Some(CycleSearchResult::NotList);
+ return Some(CycleSearchResult::NotList(self.num_steps(), value));
}
);
}
} else if name == atom!(".") && arity == 2 {
s + 2
} else {
- return CycleSearchResult::NotList;
+ return CycleSearchResult::NotList(0, value);
}
}
(HeapCellValueTag::Atom, (name, arity)) => {
return if name == atom!("[]") && arity == 0 {
CycleSearchResult::EmptyList
} else {
- CycleSearchResult::NotList
+ CycleSearchResult::NotList(0, value)
};
}
(HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => {
return CycleSearchResult::PartialList(0, value.as_var().unwrap());
}
_ => {
- return CycleSearchResult::NotList;
+ return CycleSearchResult::NotList(0, value);
}
);
return CycleSearchResult::UntouchedList(0, s + 1);
}
} else {
- return CycleSearchResult::NotList;
+ return CycleSearchResult::NotList(0, value);
}
}
(HeapCellValueTag::Atom, (name, arity)) => {
return if name == atom!("[]") && arity == 0 {
CycleSearchResult::EmptyList
} else {
- CycleSearchResult::NotList
+ CycleSearchResult::NotList(0, value)
};
}
(HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => {
return CycleSearchResult::PartialList(0, value.as_var().unwrap());
}
_ => {
- return CycleSearchResult::NotList;
+ return CycleSearchResult::NotList(0, value);
}
);
CycleSearchResult::ProperList(steps) => {
self.finalize_skip_max_list(steps as i64, empty_list_as_cell!())
}
- CycleSearchResult::NotList => {
- let n = self.store(self.deref(self.registers[2]));
-
- self.unify_fixnum(Fixnum::build_with(max_steps), n);
- self.finalize_skip_max_list(max_steps, self.registers[3]);
+ CycleSearchResult::NotList(n, value) => {
+ self.finalize_skip_max_list(n as i64, value);
}
CycleSearchResult::Cyclic(lam) => {
self.skip_max_list_cycle(lam);