From: Mark Thom Date: Tue, 22 Mar 2022 06:55:44 +0000 (-0600) Subject: compare TypedArenaPtr by value not pointer (#1362) X-Git-Tag: v0.9.1~100 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=067e2633afd52f63929a27fd27ec8d2163c5705f;p=scryer-prolog.git compare TypedArenaPtr by value not pointer (#1362) --- diff --git a/src/arena.rs b/src/arena.rs index 0dde0751..8824ede8 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -72,9 +72,15 @@ impl ArenaHeader { } } -#[derive(Debug, PartialOrd, Ord)] +#[derive(Debug)] pub struct TypedArenaPtr(ptr::NonNull); +impl PartialOrd for TypedArenaPtr { + fn partial_cmp(&self, other: &Self) -> Option { + (**self).partial_cmp(&**other) + } +} + impl PartialEq for TypedArenaPtr { fn eq(&self, other: &TypedArenaPtr) -> bool { self.0 == other.0 || &**self == &**other @@ -83,6 +89,12 @@ impl PartialEq for TypedArenaPtr { impl Eq for TypedArenaPtr {} +impl Ord for TypedArenaPtr { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + (**self).cmp(&**other) + } +} + impl Hash for TypedArenaPtr { #[inline(always)] fn hash(&self, hasher: &mut H) { diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index 0f128e08..eccbe6af 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -147,8 +147,9 @@ impl MachineState { h as u64, )); - self.trail.push(TrailEntry::from_bytes( - list_loc_as_cell!(l).into_bytes() + self.trail.push(TrailEntry::build_with( + TrailEntryTag::TrailedAttachedValue, + l as u64, )); self.tr += 2; @@ -2379,15 +2380,14 @@ impl MachineState { value: HeapCellValue, stub_gen: impl Fn() -> FunctorStub, ) -> Result, MachineStub> { - let deref_v = self.deref(value); - let store_v = self.store(deref_v); + let value = self.store(self.deref(value)); - read_heap_cell!(store_v, + read_heap_cell!(value, (HeapCellValueTag::Lis, l) => { - self.try_from_inner_list(vec![], l, stub_gen, store_v) + self.try_from_inner_list(vec![], l, stub_gen, value) } (HeapCellValueTag::PStrLoc, h) => { - self.try_from_partial_string(vec![], h, stub_gen, store_v) + self.try_from_partial_string(vec![], h, stub_gen, value) } (HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => { let err = self.instantiation_error(); @@ -2397,7 +2397,7 @@ impl MachineState { if name == atom!("[]") && arity == 0 { Ok(vec![]) } else { - let err = self.type_error(ValidType::List, store_v); + let err = self.type_error(ValidType::List, value); Err(self.error_form(err, stub_gen())) } } @@ -2406,7 +2406,7 @@ impl MachineState { Ok(cstr.chars().map(|c| char_as_cell!(c)).collect()) } _ => { - let err = self.type_error(ValidType::List, store_v); + let err = self.type_error(ValidType::List, value); Err(self.error_form(err, stub_gen())) } ) @@ -2423,16 +2423,15 @@ impl MachineState { l += 1; loop { - let deref_v = self.deref(self.heap[l]); - let store_v = self.store(self.heap[l]); + let value = self.store(self.deref(self.heap[l])); - read_heap_cell!(store_v, + read_heap_cell!(value, (HeapCellValueTag::Lis, hcp) => { result.push(self.heap[hcp]); l = hcp + 1; } - (HeapCellValueTag::PStrOffset) => { - return self.try_from_partial_string(result, deref_v.get_value(), stub_gen, a1); + (HeapCellValueTag::PStrLoc, l) => { + return self.try_from_partial_string(result, l, stub_gen, a1); } (HeapCellValueTag::Atom, (name, arity)) => { if name == atom!("[]") && arity == 0 { @@ -2443,7 +2442,7 @@ impl MachineState { } } _ => { - if store_v.is_var() { + if value.is_var() { let err = self.instantiation_error(); return Err(self.error_form(err, stub_gen())); } else { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index f5b26e4a..f69426b6 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -829,12 +829,12 @@ impl Machine { self.machine_st.heap[h] = heap_loc_as_cell!(h); } TrailEntryTag::TrailedAttrVarListLink => { - let value = HeapCellValue::from_bytes( - self.machine_st.trail[i + 1].into_bytes() - ); + let l = self.machine_st.trail[i + 1].get_value() as usize; - if value.get_value() < self.machine_st.hb { - self.machine_st.heap[h] = value; + if l < self.machine_st.hb { + self.machine_st.heap[h] = list_loc_as_cell!(l); + } else { + self.machine_st.heap[h] = heap_loc_as_cell!(h); } } TrailEntryTag::TrailedBlackboardEntry => { diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 62a52fac..35b9b9d6 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -2876,7 +2876,7 @@ impl Machine { debug_assert_eq!(addr.get_tag(), HeapCellValueTag::Lis); let l = addr.get_value(); - let tail = self.machine_st.store(self.machine_st.deref(heap_loc_as_cell!(l + 1))); + let tail = self.machine_st.store(self.machine_st.deref(self.machine_st.heap[l + 1])); let tail = if tail.is_var() { self.machine_st.heap[h] = heap_loc_as_cell!(h);