Commit 8418db1e authored by Jeff Smits's avatar Jeff Smits

cargo fmt

parent 39f8cb86
...@@ -13,7 +13,7 @@ use std::cell::RefCell; ...@@ -13,7 +13,7 @@ use std::cell::RefCell;
/// This context is internally mutable in `RefCell` fields. This is just for convenience as we don't /// This context is internally mutable in `RefCell` fields. This is just for convenience as we don't
/// want to pass around the mutable fields separately. But the internal mutability is not a hidden /// want to pass around the mutable fields separately. But the internal mutability is not a hidden
/// thing, there is observable effect, so the name of the context includes `Mut`. /// thing, there is observable effect, so the name of the context includes `Mut`.
pub struct MutContext<'d, 'f : 'd> { pub struct MutContext<'d, 'f: 'd> {
pub stack_tracer: RefCell<StackTracer<'f>>, pub stack_tracer: RefCell<StackTracer<'f>>,
pub scopes: RefCell<Vec<Scope<'d, 'f, ATermRef<'f>>>>, pub scopes: RefCell<Vec<Scope<'d, 'f, ATermRef<'f>>>>,
pub factory: &'f ATermFactory, pub factory: &'f ATermFactory,
...@@ -21,7 +21,7 @@ pub struct MutContext<'d, 'f : 'd> { ...@@ -21,7 +21,7 @@ pub struct MutContext<'d, 'f : 'd> {
pub ssl_state: RefCell<State<'f>>, pub ssl_state: RefCell<State<'f>>,
} }
impl<'d, 'f : 'd> MutContext<'d, 'f> { impl<'d, 'f: 'd> MutContext<'d, 'f> {
pub fn new( pub fn new(
factory: &'f ATermFactory, factory: &'f ATermFactory,
scopes: Vec<Scope<'d, 'f, ATermRef<'f>>>, scopes: Vec<Scope<'d, 'f, ATermRef<'f>>>,
...@@ -72,9 +72,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> { ...@@ -72,9 +72,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
} }
pub fn get_term(&self, term_name: &str) -> Result<ATermRef<'f>> { pub fn get_term(&self, term_name: &str) -> Result<ATermRef<'f>> {
Scopes::get_term_option(&self.scopes.borrow(), term_name).and_then(|(_, o)| { Scopes::get_term_option(&self.scopes.borrow(), term_name)
o.ok_or(Error::StrategyFailed) .and_then(|(_, o)| o.ok_or(Error::StrategyFailed))
})
} }
pub fn match_term(&self, term_name: &'f str, current: &ATermRef<'f>) -> Result<()> { pub fn match_term(&self, term_name: &'f str, current: &ATermRef<'f>) -> Result<()> {
...@@ -144,8 +143,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> { ...@@ -144,8 +143,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
"clear_overlay: Interpreter bug, unexpected end of stack", "clear_overlay: Interpreter bug, unexpected end of stack",
); );
debug_assert!( debug_assert!(
last_scope.is_overlay, last_scope.is_overlay,
"clear_overlay: Interpreter bug, unexpected normal scope" "clear_overlay: Interpreter bug, unexpected normal scope"
); );
last_scope.term.clear(); last_scope.term.clear();
} }
...@@ -236,12 +235,14 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> { ...@@ -236,12 +235,14 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> {
pub fn from_let_defs<I>(no_of_scopes: usize, defs: I) -> Self pub fn from_let_defs<I>(no_of_scopes: usize, defs: I) -> Self
where where
I: IntoIterator<Item=&'d Def<'f>>, I: IntoIterator<Item = &'d Def<'f>>,
{ {
Scope { Scope {
term: FnvHashMap::default(), term: FnvHashMap::default(),
strategy: defs.into_iter() strategy: defs.into_iter()
.map(|def| (def.name, StrategyDef::from_let_def(def, no_of_scopes))) .map(|def| {
(def.name, StrategyDef::from_let_def(def, no_of_scopes))
})
.collect(), .collect(),
is_overlay: false, is_overlay: false,
} }
...@@ -252,7 +253,10 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> { ...@@ -252,7 +253,10 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> {
I: IntoIterator<Item = &'f str>, I: IntoIterator<Item = &'f str>,
{ {
Scope { Scope {
term: fresh_vars.into_iter().map(|fresh_var| (fresh_var, None)).collect(), term: fresh_vars
.into_iter()
.map(|fresh_var| (fresh_var, None))
.collect(),
strategy: FnvHashMap::default(), strategy: FnvHashMap::default(),
is_overlay: false, is_overlay: false,
} }
...@@ -268,13 +272,13 @@ pub mod Scopes { ...@@ -268,13 +272,13 @@ pub mod Scopes {
term_name: &str, term_name: &str,
) -> Result<(usize, Option<ATermRef<'f>>)> { ) -> Result<(usize, Option<ATermRef<'f>>)> {
let mut offset = None; let mut offset = None;
for (n,scope) in scopes.iter().enumerate().rev() { for (n, scope) in scopes.iter().enumerate().rev() {
if offset == None && scope.is_overlay { if offset == None && scope.is_overlay {
offset = Some(n); offset = Some(n);
} }
if let Some(binding) = scope.term.get(term_name) { if let Some(binding) = scope.term.get(term_name) {
let n = offset.unwrap_or(n); let n = offset.unwrap_or(n);
return Ok((n, binding.clone())) return Ok((n, binding.clone()));
} }
} }
Err(Error::UndefinedVariable(term_name.to_owned())) Err(Error::UndefinedVariable(term_name.to_owned()))
...@@ -297,11 +301,11 @@ pub mod Scopes { ...@@ -297,11 +301,11 @@ pub mod Scopes {
(n, None) => { (n, None) => {
if let Some(Some(t)) = scopes[n].term.insert(term_name, Some(current.clone())) { if let Some(Some(t)) = scopes[n].term.insert(term_name, Some(current.clone())) {
unreachable!(format!( unreachable!(format!(
"match_term: No scope had {}, but we just \ "match_term: No scope had {}, but we just \
replaced {} when we added it?!", replaced {} when we added it?!",
term_name, term_name,
t t
)) ))
} else { } else {
return Ok(()); return Ok(());
} }
......
...@@ -49,8 +49,7 @@ impl<'s> fmt::Display for Module<'s> { ...@@ -49,8 +49,7 @@ impl<'s> fmt::Display for Module<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Module<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Module<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -112,8 +111,7 @@ impl<'s> fmt::Display for Decl<'s> { ...@@ -112,8 +111,7 @@ impl<'s> fmt::Display for Decl<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Decl<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Decl<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -157,8 +155,7 @@ impl<'s> fmt::Display for ImportModName<'s> { ...@@ -157,8 +155,7 @@ impl<'s> fmt::Display for ImportModName<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ImportModName<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ImportModName<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -210,8 +207,7 @@ impl<'s> fmt::Display for SDecl<'s> { ...@@ -210,8 +207,7 @@ impl<'s> fmt::Display for SDecl<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SDecl<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SDecl<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -245,12 +241,8 @@ impl<'s> fmt::Display for Sort<'s> { ...@@ -245,12 +241,8 @@ impl<'s> fmt::Display for Sort<'s> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Sort::*; use self::Sort::*;
match *self { match *self {
SortVar(ref lcid) => { SortVar(ref lcid) => lcid.fmt(f),
lcid.fmt(f) SortNoArgs(ref ucid) => ucid.fmt(f),
}
SortNoArgs(ref ucid) => {
ucid.fmt(f)
}
Sort(ref id, ref sorts) => { Sort(ref id, ref sorts) => {
write!(f, "{}(", id)?; write!(f, "{}(", id)?;
for sort in sorts.iter() { for sort in sorts.iter() {
...@@ -262,8 +254,7 @@ impl<'s> fmt::Display for Sort<'s> { ...@@ -262,8 +254,7 @@ impl<'s> fmt::Display for Sort<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Sort<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Sort<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -307,25 +298,16 @@ impl<'s> fmt::Display for OpDecl<'s> { ...@@ -307,25 +298,16 @@ impl<'s> fmt::Display for OpDecl<'s> {
use self::OpDecl::*; use self::OpDecl::*;
match *self { match *self {
OpDecl(ref s, ref ty) | OpDecl(ref s, ref ty) |
OpDeclQ(ref s, ref ty) => { OpDeclQ(ref s, ref ty) => writeln!(f, "{}: {}", s, ty),
writeln!(f, "{}: {}", s, ty) OpDeclInj(ref ty) => writeln!(f, ": {}", ty),
}
OpDeclInj(ref ty) => {
writeln!(f, ": {}", ty)
}
ExtOpDecl(ref s, ref ty) | ExtOpDecl(ref s, ref ty) |
ExtOpDeclQ(ref s, ref ty) => { ExtOpDeclQ(ref s, ref ty) => writeln!(f, "external {}: {}", s, ty),
writeln!(f, "external {}: {}", s, ty) ExtOpDeclInj(ref ty) => writeln!(f, "external : {}", ty),
}
ExtOpDeclInj(ref ty) => {
writeln!(f, "external : {}", ty)
}
} }
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for OpDecl<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for OpDecl<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -382,8 +364,7 @@ impl<'s> fmt::Display for ConstType<'s> { ...@@ -382,8 +364,7 @@ impl<'s> fmt::Display for ConstType<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ConstType<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ConstType<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -417,15 +398,12 @@ impl<'s> fmt::Display for Type<'s> { ...@@ -417,15 +398,12 @@ impl<'s> fmt::Display for Type<'s> {
} }
write!(f, "-> {}", rettype) write!(f, "-> {}", rettype)
} }
ConstType(ref sort) => { ConstType(ref sort) => sort.fmt(f),
sort.fmt(f)
}
} }
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Type<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Type<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -471,7 +449,7 @@ impl<'s> fmt::Display for Def<'s> { ...@@ -471,7 +449,7 @@ impl<'s> fmt::Display for Def<'s> {
write!(f, "{}, ", vardec)?; write!(f, "{}, ", vardec)?;
} }
write!(f, ") =\n {}", strategy) write!(f, ") =\n {}", strategy)
}, }
ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => { ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => {
write!(f, "external {}(", id)?; write!(f, "external {}(", id)?;
for vardec in vardecs1 { for vardec in vardecs1 {
...@@ -508,8 +486,7 @@ impl<'s> fmt::Display for Def<'s> { ...@@ -508,8 +486,7 @@ impl<'s> fmt::Display for Def<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Def<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Def<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -569,8 +546,7 @@ impl<'s> fmt::Display for SVar<'s> { ...@@ -569,8 +546,7 @@ impl<'s> fmt::Display for SVar<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SVar<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SVar<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -607,7 +583,7 @@ impl<'s> fmt::Display for StrategyDef<'s> { ...@@ -607,7 +583,7 @@ impl<'s> fmt::Display for StrategyDef<'s> {
write!(f, "{}, ", vardec)?; write!(f, "{}, ", vardec)?;
} }
write!(f, ") =\n {}", strategy) write!(f, ") =\n {}", strategy)
}, }
ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => { ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => {
write!(f, "external {}(", id)?; write!(f, "external {}(", id)?;
for vardec in vardecs1 { for vardec in vardecs1 {
...@@ -638,8 +614,7 @@ impl<'s> fmt::Display for StrategyDef<'s> { ...@@ -638,8 +614,7 @@ impl<'s> fmt::Display for StrategyDef<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for StrategyDef<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for StrategyDef<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -716,8 +691,7 @@ impl fmt::Display for Anno { ...@@ -716,8 +691,7 @@ impl fmt::Display for Anno {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Anno impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Anno {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -755,8 +729,7 @@ impl<'s> fmt::Display for VarDec<'s> { ...@@ -755,8 +729,7 @@ impl<'s> fmt::Display for VarDec<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for VarDec<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for VarDec<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -851,7 +824,9 @@ impl<'s> fmt::Display for Strategy<'s> { ...@@ -851,7 +824,9 @@ impl<'s> fmt::Display for Strategy<'s> {
write!(f, " : {} }}", strategy) write!(f, " : {} }}", strategy)
} }
Seq(ref first, ref second) => write!(f, "{}; {}", first, second), Seq(ref first, ref second) => write!(f, "{}; {}", first, second),
GuardedLChoice(ref s_if, ref s_then, ref s_else) => write!(f, "{} < {} + {}", s_if, s_then, s_else), GuardedLChoice(ref s_if, ref s_then, ref s_else) => {
write!(f, "{} < {} + {}", s_if, s_then, s_else)
}
PrimT(ref string, ref strategies, ref terms) => { PrimT(ref string, ref strategies, ref terms) => {
write!(f, "prim({},", string)?; write!(f, "prim({},", string)?;
for strategy in strategies.iter() { for strategy in strategies.iter() {
...@@ -871,8 +846,7 @@ impl<'s> fmt::Display for Strategy<'s> { ...@@ -871,8 +846,7 @@ impl<'s> fmt::Display for Strategy<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Strategy<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Strategy<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -1006,8 +980,7 @@ impl<'s> fmt::Display for Var<'s> { ...@@ -1006,8 +980,7 @@ impl<'s> fmt::Display for Var<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Var<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Var<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -1043,8 +1016,7 @@ impl<'s> fmt::Display for Term<'s> { ...@@ -1043,8 +1016,7 @@ impl<'s> fmt::Display for Term<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Term<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Term<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -1116,8 +1088,7 @@ impl<'s> fmt::Display for PreTerm<'s> { ...@@ -1116,8 +1088,7 @@ impl<'s> fmt::Display for PreTerm<'s> {
} }
} }
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s> impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s> {
{
type Err = Error; type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> { fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
...@@ -1188,7 +1159,7 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s> ...@@ -1188,7 +1159,7 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s>
fn match_string<'s>(r: &ATermRef<'s>) -> Result<&'s str, Error> { fn match_string<'s>(r: &ATermRef<'s>) -> Result<&'s str, Error> {
if let FTerm::String(str) = r.term { if let FTerm::String(str) = r.term {
return Ok(str) return Ok(str);
} }
Err(Error::CTreeParse("string")) Err(Error::CTreeParse("string"))
} }
......
...@@ -22,7 +22,10 @@ pub struct IndexedSet<'s>(FnvHashMap<ATermRef<'s>, u16>, u16); ...@@ -22,7 +22,10 @@ pub struct IndexedSet<'s>(FnvHashMap<ATermRef<'s>, u16>, u16);
impl<'s> IndexedSet<'s> { impl<'s> IndexedSet<'s> {
pub fn with_capacity(capacity: usize) -> Self { pub fn with_capacity(capacity: usize) -> Self {
IndexedSet(FnvHashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()), 0) IndexedSet(
FnvHashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()),
0,
)
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {
...@@ -144,10 +147,12 @@ impl<'s> TermList<'s> { ...@@ -144,10 +147,12 @@ impl<'s> TermList<'s> {
fn from_iter<T>(iter: T) -> Self fn from_iter<T>(iter: T) -> Self
where where
T: IntoIterator<Item=ATermRef<'s>>, T: IntoIterator<Item = ATermRef<'s>>,
<T as IntoIterator>::IntoIter: DoubleEndedIterator, <T as IntoIterator>::IntoIter: DoubleEndedIterator,
{ {
iter.into_iter().rev().fold(TermList::Nil, |list, item| TermList::Cons(item, Rc::new(list))) iter.into_iter().rev().fold(TermList::Nil, |list, item| {
TermList::Cons(item, Rc::new(list))
})
} }
} }
...@@ -156,9 +161,7 @@ impl<'s> IntoIterator for TermList<'s> { ...@@ -156,9 +161,7 @@ impl<'s> IntoIterator for TermList<'s> {
type IntoIter = TermListIterator<'s>; type IntoIter = TermListIterator<'s>;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
TermListIterator { TermListIterator { listterm: Rc::new(self) }
listterm: Rc::new(self),
}
} }
} }
...@@ -182,7 +185,7 @@ impl<'s> Iterator for TermListIterator<'s> { ...@@ -182,7 +185,7 @@ impl<'s> Iterator for TermListIterator<'s> {
let (h, t) = if let Cons(ref h, ref t) = *self.listterm { let (h, t) = if let Cons(ref h, ref t) = *self.listterm {
(h.clone(), t.clone()) (h.clone(), t.clone())
} else { } else {
return None return None;
}; };
self.listterm = t; self.listterm = t;
...@@ -213,12 +216,8 @@ impl<'s, B: PartialEq> PartialEq for Term<'s, B> { ...@@ -213,12 +216,8 @@ impl<'s, B: PartialEq> PartialEq for Term<'s, B> {
(&Int(l), &Int(r)) => l == r, (&Int(l), &Int(r)) => l == r,
(&Long(l), &Long(r)) => l == r, (&Long(l), &Long(r)) => l == r,
(&Real(l), &Real(r)) => l == r, (&Real(l), &Real(r)) => l == r,
(&Application(lc, ref lch), &Application(rc, ref rch)) => { (&Application(lc, ref lch), &Application(rc, ref rch)) => ptr::eq(lc, rc) && lch == rch,
ptr::eq(lc, rc) && lch == rch (&String(lc), &String(rc)) => ptr::eq(lc, rc),
}
(&String(lc), &String(rc)) => {
ptr::eq(lc, rc)
}
(&List(ref l), &List(ref r)) => l == r, (&List(ref l), &List(ref r)) => l == r,
(&Placeholder(_, ref l), &Placeholder(_, ref r)) => l == r, (&Placeholder(_, ref l), &Placeholder(_, ref r)) => l == r,
(&Blob(ref l), &Blob(ref r)) => l == r, (&Blob(ref l), &Blob(ref r)) => l == r,
...@@ -239,7 +238,7 @@ where ...@@ -239,7 +238,7 @@ where
Long(l) => write!(writer, "{}", l), Long(l) => write!(writer, "{}", l),
Real(BrokenF32(r)) => write!(writer, "{}", r), Real(BrokenF32(r)) => write!(writer, "{}", r),
Application(cons, ref children) => { Application(cons, ref children) => {
// write!(writer, "{:p}#{}", cons, cons)?; // write!(writer, "{:p}#{}", cons, cons)?;
writer.write_str(cons)?; writer.write_str(cons)?;
if !children.is_empty() { if !children.is_empty() {
write!(writer, "(")?; write!(writer, "(")?;
...@@ -249,7 +248,7 @@ where ...@@ -249,7 +248,7 @@ where
Ok(()) Ok(())
} }
String(string) => { String(string) => {
// write!(writer, "{:p}#{:?}", string, string) // write!(writer, "{:p}#{:?}", string, string)
write!(writer, "{:?}", string) write!(writer, "{:?}", string)
} }
List(ref l) => { List(ref l) => {
...@@ -261,7 +260,7 @@ where ...@@ -261,7 +260,7 @@ where
write!(writer, "<")?; write!(writer, "<")?;
tp.to_ascii(writer)?; tp.to_ascii(writer)?;
write!(writer, ">") write!(writer, ">")
}, }
Blob(ref b) => b.to_ascii(writer), Blob(ref b) => b.to_ascii(writer),
} }
} }
...@@ -297,8 +296,7 @@ impl<'s> Hash for ATerm<'s> { ...@@ -297,8 +296,7 @@ impl<'s> Hash for ATerm<'s> {
} }
} }
impl<'s> ATermWrite for ATerm<'s> impl<'s> ATermWrite for ATerm<'s> {
{
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result { fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
let annotations = &self.annotations; let annotations = &self.annotations;
self.term.to_ascii(writer)?; self.term.to_ascii(writer)?;
...@@ -322,7 +320,7 @@ impl<'s> ATerm<'s> { ...@@ -322,7 +320,7 @@ impl<'s> ATerm<'s> {
ATerm { ATerm {
term: term, term: term,
annotations: Box::new([]), annotations: Box::new([]),
attachments: RefCell::new(Vec::new()) attachments: RefCell::new(Vec::new()),
} }
} }
...@@ -340,7 +338,7 @@ impl<'s> ATerm<'s> { ...@@ -340,7 +338,7 @@ impl<'s> ATerm<'s> {
pub fn with_annos_attachments<A, I>(term: Term<'s, Blob<'s>>, annos: A, attachments: I) -> Self pub fn with_annos_attachments<A, I>(term: Term<'s, Blob<'s>>, annos: A, attachments: I) -> Self
where where
A: IntoIterator<Item = ATermRef<'s>>, A: IntoIterator<Item = ATermRef<'s>>,
I: IntoIterator<Item=Attachment>, I: IntoIterator<Item = Attachment>,
{ {
ATerm { ATerm {
term: term, term: term,
...@@ -363,8 +361,8 @@ impl<'s> ATerm<'s> { ...@@ -363,8 +361,8 @@ impl<'s> ATerm<'s> {
#[allow(dead_code)] #[allow(dead_code)]
pub fn set_attachments<I>(&self, attachments: I) pub fn set_attachments<I>(&self, attachments: I)
where where
I: IntoIterator<Item=Attachment>, I: IntoIterator<Item = Attachment>,
{ {
*self.attachments.borrow_mut() = attachments.into_iter().collect(); *self.attachments.borrow_mut() = attachments.into_iter().collect();
} }
...@@ -452,15 +450,15 @@ pub struct ATermFactory { ...@@ -452,15 +450,15 @@ pub struct ATermFactory {
impl ATermFactory { impl ATermFactory {
pub fn new() -> Self { pub fn new() -> Self {
ATermFactory { ATermFactory { string_cache: RefCell::new(StringShare::new()) }
string_cache: RefCell::new(StringShare::new()),
}
} }
} }
impl<'s> ATermFactory { impl<'s> ATermFactory {
pub fn cons(&'s self, head: ATermRef<'s>, tail: Rc<TermList<'s>>) -> ATermRef<'s> { pub fn cons(&'s self, head: ATermRef<'s>, tail: Rc<TermList<'s>>) -> ATermRef<'s> {
Rc::new(ATerm::no_annos(Term::List(Rc::new(TermList::Cons(head, tail))))) Rc::new(ATerm::no_annos(
Term::List(Rc::new(TermList::Cons(head, tail))),
))
} }
pub fn nil(&'s self) -> ATermRef<'s> { pub fn nil(&'s self) -> ATermRef<'s> {
...@@ -471,16 +469,27 @@ impl<'s> ATermFactory { ...@@ -471,16 +469,27 @@ impl<'s> ATermFactory {
Rc::new(ATerm::no_annos(Term::List(list))) Rc::new(ATerm::no_annos(Term::List(list)))
} }
pub fn with_annos_attachments<I, A>(&'s self, aterm: ATermRef<'s>, annos: A, attachments: I) -> ATermRef<'s> pub fn with_annos_attachments<I, A>(
&'s self,
aterm: ATermRef<'s>,
annos: A,
attachments: I,
) -> ATermRef<'s>
where where
A: IntoIterator<Item=ATermRef<'s>>, A: IntoIterator<Item = ATermRef<'s>>,
I: IntoIterator<Item=Attachment>, I: IntoIterator<Item = Attachment>,
{