equate chars with atoms consisting of chars
This commit is contained in:
@@ -527,7 +527,7 @@ pub enum Fixity {
|
|||||||
In, Post, Pre
|
In, Post, Pre
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, Hash, PartialEq)]
|
#[derive(Clone, Hash)]
|
||||||
pub enum Constant {
|
pub enum Constant {
|
||||||
Atom(ClauseName),
|
Atom(ClauseName),
|
||||||
Char(char),
|
Char(char),
|
||||||
@@ -537,6 +537,37 @@ pub enum Constant {
|
|||||||
EmptyList
|
EmptyList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Constant {
|
||||||
|
fn eq(&self, other: &Constant) -> bool {
|
||||||
|
match (self, other) {
|
||||||
|
(&Constant::Atom(ref atom), &Constant::Char(c))
|
||||||
|
| (&Constant::Char(c), &Constant::Atom(ref atom)) => {
|
||||||
|
let s = atom.as_str();
|
||||||
|
if c.len_utf8() != s.len() || Some(c) != s.chars().next() {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(&Constant::Atom(ref a1), &Constant::Atom(ref a2)) =>
|
||||||
|
a1.as_str() == a2.as_str(),
|
||||||
|
(&Constant::Char(c1), &Constant::Char(c2)) =>
|
||||||
|
c1 == c2,
|
||||||
|
(&Constant::Number(ref n1), &Constant::Number(ref n2)) =>
|
||||||
|
n1 == n2,
|
||||||
|
(&Constant::String(ref s1), &Constant::String(ref s2)) =>
|
||||||
|
s1 == s2,
|
||||||
|
(&Constant::EmptyList, &Constant::EmptyList) =>
|
||||||
|
true,
|
||||||
|
(&Constant::Usize(u1), &Constant::Usize(u2)) =>
|
||||||
|
u1 == u2,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for Constant {}
|
||||||
|
|
||||||
impl Constant {
|
impl Constant {
|
||||||
pub fn to_atom(self) -> Option<ClauseName> {
|
pub fn to_atom(self) -> Option<ClauseName> {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -190,13 +190,6 @@ impl MachineState {
|
|||||||
|
|
||||||
self.fail = true;
|
self.fail = true;
|
||||||
},
|
},
|
||||||
(Addr::Con(Constant::Char(c)), Addr::Con(Constant::Atom(atom)))
|
|
||||||
| (Addr::Con(Constant::Atom(atom)), Addr::Con(Constant::Char(c))) => {
|
|
||||||
let s = atom.as_str();
|
|
||||||
if c.len_utf8() != s.len() || Some(c) != s.chars().next() {
|
|
||||||
self.fail = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(Addr::Lis(a1), Addr::Con(Constant::String(ref s)))
|
(Addr::Lis(a1), Addr::Con(Constant::String(ref s)))
|
||||||
| (Addr::Con(Constant::String(ref s)), Addr::Lis(a1))
|
| (Addr::Con(Constant::String(ref s)), Addr::Lis(a1))
|
||||||
if self.flags.double_quotes.is_chars() =>
|
if self.flags.double_quotes.is_chars() =>
|
||||||
@@ -208,7 +201,7 @@ impl MachineState {
|
|||||||
pdl.push(Addr::HeapCell(a1));
|
pdl.push(Addr::HeapCell(a1));
|
||||||
} else {
|
} else {
|
||||||
self.fail = true;
|
self.fail = true;
|
||||||
},
|
},
|
||||||
(Addr::Con(Constant::EmptyList), Addr::Con(Constant::String(ref s)))
|
(Addr::Con(Constant::EmptyList), Addr::Con(Constant::String(ref s)))
|
||||||
| (Addr::Con(Constant::String(ref s)), Addr::Con(Constant::EmptyList))
|
| (Addr::Con(Constant::String(ref s)), Addr::Con(Constant::EmptyList))
|
||||||
if self.flags.double_quotes.is_chars() => {
|
if self.flags.double_quotes.is_chars() => {
|
||||||
@@ -221,7 +214,7 @@ impl MachineState {
|
|||||||
pdl.push(Addr::HeapCell(a1 + 1));
|
pdl.push(Addr::HeapCell(a1 + 1));
|
||||||
pdl.push(Addr::HeapCell(a2 + 1));
|
pdl.push(Addr::HeapCell(a2 + 1));
|
||||||
},
|
},
|
||||||
(Addr::Con(c1), Addr::Con(c2)) =>
|
(Addr::Con(ref c1), Addr::Con(ref c2)) =>
|
||||||
if c1 != c2 {
|
if c1 != c2 {
|
||||||
self.fail = true;
|
self.fail = true;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user