From 737acb7cde360f57d3cd87697cf33711371b9094 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 25 Sep 2019 22:40:31 -0600 Subject: [PATCH] ignore single line comments after end token read --- Cargo.toml | 4 +-- src/prolog/examples/domain.pl | 4 +-- src/prolog/examples/expert_system.pl | 4 +-- src/prolog/examples/minatotask.pl | 6 ++-- src/prolog/examples/plres.pl | 6 ++-- src/prolog/machine/machine_state.rs | 5 +++- src/prolog/machine/machine_state_impl.rs | 37 ++++++++++++------------ src/tests.rs | 2 +- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 28498ab1..ec8c2b85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.8.92" +version = "0.8.93" authors = ["Mark Thom "] repository = "https://github.com/mthom/scryer-prolog" description = "A modern Prolog implementation written mostly in Rust." @@ -15,7 +15,7 @@ dirs = "2.0.2" downcast = "0.10.0" indexmap = "1.0.2" ordered-float = "0.5.0" -prolog_parser = "0.8.28" +prolog_parser = "0.8.29" readline_rs_compat = { version = "0.1.9", optional = true } ref_thread_local = "0.0.0" rug = "1.4.0" diff --git a/src/prolog/examples/domain.pl b/src/prolog/examples/domain.pl index cfada79f..f1fadad9 100644 --- a/src/prolog/examples/domain.pl +++ b/src/prolog/examples/domain.pl @@ -4,8 +4,8 @@ https://sicstus.sics.se/sicstus/docs/3.7.1/html/sicstus_17.html :- module(domain, [domain/2]). -:- use_module(library(atts)). -:- use_module(library(ordsets), [ +:- use_module('src/prolog/lib/atts'). +:- use_module('src/prolog/lib/ordsets', [ ord_intersection/3, ord_intersect/2, list_to_ord_set/2 diff --git a/src/prolog/examples/expert_system.pl b/src/prolog/examples/expert_system.pl index 43ba9bd7..55b5d287 100644 --- a/src/prolog/examples/expert_system.pl +++ b/src/prolog/examples/expert_system.pl @@ -1,5 +1,5 @@ -:- use_module(library(dcgs)). -:- use_module(library(reif)). +:- use_module('src/prolog/lib/dcgs'). +:- use_module('src/prolog/lib/reif'). animals([animal(dog, [is_true('has fur'), is_true('says woof')]), animal(cat, [is_true('has fur'), is_true('says meow')]), diff --git a/src/prolog/examples/minatotask.pl b/src/prolog/examples/minatotask.pl index fd1a4233..2d0d4ff9 100644 --- a/src/prolog/examples/minatotask.pl +++ b/src/prolog/examples/minatotask.pl @@ -60,9 +60,9 @@ :- module(zdd, [variables_set_zdd/2]). -:- use_module(library(atts)). -:- use_module(library(dcgs)). -:- use_module(library(lists)). +:- use_module('src/prolog/lib/atts'). +:- use_module('src/prolog/lib/dcgs'). +:- use_module('src/prolog/lib/lists'). :- attribute zdd_vs/2. diff --git a/src/prolog/examples/plres.pl b/src/prolog/examples/plres.pl index a19ca5a7..3ccfc409 100644 --- a/src/prolog/examples/plres.pl +++ b/src/prolog/examples/plres.pl @@ -29,9 +29,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -:- use_module(library(dcgs)). -:- use_module(library(dif)). -:- use_module(library(lists)). +:- use_module('src/prolog/lib/dcgs'). +:- use_module('src/prolog/lib/dif'). +:- use_module('src/prolog/lib/lists'). pl_resolution(Clauses0, Chain) :- maplist(sort, Clauses0, Clauses), % remove duplicates diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index 166e2c43..d5f96d70 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -692,7 +692,10 @@ pub(crate) trait CallPolicy: Any { return_from_clause!(machine_st.last_call, machine_st) } &BuiltInClauseType::Eq => { - machine_st.fail = machine_st.eq_test(); + let a1 = machine_st[temp_v!(1)].clone(); + let a2 = machine_st[temp_v!(2)].clone(); + + machine_st.fail = machine_st.eq_test(a1, a2); return_from_clause!(machine_st.last_call, machine_st) } &BuiltInClauseType::Ground => { diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index 1df1b7bf..ca381672 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -552,7 +552,7 @@ impl MachineState { self.fail = true; } (Addr::Lis(a1), Addr::Con(Constant::String(ref mut s))) - | (Addr::Con(Constant::String(ref mut s)), Addr::Lis(a1)) => { + | (Addr::Con(Constant::String(ref mut s)), Addr::Lis(a1)) => { if match self.flags.double_quotes { DoubleQuotes::Chars => self.deconstruct_chars(s, a1, &mut pdl), DoubleQuotes::Codes => self.deconstruct_codes(s, a1, &mut pdl), @@ -564,7 +564,7 @@ impl MachineState { self.fail = true; } (Addr::Con(Constant::EmptyList), Addr::Con(Constant::String(ref s))) - | (Addr::Con(Constant::String(ref s)), Addr::Con(Constant::EmptyList)) + | (Addr::Con(Constant::String(ref s)), Addr::Con(Constant::EmptyList)) if !self.flags.double_quotes.is_atom() => { if s.is_expandable() && s.is_empty() { @@ -852,11 +852,8 @@ impl MachineState { Addr::Con(Constant::String(ref mut s)) => { self.fail = self.write_constant_to_string(s, c) } - Addr::Con(c1) => { - if c1 != c { - self.fail = true; - } - } + Addr::Con(c1) => + self.fail = self.eq_test(Addr::Con(c), Addr::Con(c1)), Addr::Lis(l) => self.unify(Addr::Lis(l), Addr::Con(c)), addr => { if let Some(r) = addr.as_var() { @@ -2266,25 +2263,29 @@ 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(); - + pub(super) fn eq_test(&self, a1: Addr, a2: Addr) -> bool { let mut iter = self.zipped_acyclic_pre_order_iter(a1, a2); while let Some((v1, v2)) = iter.next() { match (v1, v2) { - (HeapCellValue::NamedStr(ar1, n1, _), HeapCellValue::NamedStr(ar2, n2, _)) => { + (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)) => { + }, + (HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_))) => + continue, + (HeapCellValue::Addr(Addr::Con(Constant::EmptyList)), + HeapCellValue::Addr(Addr::Con(Constant::String(s)))) + | (HeapCellValue::Addr(Addr::Con(Constant::String(s))), + HeapCellValue::Addr(Addr::Con(Constant::EmptyList))) => + return match self.flags.double_quotes { + DoubleQuotes::Atom => true, + _ => !s.is_empty() + }, + (HeapCellValue::Addr(a1), HeapCellValue::Addr(a2)) => if a1 != a2 { return true; - } - } + }, _ => return true, } } diff --git a/src/tests.rs b/src/tests.rs index ef247436..d8857b38 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3068,7 +3068,7 @@ fn test_queries_on_string_lists() { // double_quotes is chars by default. assert_prolog_success!(&mut wam, "variant(\"\", [])."); - assert_prolog_failure!(&mut wam, "\"\" == []."); + assert_prolog_success!(&mut wam, "\"\" == []."); assert_prolog_failure!(&mut wam, "\"abc\" == []."); assert_prolog_success!(&mut wam, "variant(\"abc\", ['a', 'b', 'c'])."); assert_prolog_success!(&mut wam, "variant(\"abc\", ['a', 'b', c])."); -- 2.54.0