From ef3a97cedd91e49663a7502c60502c4a5316f7c3 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 29 Nov 2021 19:22:26 -0700 Subject: [PATCH] detect attributed variables by properly detecting them in copy_term/2 --- src/machine/attributed_variables.rs | 2 ++ src/machine/copier.rs | 51 ++--------------------------- src/types.rs | 6 ++-- 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/src/machine/attributed_variables.rs b/src/machine/attributed_variables.rs index 30ec9a8c..568978d8 100644 --- a/src/machine/attributed_variables.rs +++ b/src/machine/attributed_variables.rs @@ -143,6 +143,8 @@ impl MachineState { continue; } + let value = unmark_cell_bits!(value); + seen_vars.push(value); seen_set.insert(h); diff --git a/src/machine/copier.rs b/src/machine/copier.rs index bab1d110..f5417e53 100644 --- a/src/machine/copier.rs +++ b/src/machine/copier.rs @@ -166,8 +166,7 @@ impl CopyTermState { self.trail.push((Ref::attr_var(h), attr_var_as_cell!(h))); if let AttrVarPolicy::DeepCopy = self.attr_var_policy { - self.target - .push(attr_var_as_cell!(threshold)); + self.target.push(attr_var_as_cell!(threshold)); let list_val = self.target[h + 1]; self.target.push(list_val); @@ -195,58 +194,14 @@ impl CopyTermState { _ => {} ); - if addr == ra { - self.reinstantiate_var(addr, self.scan); + if rd == ra { + self.reinstantiate_var(ra, self.scan); self.scan += 1; } else { *self.value_at_scan() = ra; - // self.copy_compound(rd, ra); } } - /* - fn copy_compound(&mut self, rd: HeapCellValue, ra: HeapCellValue) { - let h = rd.get_value(); - let trail_item = self.target[h]; - let threshold = self.target.threshold(); - - self.trail.push((Ref::heap_cell(h), trail_item)); - self.target[self.scan].set_value(threshold); - - read_heap_cell!(ra, - (HeapCellValueTag::Atom, (_name, arity)) => { - self.target.push(ra); - - for i in 0..arity { - self.target.push(self.target[h + 1 + i]); - } - - self.target[h] = str_loc_as_cell!(self.scan + 1); - } - (HeapCellValueTag::PStr | HeapCellValueTag::PStrOffset) => { - self.target.push(ra); - self.target.push(self.target[h + 1]); - - self.target[h] = pstr_loc_as_cell!(self.scan + 1); - } - (HeapCellValueTag::CStr, cstr_atom) => { - self.target[h] = atom_as_cstr_cell!(cstr_atom); - } - (HeapCellValueTag::Str, s) => { - self.copy_structure(s); - return; - } - _ => { - *self.value_at_scan() = rd; - self.trail.pop(); - return; - } - ); - - self.scan += 1; - } - */ - fn copy_structure(&mut self, addr: usize) { read_heap_cell!(self.target[addr], (HeapCellValueTag::Atom, (name, arity)) => { diff --git a/src/types.rs b/src/types.rs index 57a6c5a3..b0339a1a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -221,9 +221,9 @@ impl TrailEntry { #[inline(always)] pub(crate) fn get_tag(self) -> TrailEntryTag { match self.tag_or_err() { - Ok(tag) => tag, - Err(_) => TrailEntryTag::TrailedAttachedValue, - } + Ok(tag) => tag, + Err(_) => TrailEntryTag::TrailedAttachedValue, + } } #[inline] -- 2.54.0