]> Repositorios git - scryer-prolog.git/commitdiff
shed CodeIndex for control predicates in disjuncts.rs (#1791)
authorMark <[email protected]>
Sun, 6 Aug 2023 07:26:01 +0000 (01:26 -0600)
committerMark <[email protected]>
Sun, 6 Aug 2023 07:26:01 +0000 (01:26 -0600)
src/machine/disjuncts.rs
src/parser/ast.rs

index 6c6d3a7be03732fa900b695b34ba41e5c4dcd478..a17240f1ce2ae23396f79ac372b9dac6d3ab514e 100644 (file)
@@ -530,7 +530,36 @@ impl VariableClassifier {
                         }
                     };
 
+                    let mut add_chunk = |classifier: &mut Self, name: Atom, terms: Vec<Term>| {
+                        if update_chunk_data(classifier, name, terms.len()) {
+                            build_stack.add_chunk();
+                        }
+
+                        for (arg_c, term) in terms.iter().enumerate() {
+                            classifier.probe_body_term(arg_c + 1, terms.len(), term);
+                        }
+
+                        build_stack.push_chunk_term(
+                            clause_to_query_term(
+                                loader,
+                                name,
+                                terms,
+                                classifier.call_policy,
+                            ),
+                        );
+                    };
+
                     match term {
+                        Term::Clause(_, name @ (atom!("->") | atom!(";") | atom!(",")), mut terms) if terms.len() == 3 => {
+                            if let Some(last_arg) = terms.last() {
+                                if let Term::Literal(_, Literal::CodeIndex(_)) = last_arg {
+                                    terms.pop();
+                                    state_stack.push(TraversalState::Term(Term::Clause(Cell::default(), name, terms)));
+                                } else {
+                                    add_chunk(self, name, terms);
+                                }
+                            }
+                        }
                         Term::Clause(_, atom!(","), mut terms) if terms.len() == 2 => {
                             let tail = terms.pop().unwrap();
                             let head = terms.pop().unwrap();
@@ -700,22 +729,7 @@ impl VariableClassifier {
                             self.call_policy = CallPolicy::Counted;
                         }
                         Term::Clause(_, name, terms) => {
-                            if update_chunk_data(self, name, terms.len()) {
-                                build_stack.add_chunk();
-                            }
-
-                            for (arg_c, term) in terms.iter().enumerate() {
-                                self.probe_body_term(arg_c + 1, terms.len(), term);
-                            }
-
-                            build_stack.push_chunk_term(
-                                clause_to_query_term(
-                                    loader,
-                                    name,
-                                    terms,
-                                    self.call_policy,
-                                ),
-                            );
+                            add_chunk(self, name, terms);
                         }
                         var @ Term::Var(..) => {
                             if update_chunk_data(self, atom!("call"), 1) {
index fc72878230db87a7f684f279c879761987512db0..05ca5a377fe1f46114ba30a2d0236283aa8710f9 100644 (file)
@@ -830,30 +830,3 @@ pub fn unfold_by_str(mut term: Term, s: Atom) -> Vec<Term> {
     terms.push(term);
     terms
 }
-
-fn unfold_by_str_ref_once(term: &Term, s: Atom) -> Option<(&Term, &Term)> {
-    if let Term::Clause(_, ref name, ref subterms) = term {
-        if name == &s && subterms.len() == 2 {
-            let fst = &subterms[0];
-            let snd = &subterms[1];
-
-            return Some((fst, snd));
-        }
-    }
-
-    None
-}
-
-pub fn unfold_by_str_ref(mut term: &Term, s: Atom) -> Vec<&Term> {
-    let mut terms = vec![];
-
-    while let Some((fst, snd)) = unfold_by_str_ref_once(&term, s) {
-        terms.push(fst);
-        term = snd;
-    }
-
-    terms.push(term);
-    terms
-}
-
-