From: Mark Thom Date: Tue, 23 Nov 2021 06:06:02 +0000 (-0700) Subject: fix HeapPStrIter bug not recognizing nil focus if PStrLoc points to PStrOffset to... X-Git-Tag: v0.9.0^2~122 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=4af57b0dd3cfd2b955f8d40fbab490e4835a071b;p=scryer-prolog.git fix HeapPStrIter bug not recognizing nil focus if PStrLoc points to PStrOffset to CStr --- diff --git a/src/loader.pl b/src/loader.pl index 21489e46..fb5d8ab1 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -691,14 +691,10 @@ expand_goal_cases((\+ Goals0), Module, ExpandedGoals, HeadVars) :- expand_goal_cases((Module:Goals0), _, ExpandedGoals, HeadVars) :- expand_goal(Goals0, Module, Goals1, HeadVars), ExpandedGoals = (Module:Goals1). -expand_goal_cases(call(Goals0), _, ExpandedGoals, HeadVars) :- - expand_goal(Goals0, Module, Goals1, HeadVars), - ExpandedGoals = call(Goals1). expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars) :- ( var(UnexpandedGoals) -> - UnexpandedGoals = ExpandedGoals - % expand_module_names(call(UnexpandedGoals), [0], Module, ExpandedGoals, HeadVars) + expand_module_names(call(UnexpandedGoals), [0], Module, ExpandedGoals, HeadVars) ; goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1), ( Module \== user -> goal_expansion(UnexpandedGoals1, user, Goals) diff --git a/src/machine/machine_indices.rs b/src/machine/machine_indices.rs index 6d5be8c1..361b084e 100644 --- a/src/machine/machine_indices.rs +++ b/src/machine/machine_indices.rs @@ -45,25 +45,6 @@ pub enum TermOrderCategory { Compound, } -// the position-dependent heap template: - -/* - read_heap_cell!( - (HeapCellValueTag::AttrVar, n) => { - } - (HeapCellValueTag::Lis, n) => { - } - (HeapCellValueTag::Var, n) => { - } - (HeapCellValueTag::Str, n) => { - } - (HeapCellValueTag::PStrOffset, n) => { - } - _ => { - } - ) -*/ - impl PartialEq for HeapCellValue { fn eq(&self, r: &Ref) -> bool { self.as_var() == Some(*r) @@ -82,7 +63,10 @@ impl PartialOrd for HeapCellValue { _ => Some(Ordering::Greater), } } - (HeapCellValueTag::Var | HeapCellValueTag::AttrVar, h1) => { + (HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h1) => { + // _ if self.is_ref() => { + // let h1 = self.get_value(); + match r.get_tag() { RefTag::StackCell => Some(Ordering::Less), _ => { diff --git a/src/types.rs b/src/types.rs index 57c999eb..57a6c5a3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -343,21 +343,27 @@ impl HeapCellValue { } #[inline] - pub fn is_string_terminator(self, heap: &[HeapCellValue]) -> bool { - read_heap_cell!(self, - (HeapCellValueTag::Atom, (name, arity)) => { - name == atom!("[]") && arity == 0 - } - (HeapCellValueTag::CStr) => { - true - } - (HeapCellValueTag::PStrOffset, pstr_offset) => { - heap[pstr_offset].get_tag() == HeapCellValueTag::CStr - } - _ => { - false - } - ) + pub fn is_string_terminator(mut self, heap: &[HeapCellValue]) -> bool { + loop { + return read_heap_cell!(self, + (HeapCellValueTag::Atom, (name, arity)) => { + name == atom!("[]") && arity == 0 + } + (HeapCellValueTag::CStr) => { + true + } + (HeapCellValueTag::PStrLoc, h) => { + self = heap[h]; + continue; + } + (HeapCellValueTag::PStrOffset, pstr_offset) => { + heap[pstr_offset].get_tag() == HeapCellValueTag::CStr + } + _ => { + false + } + ); + } } #[inline(always)]