From ccbc0566ba17429ac470c78e681e254838b53e5f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 12 Sep 2018 23:31:29 -0600 Subject: [PATCH] provisional changes #2 --- Cargo.lock | 8 +++----- Cargo.toml | 4 ++-- src/prolog/compile.rs | 14 +++++++------- src/prolog/machine/mod.rs | 6 +----- src/prolog/read.rs | 4 ++-- src/prolog/toplevel.rs | 17 +++++++++++++---- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42d1dbcf..6ed1a05a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 9080870d..3ed2e17e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rusty-wam" -version = "0.7.9" +version = "0.7.10" authors = ["Mark Thom "] 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 diff --git a/src/prolog/compile.rs b/src/prolog/compile.rs index 94feb835..30f4b39d 100644 --- a/src/prolog/compile.rs +++ b/src/prolog/compile.rs @@ -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); diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index d07bf29b..8f96705e 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -175,11 +175,7 @@ impl Machine { pub fn atom_tbl(&self) -> TabledData { 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() { diff --git a/src/prolog/read.rs b/src/prolog/read.rs index b079eef2..888b4454 100644 --- a/src/prolog/read.rs +++ b/src/prolog/read.rs @@ -43,7 +43,7 @@ pub fn read_toplevel(wam: &Machine) -> Result { 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(&mut self, inner: R, op_dir: &OpDir) -> Result { 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)) } diff --git a/src/prolog/toplevel.rs b/src/prolog/toplevel.rs index 267695f6..e32a86e1 100644 --- a/src/prolog/toplevel.rs +++ b/src/prolog/toplevel.rs @@ -627,7 +627,8 @@ pub fn parse_term(term: Term, mut indices: MachineCodeIndices) -> Result { parser: Parser, rel_worker: RelationWorker, - pub results: Vec<(Predicate, VecDeque)> + pub results: Vec<(Predicate, VecDeque)>, + pub in_module: bool } impl TopLevelBatchWorker { @@ -635,11 +636,19 @@ impl TopLevelBatchWorker { { 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 { + 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, SessionError> + fn consume(&mut self, op_dir: &OpDir, indices: &mut MachineCodeIndices) + -> Result, SessionError> { let mut preds = vec![]; @@ -647,7 +656,7 @@ impl TopLevelBatchWorker { 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. -- 2.54.0