]> Repositorios git - scryer-prolog.git/commitdiff
provisional changes #2
authorMark Thom <[email protected]>
Thu, 13 Sep 2018 05:31:29 +0000 (23:31 -0600)
committerMark Thom <[email protected]>
Thu, 13 Sep 2018 05:31:29 +0000 (23:31 -0600)
Cargo.lock
Cargo.toml
src/prolog/compile.rs
src/prolog/machine/mod.rs
src/prolog/read.rs
src/prolog/toplevel.rs

index 42d1dbcf8ea0f70a6f653186cc21dc30f901bfb2..6ed1a05ac0252d686aeaa65acff1abece249dd08 100644 (file)
@@ -86,8 +86,7 @@ dependencies = [
 
 [[package]]
 name = "prolog_parser"
-version = "0.7.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+version = "0.7.12"
 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)",
@@ -108,12 +107,12 @@ dependencies = [
 
 [[package]]
 name = "rusty-wam"
-version = "0.7.9"
+version = "0.7.10"
 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.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "prolog_parser 0.7.12",
  "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -152,7 +151,6 @@ 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.11 (registry+https://github.com/rust-lang/crates.io-index)" = "608b6d0e85a6ea8d4fda3679fc314a8b08efdb07f896438342a9d727b04b72d7"
 "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 9080870dafaeef58247dbdd7328fb0ece0734342..3ed2e17ec07fad5013a71e500a00f2f5bd2fe022 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "rusty-wam"
-version = "0.7.9"
+version = "0.7.10"
 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 = "0.7.11"
+prolog_parser = { path = "../prolog_parser", version = "0.7.12" }
 
 [dependencies.termion]
 version = "1.4.0"
\ No newline at end of file
index 94feb8359b7711a389dc5dccd269597585996ee0..30f4b39dcb17201328531494c1daa2787ccd7b1e 100644 (file)
@@ -133,12 +133,12 @@ impl ListingCompiler {
     pub fn new() -> Self {
         ListingCompiler { module: None, non_counted_bt_preds: HashSet::new() }
     }
-    
-    fn use_module(&mut self, submodule: Module, wam: &mut Machine,
-                  indices: &mut MachineCodeIndices) -> Result<(), SessionError>
+
+    fn use_module(&mut self, submodule: Module, wam: &mut Machine, indices: &mut MachineCodeIndices)
+                  -> Result<(), SessionError>
     {
         let mod_name = self.get_module_name();
-                
+
         indices.use_module(&submodule)?;
 
         if let &mut Some(ref mut module) = &mut self.module {
@@ -157,7 +157,7 @@ impl ListingCompiler {
                             -> Result<(), SessionError>
     {
         let mod_name = self.get_module_name();
-                
+
         indices.use_qualified_module(&submodule, exports)?;
 
         if let &mut Some(ref mut module) = &mut self.module {
@@ -170,7 +170,7 @@ impl ListingCompiler {
         wam.insert_module(submodule);
         Ok(())
     }
-    
+
     fn get_module_name(&self) -> ClauseName {
         self.module.as_ref()
             .map(|module| module.module_decl.name.clone())
@@ -268,7 +268,7 @@ pub fn compile_listing<'a, R>(wam: &mut Machine, src: R, mut indices: MachineCod
     let mut compiler = ListingCompiler::new();
     let mut toplevel_results = vec![];
 
-    while let Some(decl) = try_eval_session!(worker.consume(&mut indices)) {
+    while let Some(decl) = try_eval_session!(worker.consume(&wam.op_dir, &mut indices)) {
         if decl.is_module_decl() {
             toplevel_indices.copy_and_swap(&mut indices);
             mem::swap(&mut worker.results, &mut toplevel_results);
index d07bf29bc558128424a4c8a07d7afb20e5e58e7d..8f96705ef10ba439e445ed9d89e429a8e5e7ca71 100644 (file)
@@ -175,11 +175,7 @@ impl Machine {
     pub fn atom_tbl(&self) -> TabledData<Atom> {
         self.ms.atom_tbl.clone()
     }
-
-    pub fn get_module(&self, name: ClauseName) -> Option<&Module> {
-        self.modules.get(&name)
-    }
-
+   
     pub fn add_batched_code(&mut self, code: Code, code_dir: CodeDir) -> Result<(), SessionError>
     {
         for (ref key, ref idx) in code_dir.iter() {
index b079eef29bb999df6574601268f6e028bf5f0daf..888b4454dbce0b2c40bb1e94d5919ee559042697 100644 (file)
@@ -43,7 +43,7 @@ pub fn read_toplevel(wam: &Machine) -> Result<Input, ParserError> {
             let mut parser = Parser::new(stdin.lock(), wam.atom_tbl(), wam.machine_flags());
             
             parser.add_to_top(buffer.as_str());
-            Ok(Input::Term(parser.read_term(&wam.op_dir)?))
+            Ok(Input::Term(parser.read_term(composite_op!(&wam.op_dir))?))
         }        
     }
 }
@@ -52,7 +52,7 @@ impl MachineState {
     pub fn read<R: Read>(&mut self, inner: R, op_dir: &OpDir) -> Result<usize, ParserError>
     {
         let mut parser = Parser::new(inner, self.atom_tbl.clone(), self.flags);
-        let term = parser.read_term(op_dir)?;
+        let term = parser.read_term(composite_op!(op_dir))?;
 
         Ok(write_term_to_heap(term, self))
     }
index 267695f680ddbbff5e10ecb5b2cb5ac4f881c3c8..e32a86e1bf8d90567c168d551a7c4729a592dc0f 100644 (file)
@@ -627,7 +627,8 @@ pub fn parse_term(term: Term, mut indices: MachineCodeIndices) -> Result<TopLeve
 pub struct TopLevelBatchWorker<R: Read> {
     parser: Parser<R>,
     rel_worker: RelationWorker,
-    pub results: Vec<(Predicate, VecDeque<TopLevel>)>
+    pub results: Vec<(Predicate, VecDeque<TopLevel>)>,
+    pub in_module: bool
 }
 
 impl<R: Read> TopLevelBatchWorker<R> {
@@ -635,11 +636,19 @@ impl<R: Read> TopLevelBatchWorker<R> {
     {
         TopLevelBatchWorker { parser: Parser::new(inner, atom_tbl, flags),
                               rel_worker: RelationWorker::new(),
-                              results: vec![] }
+                              results: vec![],
+                              in_module: false }
     }    
 
+    #[inline]
+    fn read_term(&mut self, static_op_dir: &OpDir, op_dir: &OpDir) -> Result<Term, ParserError> {
+        let composite_op = composite_op!(self.in_module, op_dir, static_op_dir);
+        self.parser.read_term(composite_op)
+    }
+    
     pub
-    fn consume(&mut self, indices: &mut MachineCodeIndices) -> Result<Option<Declaration>, SessionError>
+    fn consume(&mut self, op_dir: &OpDir, indices: &mut MachineCodeIndices)
+               -> Result<Option<Declaration>, SessionError>
     {
         let mut preds = vec![];
 
@@ -647,7 +656,7 @@ impl<R: Read> TopLevelBatchWorker<R> {
             self.parser.reset(); // empty the parser stack of token descriptions.
 
             let mut new_rel_worker = RelationWorker::new();
-            let term = self.parser.read_term(&indices.op_dir)?;
+            let term = self.read_term(op_dir, &indices.op_dir)?;
             let tl = new_rel_worker.try_term_to_tl(indices, term, true)?;
 
             if !is_consistent(&tl, &preds) {  // if is_consistent returns false, preds is non-empty.