]> Repositorios git - scryer-prolog.git/commitdiff
remove is from inlined terms.
authorMark Thom <[email protected]>
Mon, 13 Nov 2017 20:35:34 +0000 (13:35 -0700)
committerMark Thom <[email protected]>
Mon, 13 Nov 2017 20:35:34 +0000 (13:35 -0700)
src/prolog/ast.rs
src/prolog/codegen.rs
src/prolog/iterators.rs
src/prolog/parser

index e834a4b75adfc508bce45489f4dfb71c129cbd8d..0f7c993e5929df101cc20a49a993f462d7aac631 100644 (file)
@@ -310,7 +310,6 @@ pub enum Term {
 }
 
 pub enum InlinedQueryTerm {    
-    Is(Vec<Box<Term>>),
     IsAtomic(Vec<Box<Term>>),
     IsVar(Vec<Box<Term>>)
 }    
@@ -318,8 +317,8 @@ pub enum InlinedQueryTerm {
 impl InlinedQueryTerm {
     pub fn arity(&self) -> usize {
         match self {
-            &InlinedQueryTerm::Is(_) => 2,
-            _ => 1
+            &InlinedQueryTerm::IsAtomic(_) => 1,
+            &InlinedQueryTerm::IsVar(_) => 1
         }
     }
 }
@@ -328,6 +327,7 @@ pub enum QueryTerm {
     CallN(Vec<Box<Term>>),
     Catch(Vec<Box<Term>>),
     Cut,
+    Is(Vec<Box<Term>>),
     Inlined(InlinedQueryTerm),
     Term(Term),
     Throw(Vec<Box<Term>>)
@@ -339,6 +339,7 @@ impl QueryTerm {
             &QueryTerm::Catch(_) => 3,
             &QueryTerm::Throw(_) => 1,
             &QueryTerm::Inlined(ref term) => term.arity(),
+            &QueryTerm::Is(_) => 2,
             &QueryTerm::CallN(ref terms) => terms.len(),
             &QueryTerm::Cut => 0,
             &QueryTerm::Term(ref term) => term.arity(),
index 9e332f3df21a1995a03eef504c48e5166ff8de57..c25761602fde2088b198f364904005a3f9eef300 100644 (file)
@@ -235,8 +235,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
     {
         match term {
             &InlinedQueryTerm::IsAtomic(_) | &InlinedQueryTerm::IsVar(_) =>
-                code.push(proceed!()),
-            _ => {}
+                code.push(proceed!())            
         };
     }
     
@@ -290,65 +289,23 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
 
         dealloc_index
     }
-
+    
     fn compile_inlined(&mut self, term: &'a InlinedQueryTerm, term_loc: GenContext, code: &mut Code)
-                       -> Result<(), ParserError>
     {
         match term {
-            &InlinedQueryTerm::Is(ref terms) => {
-                let mut arith_code = {
-                    let mut evaluator = ArithmeticEvaluator::new(self.marker.bindings());
-                    evaluator.eval(terms[1].as_ref())?
-                };
-
-                code.append(&mut arith_code);
-
-                match terms[0].as_ref() {
-                    &Term::Var(ref vr, ref name) => {
-                        let r = self.mark_non_callable(name,
-                                                       2,
-                                                       term_loc,
-                                                       vr,
-                                                       code);
-
-                        code.push(is_call!(r));
-                    },
-                    &Term::Constant(_, Constant::Float(fl)) => {
-                        code.push(query![put_constant!(Level::Shallow,
-                                                       Constant::Float(fl),
-                                                       temp_v!(1))]);
-                        code.push(is_call!(temp_v!(1)));
-                    },
-                    &Term::Constant(_, Constant::Integer(ref bi)) => {
-                        let bi = bi.clone();
-                        code.push(query![put_constant!(Level::Shallow,
-                                                       Constant::Integer(bi),
-                                                       temp_v!(1))]);
-                        code.push(is_call!(temp_v!(1)));
-                    },
-                    _ => {
-                        return Err(ParserError::from(ArithmeticError::InvalidTerm));
-                    }
-                }
-            },
             &InlinedQueryTerm::IsAtomic(ref inner_term) =>
-                match inner_term[0].as_ref() {
-                    &Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
-                        code.push(fail!());
-                    },
-                    &Term::Constant(_, _) => {
-                        code.push(succeed!());
-                    },
-                    &Term::Var(ref vr, ref name) => {
-                        let r = self.mark_non_callable(name,
-                                                       1,
-                                                       term_loc,
-                                                       vr,
-                                                       code);
-
-                        code.push(is_atomic!(r));
-                    }
+            match inner_term[0].as_ref() {
+                &Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
+                    code.push(fail!());
                 },
+                &Term::Constant(_, _) => {
+                    code.push(succeed!());
+                },
+                &Term::Var(ref vr, ref name) => {
+                    let r = self.mark_non_callable(name, 1, term_loc, vr, code);
+                    code.push(is_atomic!(r));
+                }
+            },            
             &InlinedQueryTerm::IsVar(ref inner_term) =>
                 match inner_term[0].as_ref() {
                     &Term::Constant(_, _) | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
@@ -358,26 +315,19 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
                         code.push(succeed!());
                     },
                     &Term::Var(ref vr, ref name) => {
-                        let r = self.mark_non_callable(name,
-                                                       1,
-                                                       term_loc,
-                                                       vr,
-                                                       code);
-
+                        let r = self.mark_non_callable(name, 1, term_loc, vr, code);
                         code.push(is_var!(r));
                     }
                 }
         }
-
-        Ok(())
     }
-
+    
     fn compile_seq(&mut self,
                    iter: ChunkedIterator<'a>,
                    conjunct_info: &ConjunctInfo<'a>,
                    code: &mut Code,
                    is_exposed: bool)
-        -> Result<(), ParserError>
+                   -> Result<(), ParserError>
     {
         for (chunk_num, _, terms) in iter {
             for (i, term) in terms.iter().enumerate()
@@ -403,7 +353,43 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
                         });
                     },
                     &QueryTerm::Inlined(ref term) =>
