]> Repositorios git - scryer-prolog.git/commitdiff
improve matching on partial strings as lists
authorMark Thom <[email protected]>
Wed, 1 May 2019 03:30:28 +0000 (21:30 -0600)
committerMark Thom <[email protected]>
Wed, 1 May 2019 03:30:28 +0000 (21:30 -0600)
Cargo.toml
src/prolog/indexing.rs
src/prolog/machine/compile.rs
src/prolog/machine/machine_state_impl.rs

index 7d570da416a5e25c0192f98cba16e1f6453ac051..7236e49867e13722c79a42f50f20b646f131cfdd 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.77"
+version = "0.8.78"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
index 4cba9d1353f787f48d54b1cdc3f9d3387af883ba..81207a334d1a6f53aa21aa20897cdfb44f63164b 100644 (file)
@@ -58,8 +58,13 @@ impl CodeOffsets {
                 let is_initial_index = self.lists.is_empty();
                 self.lists.push(Self::add_index(is_initial_index, index));
             },
-            &Term::Constant(_, Constant::String(_))
-                if !self.flags.double_quotes.is_atom() => { // strings are lists in this case.
+            &Term::Constant(_, Constant::String(ref s))
+                if !self.flags.double_quotes.is_atom() && !s.is_empty() => { // strings are lists in this case.
+                    let is_initial_index = self.lists.is_empty();
+                    self.lists.push(Self::add_index(is_initial_index, index));
+                },
+            &Term::Constant(_, Constant::String(ref s))
+                if !self.flags.double_quotes.is_atom() && s.is_expandable() => {
                     let is_initial_index = self.lists.is_empty();
                     self.lists.push(Self::add_index(is_initial_index, index));
                 },
@@ -132,7 +137,7 @@ impl CodeOffsets {
             _ => IntIndex::Fail
         }
     }
-    
+
     fn switch_on_constant(con_ind: HashMap<Constant, ThirdLevelIndex>, prelude: &mut CodeDeque)
                           -> IntIndex
     {
@@ -203,7 +208,7 @@ impl CodeOffsets {
         match con_loc {
             IntIndex::External(offset) => offset + prelude_len + 1,
             IntIndex::Fail => 0,
-            IntIndex::Internal(offset) => offset, 
+            IntIndex::Internal(offset) => offset,
         }
     }
 
@@ -216,7 +221,7 @@ impl CodeOffsets {
             IntIndex::Internal(_) => prelude_len - lst_offset + 1
         }
     }
-    
+
     pub fn add_indices(self, code: &mut Code, mut code_body: Code)
     {
         if self.no_indices() {
index ac60200ad445f87c5b7b872ab309e42234af5f4b..8a0f4326cdcdde5e659e790452d84d2f06856f31 100644 (file)
@@ -133,8 +133,8 @@ fn compile_decl(wam: &mut Machine, compiler: &mut ListingCompiler, decl: Declara
     let mut indices = default_index_store!(wam.indices.atom_tbl.clone());
     let wam_indices = &mut wam.indices;
 
-    compiler.process_decl(decl, &mut wam.code_repo, wam_indices, &mut indices, flags)?;
-
+    compiler.process_decl(decl, &mut wam.code_repo, wam_indices, &mut indices, flags)?;    
+    
     Ok(indices)
 }
 
index bab156b4d1903a6e6ae186777d27975652869d2c..8bcfde78928a8d05032ca464aa4fb549922b1d5f 100644 (file)
@@ -1496,7 +1496,8 @@ impl MachineState {
 
                 let offset = match addr {
                     Addr::HeapCell(_) | Addr::StackCell(..) | Addr::AttrVar(..) => v,
-                    Addr::Con(Constant::String(_)) if !self.flags.double_quotes.is_atom() => l,
+                    Addr::Con(Constant::String(ref s)) if !self.flags.double_quotes.is_atom() =>
+                        if s.is_empty() && !s.is_expandable() { c } else { l },
                     Addr::Con(_) => c,
                     Addr::Lis(_) => l,
                     Addr::Str(_) => s,