correct '$skip_max_list/4' for non-lists (#1276)

This commit is contained in:
Mark Thom
2022-02-20 23:44:18 -07:00
parent c893247107
commit 063f0da565
2 changed files with 18 additions and 21 deletions

View File

@@ -771,7 +771,7 @@ impl EvalError {
pub enum CycleSearchResult { pub enum CycleSearchResult {
Cyclic(usize), Cyclic(usize),
EmptyList, 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. PartialList(usize, Ref), // the list length (up to max), and an offset into the heap.
ProperList(usize), // the list length. ProperList(usize), // the list length.
PStrLocation(usize, usize), // list length (up to max), the heap address of the PStrOffset PStrLocation(usize, usize), // list length (up to max), the heap address of the PStrOffset
@@ -792,7 +792,7 @@ impl MachineState {
let err = self.instantiation_error(); let err = self.instantiation_error();
return Err(self.error_form(err, stub_gen())) return Err(self.error_form(err, stub_gen()))
} }
CycleSearchResult::NotList => { CycleSearchResult::NotList(..) => {
let err = self.type_error(ValidType::List, list); let err = self.type_error(ValidType::List, list);
return Err(self.error_form(err, stub_gen())); return Err(self.error_form(err, stub_gen()));
} }
@@ -800,7 +800,7 @@ impl MachineState {
}; };
match BrentAlgState::detect_cycles(&self.heap, sorted) { 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); let err = self.type_error(ValidType::List, sorted);
Err(self.error_form(err, stub_gen())) Err(self.error_form(err, stub_gen()))
} }
@@ -812,7 +812,7 @@ impl MachineState {
let stub_gen = || functor_stub(atom!("keysort"), 2); let stub_gen = || functor_stub(atom!("keysort"), 2);
match BrentAlgState::detect_cycles(&self.heap, list) { 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); let err = self.type_error(ValidType::List, list);
Err(self.error_form(err, stub_gen())) Err(self.error_form(err, stub_gen()))
} }
@@ -878,7 +878,7 @@ impl MachineState {
let err = self.instantiation_error(); let err = self.instantiation_error();
Err(self.error_form(err, stub_gen())) Err(self.error_form(err, stub_gen()))
} }
CycleSearchResult::NotList => { CycleSearchResult::NotList(..) => {
let err = self.type_error(ValidType::List, pairs); let err = self.type_error(ValidType::List, pairs);
Err(self.error_form(err, stub_gen())) Err(self.error_form(err, stub_gen()))
} }

View File

@@ -164,14 +164,14 @@ impl BrentAlgState {
return if name == atom!("[]") && arity == 0 { return if name == atom!("[]") && arity == 0 {
CycleSearchResult::ProperList(self.num_steps()) CycleSearchResult::ProperList(self.num_steps())
} else { } else {
CycleSearchResult::NotList CycleSearchResult::NotList(self.num_steps(), heap[self.hare])
}; };
} }
(HeapCellValueTag::Lis, l) => { (HeapCellValueTag::Lis, l) => {
return CycleSearchResult::UntouchedList(self.num_steps(), l); return CycleSearchResult::UntouchedList(self.num_steps(), l);
} }
_ => { _ => {
return CycleSearchResult::NotList; return CycleSearchResult::NotList(self.num_steps(), heap[self.hare]);
} }
); );
} }
@@ -231,7 +231,7 @@ impl BrentAlgState {
return if name == atom!(".") && arity == 2 { return if name == atom!(".") && arity == 2 {
self.step(s+2) self.step(s+2)
} else { } else {
Some(CycleSearchResult::NotList) Some(CycleSearchResult::NotList(self.num_steps(), value))
}; };
} }
(HeapCellValueTag::Atom, (name, arity)) => { (HeapCellValueTag::Atom, (name, arity)) => {
@@ -240,7 +240,7 @@ impl BrentAlgState {
return if name == atom!("[]") { return if name == atom!("[]") {
Some(CycleSearchResult::ProperList(self.num_steps())) Some(CycleSearchResult::ProperList(self.num_steps()))
} else { } else {
Some(CycleSearchResult::NotList) Some(CycleSearchResult::NotList(self.num_steps(), value))
}; };
} }
(HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h) => { (HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h) => {
@@ -252,7 +252,7 @@ impl BrentAlgState {
self.hare = h; self.hare = h;
} }
_ => { _ => {
return Some(CycleSearchResult::NotList); return Some(CycleSearchResult::NotList(self.num_steps(), value));
} }
); );
} }
@@ -298,21 +298,21 @@ impl BrentAlgState {
} else if name == atom!(".") && arity == 2 { } else if name == atom!(".") && arity == 2 {
s + 2 s + 2
} else { } else {
return CycleSearchResult::NotList; return CycleSearchResult::NotList(0, value);
} }
} }
(HeapCellValueTag::Atom, (name, arity)) => { (HeapCellValueTag::Atom, (name, arity)) => {
return if name == atom!("[]") && arity == 0 { return if name == atom!("[]") && arity == 0 {
CycleSearchResult::EmptyList CycleSearchResult::EmptyList
} else { } else {
CycleSearchResult::NotList CycleSearchResult::NotList(0, value)
}; };
} }
(HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => { (HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => {
return CycleSearchResult::PartialList(0, value.as_var().unwrap()); return CycleSearchResult::PartialList(0, value.as_var().unwrap());
} }
_ => { _ => {
return CycleSearchResult::NotList; return CycleSearchResult::NotList(0, value);
} }
); );
@@ -397,21 +397,21 @@ impl BrentAlgState {
return CycleSearchResult::UntouchedList(0, s + 1); return CycleSearchResult::UntouchedList(0, s + 1);
} }
} else { } else {
return CycleSearchResult::NotList; return CycleSearchResult::NotList(0, value);
} }
} }
(HeapCellValueTag::Atom, (name, arity)) => { (HeapCellValueTag::Atom, (name, arity)) => {
return if name == atom!("[]") && arity == 0 { return if name == atom!("[]") && arity == 0 {
CycleSearchResult::EmptyList CycleSearchResult::EmptyList
} else { } else {
CycleSearchResult::NotList CycleSearchResult::NotList(0, value)
}; };
} }
(HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => { (HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => {
return CycleSearchResult::PartialList(0, value.as_var().unwrap()); return CycleSearchResult::PartialList(0, value.as_var().unwrap());
} }
_ => { _ => {
return CycleSearchResult::NotList; return CycleSearchResult::NotList(0, value);
} }
); );
@@ -540,11 +540,8 @@ impl MachineState {
CycleSearchResult::ProperList(steps) => { CycleSearchResult::ProperList(steps) => {
self.finalize_skip_max_list(steps as i64, empty_list_as_cell!()) self.finalize_skip_max_list(steps as i64, empty_list_as_cell!())
} }
CycleSearchResult::NotList => { CycleSearchResult::NotList(n, value) => {
let n = self.store(self.deref(self.registers[2])); self.finalize_skip_max_list(n as i64, value);
self.unify_fixnum(Fixnum::build_with(max_steps), n);
self.finalize_skip_max_list(max_steps, self.registers[3]);
} }
CycleSearchResult::Cyclic(lam) => { CycleSearchResult::Cyclic(lam) => {
self.skip_max_list_cycle(lam); self.skip_max_list_cycle(lam);