]> Repositorios git - scryer-prolog.git/commitdiff
equate chars with atoms consisting of chars
authorMark Thom <[email protected]>
Sat, 25 Aug 2018 05:14:41 +0000 (23:14 -0600)
committerMark Thom <[email protected]>
Sat, 25 Aug 2018 05:14:41 +0000 (23:14 -0600)
src/prolog/ast.rs
src/prolog/machine/machine_state_impl.rs

index 23425e9a0c01cd5a092cd2b13cd378f7f7519389..f8e0a3854f198459e4799216b9593f5f6953f1d9 100644 (file)
@@ -527,7 +527,7 @@ pub enum Fixity {
     In, Post, Pre
 }
 
-#[derive(Clone, Eq, Hash, PartialEq)]
+#[derive(Clone, Hash)]
 pub enum Constant {
     Atom(ClauseName),
     Char(char),
@@ -537,6 +537,37 @@ pub enum Constant {
     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 {
     pub fn to_atom(self) -> Option<ClauseName> {
         match self {
index 12db9d2a5b9f1f24a4cc6e1e1d547231802f1612..850b006846180427a41b4bc152b8711a1c40b919 100644 (file)
@@ -190,13 +190,6 @@ impl MachineState {
 
                         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::Con(Constant::String(ref s)), Addr::Lis(a1))
                         if self.flags.double_quotes.is_chars() =>
@@ -208,7 +201,7 @@ impl MachineState {
                                 pdl.push(Addr::HeapCell(a1));
                             } else {
                                 self.fail = true;
-                            },                        
+                            },                   
                     (Addr::Con(Constant::EmptyList), Addr::Con(Constant::String(ref s)))
                   | (Addr::Con(Constant::String(ref s)), Addr::Con(Constant::EmptyList))
                         if self.flags.double_quotes.is_chars() => {
@@ -221,7 +214,7 @@ impl MachineState {
                         pdl.push(Addr::HeapCell(a1 + 1));
                         pdl.push(Addr::HeapCell(a2 + 1));
                     },
-                    (Addr::Con(c1), Addr::Con(c2)) =>
+                    (Addr::Con(ref c1), Addr::Con(ref c2)) => 
                         if c1 != c2 {
                             self.fail = true;
                         },