edit README, ast, remove redundant modules

This commit is contained in:
Mark Thom
2018-09-03 22:02:15 -06:00
parent ff9d2662e6
commit 1c1eda8345
5 changed files with 11 additions and 239 deletions

4
Cargo.lock generated
View File

@@ -87,6 +87,7 @@ dependencies = [
[[package]] [[package]]
name = "prolog_parser" name = "prolog_parser"
version = "0.7.9" version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"num 0.2.0 (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)", "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)", "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)", "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)", "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)", "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.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 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 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_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 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" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"

View File

@@ -85,18 +85,15 @@ strings.
First, install the latest stable version of First, install the latest stable version of
[Rust](https://www.rust-lang.org/en-US/install.html) using your [Rust](https://www.rust-lang.org/en-US/install.html) using your
preferred method. Then clone the rusty-wam repo and build it with preferred method. Then install the latest rusty-wam with cargo,
cargo, like so: like so:
``` ```
$> git clone https://github.com/mthom/rusty-wam --recursive $> cargo install rusty-wam
$> cd rusty-wam
$> cargo build
``` ```
cargo will download and install the libraries rusty-wam uses cargo will download and install the libraries rusty-wam uses
automatically. rusty-wam can be run with the command `cargo run`, and automatically.
likewise tests can be run with `cargo test`.
Note on compatibility: rusty-wam should work on Linux, Mac OS X, and Note on compatibility: rusty-wam should work on Linux, Mac OS X, and
FreeBSD. Windows support hinges on the Termion library working in FreeBSD. Windows support hinges on the Termion library working in

View File

@@ -8,7 +8,7 @@ use std::rc::Rc;
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub enum InlinedClauseType { pub enum InlinedClauseType {
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
IsAtom(RegType), IsAtom(RegType),
IsAtomic(RegType), IsAtomic(RegType),
IsCompound(RegType), IsCompound(RegType),
@@ -34,7 +34,7 @@ impl InlinedClauseType {
&InlinedClauseType::IsFloat (..) => "float", &InlinedClauseType::IsFloat (..) => "float",
&InlinedClauseType::IsNonVar(..) => "nonvar", &InlinedClauseType::IsNonVar(..) => "nonvar",
&InlinedClauseType::IsPartialString(..) => "partial_string", &InlinedClauseType::IsPartialString(..) => "partial_string",
&InlinedClauseType::IsVar(..) => "var", &InlinedClauseType::IsVar(..) => "var",
} }
} }
@@ -317,7 +317,7 @@ impl SystemClauseType {
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub enum BuiltInClauseType { pub enum BuiltInClauseType {
AcyclicTerm, AcyclicTerm,
Arg, Arg,
Compare, Compare,
CompareTerm(CompareTermQT), CompareTerm(CompareTermQT),
CyclicTerm, CyclicTerm,
@@ -417,7 +417,7 @@ impl BuiltInClauseType {
("keysort", 2) => Some(BuiltInClauseType::KeySort), ("keysort", 2) => Some(BuiltInClauseType::KeySort),
("\\==", 2) => Some(BuiltInClauseType::NotEq), ("\\==", 2) => Some(BuiltInClauseType::NotEq),
("sort", 2) => Some(BuiltInClauseType::Sort), ("sort", 2) => Some(BuiltInClauseType::Sort),
("read", 1) => Some(BuiltInClauseType::Read), ("read", 1) => Some(BuiltInClauseType::Read),
_ => None _ => None
} }
} }

View File

@@ -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<String>);
impl Hash for StringListWrapper {
fn hash<H: Hasher>(&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<StringListWrapper>,
cursor: usize, // use this to generate a chars() iterator on the fly,
// and skip over the first cursor chars.
expandable: Rc<Cell<bool>>
}
impl Hash for StringList {
#[inline]
fn hash<H: Hasher>(&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<Ordering> {
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<char> {
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<String> {
self.body.0.borrow()
}
}

View File

@@ -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<T> = Rc<RefCell<HashSet<Rc<T>>>>;
pub struct TabledRc<T: Hash + Eq> {
atom: Rc<T>,
table: TabledData<T>
}
// this Clone instance is manually defined to prevent the compiler
// from complaining when deriving Clone for StringList.
impl<T: Hash + Eq> Clone for TabledRc<T> {
fn clone(&self) -> Self {
TabledRc { atom: self.atom.clone(), table: self.table().clone() }
}
}
impl<T: Ord + Hash + Eq> PartialOrd for TabledRc<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
{
Some(self.atom.cmp(&other.atom))
}
}
impl<T: Ord + Hash + Eq> Ord for TabledRc<T> {
fn cmp(&self, other: &Self) -> Ordering
{
self.atom.cmp(&other.atom)
}
}
impl<T: Hash + Eq> PartialEq for TabledRc<T> {
fn eq(&self, other: &TabledRc<T>) -> bool
{
self.atom == other.atom
}
}
impl<T: Hash + Eq> Eq for TabledRc<T> {}
impl<T: Hash + Eq> Hash for TabledRc<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.atom.hash(state)
}
}
impl<T: Hash + Eq> TabledRc<T> {
pub fn new(atom: T, table: TabledData<T>) -> 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<T> {
self.table.clone()
}
}
impl<T: Hash + Eq> Drop for TabledRc<T> {
fn drop(&mut self) {
if Rc::strong_count(&self.atom) == 2 {
self.table.borrow_mut().remove(&self.atom);
}
}
}
impl<T: Hash + Eq> Deref for TabledRc<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&*self.atom
}
}
impl<T: Hash + Eq + fmt::Display> fmt::Display for TabledRc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", &*self.atom)
}
}