]> Repositorios git - scryer-prolog.git/commitdiff
add term_expansion basics
authorMark Thom <[email protected]>
Sat, 22 Sep 2018 23:05:19 +0000 (17:05 -0600)
committerMark Thom <[email protected]>
Sat, 22 Sep 2018 23:05:19 +0000 (17:05 -0600)
Cargo.lock
Cargo.toml
src/prolog/machine/term_expansion.rs
src/prolog/toplevel.rs

index d46db9b5a4bf2d73f2342086b1346bd4fc264f24..064bcf4884c70af6757fe97dc02c5b60da0db878 100644 (file)
@@ -86,7 +86,8 @@ dependencies = [
 
 [[package]]
 name = "prolog_parser"
-version = "0.7.14"
+version = "0.7.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -107,12 +108,12 @@ dependencies = [
 
 [[package]]
 name = "rusty-wam"
-version = "0.7.13"
+version = "0.7.14"
 dependencies = [
  "downcast 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "prolog_parser 0.7.14",
+ "prolog_parser 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -151,6 +152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
 "checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe"
 "checksum ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58d25b6c0e47b20d05226d288ff434940296e7e2f8b877975da32f862152241f"
+"checksum prolog_parser 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "11f378539616d1cd7b8fc006f309b5a4b483b82cbab76e898a9f1c99318b4dfa"
 "checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
 "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
 "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
index 6fa9e632ea2b7441c4c60e5c84831fe2e8a04105..787ffe60796896ad86c8226ba471477fcb5d1555 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "rusty-wam"
-version = "0.7.13"
+version = "0.7.14"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/rusty-wam"
 description = "The Warren Abstract Machine in Rust."
@@ -10,7 +10,7 @@ license = "BSD-3-Clause"
 downcast = "0.9.1"
 num = "0.2"
 ordered-float = "0.5.0"
-prolog_parser = { path = "../prolog_parser", version = "0.7.14" }
+prolog_parser = "0.7.15"
 
 [dependencies.termion]
 version = "1.4.0"
\ No newline at end of file
index cc9337fad500aa8f66355154f288f6f6ca2eae96..a743a5552705cb82d3db1e94e20aa229ca919363 100644 (file)
@@ -94,7 +94,9 @@ impl Machine {
             self.reset();
             Ok(None)
         } else {
-            Ok(Some(read_term_from_heap(&self.ms, Addr::HeapCell(h))?))
+            let term = read_term_from_heap(&self.ms, Addr::HeapCell(h))?;
+            self.reset();            
+            Ok(Some(term))
         }
     }
 }
index 23134fff067ac7ec6993f24b6e7a25635a7c959b..2ec9c50cf678532a8d130048e2e52e4a04569a9a 100644 (file)
@@ -1,5 +1,4 @@
 use prolog_parser::ast::*;
-use prolog_parser::parser::*;
 use prolog_parser::tabled_rc::*;
 
 use prolog::instructions::*;
@@ -623,12 +622,12 @@ impl RelationWorker {
                   -> Result<(CompileTimeHook, PredicateClause), ParserError>
     {
         match term {
-            Term::Clause(r, name, terms, _) => 
+            Term::Clause(r, name, terms, _) =>
                 if name.as_str() == "term_expansion" && terms.len() == 2 {
                     let term = Term::Clause(r, name, terms, None);
                     Ok((CompileTimeHook::TermExpansion, PredicateClause::Fact(term)))
                 } else if name.as_str() == ":-" {
-                    let rule = self.setup_rule(indices, terms, false)?;                    
+                    let rule = self.setup_rule(indices, terms, false)?;
                     Ok((CompileTimeHook::TermExpansion, PredicateClause::Rule(rule)))
                 } else {
                     Err(ParserError::InvalidHook)
@@ -636,7 +635,7 @@ impl RelationWorker {
             _ => Err(ParserError::InvalidHook)
         }
     }
-    
+
     fn setup_rule(&mut self, indices: &mut CompositeIndices, mut terms: Vec<Box<Term>>, blocks_cuts: bool)
                   -> Result<Rule, ParserError>
     {
@@ -662,7 +661,7 @@ impl RelationWorker {
                 if is_term_expansion(&name, &terms) {
                     let term = Term::Clause(r, name, terms, fixity);
                     let (hook, clauses) = self.setup_hook(indices, term)?;
-                    
+
                     Ok(TopLevel::Declaration(Declaration::Hook(hook, clauses)))
                 } else if name.as_str() == "?-" {
                     Ok(TopLevel::Query(try!(self.setup_query(indices, terms, blocks_cuts))))
@@ -672,9 +671,9 @@ impl RelationWorker {
                     let term = *terms.pop().unwrap();
                     Ok(TopLevel::Declaration(try!(setup_declaration(term))))
                 } else {
-                    let term = Term::Clause(r, name, terms, fixity);                        
+                    let term = Term::Clause(r, name, terms, fixity);
                     Ok(TopLevel::Fact(try!(setup_fact(term))))
-                },        
+                },
             term => Ok(TopLevel::Fact(try!(setup_fact(term))))
         }
     }
@@ -699,7 +698,7 @@ impl RelationWorker {
         while let Some(terms) = self.queue.pop_front() {
             let clauses = merge_clauses(&mut self.try_terms_to_tls(indices, terms, false)?)?;
             queue.push_back(clauses);
-        
+
         }
         Ok(queue)
     }
@@ -709,9 +708,12 @@ impl RelationWorker {
     }
 }
 
-// used to parse queries in test. mostly.
+// used to parse queries in test.
+#[cfg(test)]
 pub fn parse_term<R: Read>(wam: &Machine, buf: R) -> Result<Term, ParserError>
 {
+    use prolog_parser::parser::*;
+
     let mut parser = Parser::new(buf, wam.atom_tbl(), wam.machine_flags());
     parser.read_term(composite_op!(&wam.op_dir))
 }
@@ -723,7 +725,7 @@ fn consume_term<'a>(static_code_dir: Rc<RefCell<CodeDir>>, term: Term,
 {
     let mut rel_worker = RelationWorker::new();
     let mut indices = composite_indices!(false, &mut indices, static_code_dir);
-    
+
     let tl = rel_worker.try_term_to_tl(&mut indices, term, true)?;
     let results = rel_worker.parse_queue(&mut indices)?;
 
@@ -762,8 +764,8 @@ impl<R: Read> TopLevelBatchWorker<R> {
             self.term_stream.empty_tokens(); // empty the parser stack of token descriptions.
 
             let mut new_rel_worker = RelationWorker::new();
-            let term = self.term_stream.read_term(wam, &indices.local.op_dir)?;          
-                
+            let term = self.term_stream.read_term(wam, &indices.local.op_dir)?;
+
             let tl = new_rel_worker.try_term_to_tl(&mut indices, term, true)?;
 
             if !is_consistent(&tl, &preds) {  // if is_consistent returns false, preds is non-empty.
@@ -777,7 +779,7 @@ impl<R: Read> TopLevelBatchWorker<R> {
                 TopLevel::Fact(fact) => preds.push(PredicateClause::Fact(fact)),
                 TopLevel::Rule(rule) => preds.push(PredicateClause::Rule(rule)),
                 TopLevel::Predicate(pred) => preds.extend(pred.0),
-                TopLevel::Declaration(decl) => return Ok(Some(decl)),                
+                TopLevel::Declaration(decl) => return Ok(Some(decl)),
                 TopLevel::Query(_) => return Err(SessionError::NamelessEntry)
             }
         }