-                        try!(self.compile_inlined(term, term_loc, code)),
+                        self.compile_inlined(term, term_loc, code),
+                    &QueryTerm::Is(ref terms) => {
+                        let mut arith_code = {
+                            let mut evaluator = ArithmeticEvaluator::new(self.marker.bindings());
+                            evaluator.eval(terms[1].as_ref())?
+                        };
+
+                        code.append(&mut arith_code);
+
+                        match terms[0].as_ref() {
+                            &Term::Var(ref vr, ref name) => {
+                                let r = self.mark_non_callable(name,
+                                                               2,
+                                                               term_loc,
+                                                               vr,
+                                                               code);
+
+                                code.push(is_call!(r));
+                            },
+                            &Term::Constant(_, Constant::Float(fl)) => {
+                                code.push(query![put_constant!(Level::Shallow,
+                                                               Constant::Float(fl),
+                                                               temp_v!(1))]);
+                                code.push(is_call!(temp_v!(1)));
+                            },
+                            &Term::Constant(_, Constant::Integer(ref bi)) => {
+                                let bi = bi.clone();
+                                code.push(query![put_constant!(Level::Shallow,
+                                                               Constant::Integer(bi),
+                                                               temp_v!(1))]);
+                                code.push(is_call!(temp_v!(1)));
+                            },
+                            _ => {
+                                return Err(ParserError::from(ArithmeticError::InvalidTerm));
+                            }
+                        }
+                    },
                     _ if chunk_num == 0 => {
                         self.marker.reset_arg(term.arity());
 
@@ -423,7 +409,6 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
 
         Ok(())
     }
-
     fn compile_seq_prelude(&mut self, conjunct_info: &ConjunctInfo, body: &mut Code)
     {
         if conjunct_info.allocates() {
index f8545cf95e012d7c1eb43aa4bd9b3f42bbd2871d..190dd1f83f3218b5309fbfc6da8fb97a7894f43b 100644 (file)
@@ -40,7 +40,7 @@ impl<'a> QueryIterator<'a> {
                 let state = IteratorState::Clause(0, ClauseType::Catch, terms);
                 QueryIterator { state_stack: vec![state] }
             },
-            &QueryTerm::Inlined(InlinedQueryTerm::Is(ref terms)) => {
+            &QueryTerm::Is(ref terms) => {
                 let state = IteratorState::Clause(0, ClauseType::Is, terms);
                 QueryIterator { state_stack: vec![state] }
             },
@@ -270,13 +270,12 @@ impl<'a> ChunkedIterator<'a>
                     arity = child_terms.len();
                     break;
                 },
-                &QueryTerm::Inlined(InlinedQueryTerm::Is(_)) => {
+                &QueryTerm::Is(_) => {
                     result.push(term);
                     arity = 2;
                     break;
                 },
-                &QueryTerm::Inlined(InlinedQueryTerm::IsAtomic(_))
-              | &QueryTerm::Inlined(InlinedQueryTerm::IsVar(_)) =>
+                &QueryTerm::Inlined(_) =>
                     result.push(term),
                 &QueryTerm::Cut => {
                     result.push(term);
index 41d2d7d26fd855bcb4f486411333d3671c648aaa..ae1e2b153e9f63a966837bddb5a297f75f09ecfb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 41d2d7d26fd855bcb4f486411333d3671c648aaa
+Subproject commit ae1e2b153e9f63a966837bddb5a297f75f09ecfb