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

View File

@@ -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
}
}

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)
}
}