]> Repositorios git - scryer-prolog.git/commitdiff
check that lower bound on term expansion drain is below the len of the term expansion...
authorMark Thom <[email protected]>
Wed, 29 Apr 2020 01:22:20 +0000 (19:22 -0600)
committerMark Thom <[email protected]>
Wed, 29 Apr 2020 01:22:20 +0000 (19:22 -0600)
src/prolog/machine/code_repo.rs
src/prolog/machine/term_expansion.rs

index eba8c5c926c8e371c2afbf4bb715e8aae44bab17..78f3a5488352949ebb60358cdadc0c4772d24ff2 100644 (file)
@@ -53,12 +53,23 @@ impl CodeRepo {
         self.term_dir
             .get_mut(&key)
             .map(|entry| {
-                (
-                    Predicate((entry.0).0.drain(len..).collect()),
-                    entry.1.drain(queue_len..).collect(),
-                )
+                let terms =
+                    if len < (entry.0).0.len() {
+                        (entry.0).0.drain(len ..).collect()
+                    } else {
+                        vec![]
+                    };
+
+                let queue =
+                    if queue_len < entry.1.len() {
+                        entry.1.drain(queue_len ..).collect()
+                    } else {
+                        VecDeque::new()
+                    };
+
+                (Predicate(terms), queue)
             })
-            .unwrap_or((Predicate::new(), VecDeque::from(vec![])))
+            .unwrap_or((Predicate::new(), VecDeque::new()))
     }
 
     pub(crate)
index 06d7b3be81b6b0a991b2fbb24622cbbae91941f4..d2b6419cc4d507654e75fc8ce61f7b2c0da86b4b 100644 (file)
@@ -181,6 +181,7 @@ impl<'a> TermStream<'a> {
             te_len,
             te_queue_len,
         );
+
         let goal_expansion_additions = self.wam.code_repo.truncate_terms(
             (clause_name!("goal_expansion"), 2),
             ge_len,