distinguish eq from structural_eq on strings

This commit is contained in:
Mark Thom
2018-09-03 00:06:01 -06:00
parent abcb53699a
commit c5fd13dfa0
9 changed files with 80 additions and 63 deletions

View File

@@ -6,7 +6,6 @@ use prolog::machine::machine_errors::*;
use prolog::num::{BigInt, BigUint, Zero, One};
use prolog::or_stack::*;
use prolog::read::*;
use prolog::string_list::*;
use prolog::tabled_rc::*;
use downcast::Any;
@@ -299,7 +298,6 @@ impl Default for MachineFlags {
pub struct MachineState {
pub(crate) atom_tbl: TabledData<Atom>,
pub(crate) string_tbl: TabledData<StringListWrapper>,
pub(super) s: usize,
pub(super) p: CodePtr,
pub(super) b: usize,
@@ -626,15 +624,7 @@ pub(crate) trait CallPolicy: Any {
return_from_clause!(machine_st.last_call, machine_st)
},
&BuiltInClauseType::Eq => {
let a1 = machine_st[temp_v!(1)].clone();
let a2 = machine_st[temp_v!(2)].clone();
machine_st.fail = if let Ordering::Equal = machine_st.compare_term_test(&a1, &a2) {
false
} else {
true
};
machine_st.fail = machine_st.eq_test();
return_from_clause!(machine_st.last_call, machine_st)
},
&BuiltInClauseType::Ground => {

View File

@@ -32,7 +32,6 @@ impl MachineState {
pub(super) fn new() -> Self {
MachineState {
atom_tbl: Rc::new(RefCell::new(HashSet::new())),
string_tbl: Rc::new(RefCell::new(HashSet::new())),
s: 0,
p: CodePtr::default(),
b: 0,
@@ -1420,6 +1419,33 @@ impl MachineState {
};
}
// returns true on failure.
pub(super) fn eq_test(&self) -> bool
{
let a1 = self[temp_v!(1)].clone();
let a2 = self[temp_v!(2)].clone();
let iter = self.zipped_acyclic_pre_order_iter(a1, a2);
for (v1, v2) in iter {
match (v1, v2) {
(HeapCellValue::NamedStr(ar1, n1, _), HeapCellValue::NamedStr(ar2, n2, _)) =>
if ar1 != ar2 || n1 != n2 {
return true;
},
(HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_))) =>
continue,
(HeapCellValue::Addr(a1), HeapCellValue::Addr(a2)) =>
if a1 != a2 {
return true;
},
_ => return true
}
}
false
}
pub(super) fn compare_term_test(&self, a1: &Addr, a2: &Addr) -> Ordering {
let iter = self.zipped_acyclic_pre_order_iter(a1.clone(), a2.clone());
@@ -1500,10 +1526,8 @@ impl MachineState {
HeapCellValue::Addr(Addr::Con(Constant::Number(_)))) =>
return Ordering::Greater,
(HeapCellValue::Addr(Addr::Con(Constant::String(s1))),
HeapCellValue::Addr(Addr::Con(Constant::String(s2)))) =>
if s1 != s2 {
return s1.cmp(&s2);
},
HeapCellValue::Addr(Addr::Con(Constant::String(s2)))) =>
return s1.cmp(&s2),
(HeapCellValue::Addr(Addr::Con(Constant::String(_))), _) =>
return Ordering::Less,
(HeapCellValue::Addr(Addr::Con(Constant::Atom(..))),

View File

@@ -1,7 +1,6 @@
use prolog::ast::*;
use prolog::compile::*;
use prolog::heap_print::*;
use prolog::string_list::StringListWrapper;
use prolog::tabled_rc::*;
mod machine_errors;
@@ -174,17 +173,15 @@ impl Machine {
}
}
#[inline]
pub fn failed(&self) -> bool {
self.ms.fail
}
#[inline]
pub fn atom_tbl(&self) -> TabledData<Atom> {
self.ms.atom_tbl.clone()
}
pub fn string_tbl(&self) -> TabledData<StringListWrapper> {
self.ms.string_tbl.clone()
}
pub fn use_qualified_module_in_toplevel(&mut self, name: ClauseName, exports: Vec<PredicateKey>)
-> EvalSession