From: Mark Thom Date: Tue, 4 Sep 2018 04:02:15 +0000 (-0600) Subject: edit README, ast, remove redundant modules X-Git-Tag: v0.8.110~397 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=1c1eda83457c042d006b2ebc0f500fc2b0d587e6;p=scryer-prolog.git edit README, ast, remove redundant modules --- diff --git a/Cargo.lock b/Cargo.lock index a33c62b1..69c93678 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ dependencies = [ [[package]] name = "prolog_parser" version = "0.7.9" +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)", @@ -112,7 +113,7 @@ 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.9", + "prolog_parser 0.7.9 (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.9 (registry+https://github.com/rust-lang/crates.io-index)" = "21a50c17076ba5b0028835c7a2c37a2f434f53dfa4c55e51381118bb1491817b" "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/README.md b/README.md index 8deb3cee..9c808733 100644 --- a/README.md +++ b/README.md @@ -85,18 +85,15 @@ strings. First, install the latest stable version of [Rust](https://www.rust-lang.org/en-US/install.html) using your -preferred method. Then clone the rusty-wam repo and build it with -cargo, like so: +preferred method. Then install the latest rusty-wam with cargo, +like so: ``` -$> git clone https://github.com/mthom/rusty-wam --recursive -$> cd rusty-wam -$> cargo build +$> cargo install rusty-wam ``` cargo will download and install the libraries rusty-wam uses -automatically. rusty-wam can be run with the command `cargo run`, and -likewise tests can be run with `cargo test`. +automatically. Note on compatibility: rusty-wam should work on Linux, Mac OS X, and FreeBSD. Windows support hinges on the Termion library working in diff --git a/src/prolog/ast.rs b/src/prolog/ast.rs index 9a7fbf59..c3e714c9 100644 --- a/src/prolog/ast.rs +++ b/src/prolog/ast.rs @@ -8,7 +8,7 @@ use std::rc::Rc; #[derive(Clone, PartialEq)] pub enum InlinedClauseType { - CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), + CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), IsAtom(RegType), IsAtomic(RegType), IsCompound(RegType), @@ -34,7 +34,7 @@ impl InlinedClauseType { &InlinedClauseType::IsFloat (..) => "float", &InlinedClauseType::IsNonVar(..) => "nonvar", &InlinedClauseType::IsPartialString(..) => "partial_string", - &InlinedClauseType::IsVar(..) => "var", + &InlinedClauseType::IsVar(..) => "var", } } @@ -317,7 +317,7 @@ impl SystemClauseType { #[derive(Clone, PartialEq)] pub enum BuiltInClauseType { AcyclicTerm, - Arg, + Arg, Compare, CompareTerm(CompareTermQT), CyclicTerm, @@ -417,7 +417,7 @@ impl BuiltInClauseType { ("keysort", 2) => Some(BuiltInClauseType::KeySort), ("\\==", 2) => Some(BuiltInClauseType::NotEq), ("sort", 2) => Some(BuiltInClauseType::Sort), - ("read", 1) => Some(BuiltInClauseType::Read), + ("read", 1) => Some(BuiltInClauseType::Read), _ => None } } diff --git a/src/prolog/string_list.rs b/src/prolog/string_list.rs deleted file mode 100644 index dd021a7b..00000000 --- a/src/prolog/string_list.rs +++ /dev/null @@ -1,137 +0,0 @@ -use std::cell::{Cell, Ref, RefCell}; -use std::cmp::Ordering; -use std::hash::{Hash, Hasher}; -use std::rc::Rc; - -#[derive(PartialOrd, PartialEq, Ord, Eq)] -pub struct StringListWrapper(RefCell); - -impl Hash for StringListWrapper { - fn hash(&self, state: &mut H) { - self.0.borrow().hash(state) - } -} - -// cursor is ignored if the double_quotes flag is set to atom -#[derive(Clone)] -pub struct StringList { - body: Rc, - cursor: usize, // use this to generate a chars() iterator on the fly, - // and skip over the first cursor chars. - expandable: Rc> -} - -impl Hash for StringList { - #[inline] - fn hash(&self, state: &mut H) { - (self.borrow().as_str(), self.cursor, self.expandable.get()).hash(state); - } -} - -impl PartialOrd for StringList { - #[inline] - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.body.cmp(&other.body)) - } -} - -impl Ord for StringList { - #[inline] - fn cmp(&self, other: &Self) -> Ordering { - if self.expandable.get() && !self.expandable.get() { - Ordering::Greater - } else if !self.expandable.get() && self.expandable.get() { - Ordering::Less - } else { - self.borrow()[self.cursor ..].cmp(&other.borrow()[other.cursor ..]) - } - } -} - -impl PartialEq for StringList { - #[inline] - fn eq(&self, other: &Self) -> bool { - Rc::ptr_eq(&self.body, &other.body) - } -} - -impl Eq for StringList {} - -impl StringList { - #[inline] - pub fn new(s: String, expandable: bool) -> Self { - let body = Rc::new(StringListWrapper(RefCell::new(s))); - - StringList { - cursor: 0, - body, - expandable: Rc::new(Cell::new(expandable)) - } - } - - #[inline] - pub fn is_expandable(&self) -> bool { - self.expandable.get() - } - - #[inline] - pub fn set_expandable(&self) { - self.expandable.set(true); - } - - #[inline] - pub fn set_non_expandable(&self) { - self.expandable.set(false); - } - - #[inline] - pub fn push_char(&mut self, c: char) -> Self { - if self.expandable.get() { - self.body.0.borrow_mut().push(c); - - let mut new_string_list = self.clone(); - new_string_list.cursor += c.len_utf8(); - - new_string_list - } else { - self.clone() - } - } - - #[inline] - pub fn append(&mut self, s: &StringList) { - self.body.0.borrow_mut().extend(s.borrow()[s.cursor ..].chars()); - self.expandable.set(s.expandable.get()); - } - - #[inline] - pub fn cursor(&self) -> usize { - self.cursor - } - - #[inline] - pub fn head(&self) -> Option { - self.borrow()[self.cursor ..].chars().next() - } - - #[inline] - pub fn tail(&self) -> Self { - let mut new_string_list = self.clone(); - - if let Some(c) = self.head() { - new_string_list.cursor += c.len_utf8(); - } - - new_string_list - } - - #[inline] - pub fn is_empty(&self) -> bool { - self.borrow().len() == self.cursor - } - - #[inline] - pub fn borrow(&self) -> Ref { - self.body.0.borrow() - } -} diff --git a/src/prolog/tabled_rc.rs b/src/prolog/tabled_rc.rs deleted file mode 100644 index a7a093fb..00000000 --- a/src/prolog/tabled_rc.rs +++ /dev/null @@ -1,90 +0,0 @@ -use std::cell::RefCell; -use std::cmp::Ordering; -use std::collections::HashSet; -use std::fmt; -use std::hash::{Hash, Hasher}; -use std::ops::Deref; -use std::rc::Rc; - -pub type TabledData = Rc>>>; - -pub struct TabledRc { - atom: Rc, - table: TabledData -} - -// this Clone instance is manually defined to prevent the compiler -// from complaining when deriving Clone for StringList. -impl Clone for TabledRc { - fn clone(&self) -> Self { - TabledRc { atom: self.atom.clone(), table: self.table().clone() } - } -} - -impl PartialOrd for TabledRc { - fn partial_cmp(&self, other: &Self) -> Option - { - Some(self.atom.cmp(&other.atom)) - } -} - -impl Ord for TabledRc { - fn cmp(&self, other: &Self) -> Ordering - { - self.atom.cmp(&other.atom) - } -} - -impl PartialEq for TabledRc { - fn eq(&self, other: &TabledRc) -> bool - { - self.atom == other.atom - } -} - -impl Eq for TabledRc {} - -impl Hash for TabledRc { - fn hash(&self, state: &mut H) { - self.atom.hash(state) - } -} - -impl TabledRc { - pub fn new(atom: T, table: TabledData) -> Self { - let atom = match table.borrow_mut().take(&atom) { - Some(atom) => atom.clone(), - None => Rc::new(atom) - }; - - table.borrow_mut().insert(atom.clone()); - - TabledRc { atom, table } - } - - pub fn table(&self) -> TabledData { - self.table.clone() - } -} - -impl Drop for TabledRc { - fn drop(&mut self) { - if Rc::strong_count(&self.atom) == 2 { - self.table.borrow_mut().remove(&self.atom); - } - } -} - -impl Deref for TabledRc { - type Target = T; - - fn deref(&self) -> &Self::Target { - &*self.atom - } -} - -impl fmt::Display for TabledRc { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", &*self.atom) - } -}