]> Repositorios git - scryer-prolog.git/commitdiff
hacky workaround
authorMark Thom <[email protected]>
Tue, 29 May 2018 02:07:34 +0000 (20:07 -0600)
committerMark Thom <[email protected]>
Tue, 29 May 2018 02:07:34 +0000 (20:07 -0600)
src/prolog/ast.rs
src/prolog/heap_print.rs
src/prolog/io.rs
src/prolog/lib/builtins.pl
src/prolog/macros.rs
src/prolog/parser

index 30d5ac5402d1b9b3f5c0295aec0255565e86a3e5..1b85a388e38d6be3e63ce676723349464726ec67 100644 (file)
@@ -166,7 +166,8 @@ pub fn default_op_dir() -> OpDir {
 
     op_dir.insert((clause_name!(":-"), Fixity::In),  (XFX, 1200, module_name.clone()));
     op_dir.insert((clause_name!(":-"), Fixity::Pre), (FX, 1200, module_name.clone()));
-    op_dir.insert((clause_name!("?-"), Fixity::Pre), (FX, 1200, module_name.clone()));
+    op_dir.insert((clause_name!("?-"), Fixity::Pre), (FX, 1200, module_name.clone()));    
+    op_dir.insert((clause_name!(","),  Fixity::In), (XFY, 1000, module_name.clone()));
 
     op_dir
 }
@@ -548,29 +549,6 @@ impl Constant {
     }
 }
 
-impl fmt::Display for Constant {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self {
-            &Constant::Atom(ref atom) =>
-                if atom.as_str().chars().any(|c| ".$'\" ".contains(c)) {
-                    write!(f, "'{}'", atom.as_str())
-                } else {
-                    write!(f, "{}", atom.as_str())
-                },
-            &Constant::Char(c) =>
-                write!(f, "'{}'", c as u8),
-            &Constant::EmptyList =>
-                write!(f, "[]"),
-            &Constant::Number(ref n) =>
-                write!(f, "{}", n),
-            &Constant::String(ref s) =>
-                write!(f, "\"{}\"", s),
-            &Constant::Usize(integer) =>
-                write!(f, "u{}", integer)
-        }
-    }
-}
-
 #[derive(PartialEq, Eq, Clone)]
 pub enum Term {
     AnonVar,
index 2ee4bf0abcc9e41ced5b29153f49a45cdd6bfbfa..721a9cceb0800a458789fa9b739ee2c5924d752f 100644 (file)
@@ -229,6 +229,27 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
         })
     }
 
+    fn print_constant(&mut self, c: Constant) {
+        match c {
+            Constant::Char(c) if c == '\n' =>
+                self.outputter.append("'\\n'"),
+//            Constant::Char(c) if c == '\f' =>
+//                self.outputter.append("\\f"),
+            Constant::Char(c) if c == '\r' =>
+                self.outputter.append("'\\r'"),
+            Constant::Char(c) if c == '\t' =>
+                self.outputter.append("'\\t'"),
+//            Constant::Char(c) if c == '\b' =>
+//                self.outputter.append("\\b"),
+//            Constant::Char(c) if c == '\\a' =>
+//                self.outputter.append("\a"),
+//            Constant::Char(c) if c == '\\v' =>
+//                self.outputter.append("\\v"),
+            _ =>
+                self.outputter.append(format!("{}", c).as_str())
+        }
+    }
+    
     fn handle_heap_term(&mut self, iter: &mut HCPreOrderIterator)
     {
         let heap_val = match self.check_for_seen(iter) {
@@ -246,7 +267,7 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
                     self.outputter.append("[]");
                 },
             HeapCellValue::Addr(Addr::Con(c)) =>
-                self.outputter.append(format!("{}", c).as_str()),
+                self.print_constant(c),
             HeapCellValue::Addr(Addr::Lis(_)) => {
                 let cell = Rc::new(Cell::new(true));
 
index 70965751c8ead110f2e3ca7858dc9d2f9d98776d..5a55b0f1ddc2dba0641f3662c5a16514510f58b3 100644 (file)
@@ -18,6 +18,29 @@ impl fmt::Display for IndexPtr {
     }
 }
 
+impl fmt::Display for Constant {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self {
+            &Constant::Atom(ref atom) =>
+                if atom.as_str().chars().any(|c| ".$'\" ".contains(c)) {
+                    write!(f, "'{}'", atom.as_str())
+                } else {
+                    write!(f, "{}", atom.as_str())
+                },
+            &Constant::Char(c) =>
+                write!(f, "'{}'", c as u8),
+            &Constant::EmptyList =>
+                write!(f, "[]"),
+            &Constant::Number(ref n) =>
+                write!(f, "{}", n),
+            &Constant::String(ref s) =>
+                write!(f, "\"{}\"", s),
+            &Constant::Usize(integer) =>
+                write!(f, "u{}", integer)
+        }
+    }
+}
+
 impl fmt::Display for ClauseName {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "{}", self.as_str())
index a53664b7ce717dc4f8aff0d7c630a7de18050e23..58dccdd5620aaeb5fd102dfcb153fc7917631ed5 100644 (file)
@@ -7,6 +7,15 @@
        (\==)/2, (@=<)/2, (@>=)/2, (@<)/2, (@>)/2, (=@=)/2, (\=@=)/2,
        catch/3, throw/1, true/0, false/0]).
 
+','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
+
+','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
+','(!, !, B) :- '$set_cp'(B).
+','(!, G, B) :- '$set_cp'(B), G.
+','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
+','(G, !, B) :- !, G, '$set_cp'(B).
+','(G1, G2, _) :- G1, G2.
+
 % arithmetic operators.
 :- op(700, xfx, is).
 :- op(500, yfx, +).
@@ -63,15 +72,6 @@ false :- '$fail'.
 
 % control operators.
 
-','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
-
-','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
-','(!, !, B) :- '$set_cp'(B).
-','(!, G, B) :- '$set_cp'(B), G.
-','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
-','(G, !, B) :- !, G, '$set_cp'(B).
-','(G1, G2, _) :- G1, G2.
-
 ;(G1, G2) :- '$get_cp'(B), ;(G1, G2, B).
 
 ;(G1, G4, B) :- compound(G1), G1 = ->(G2, G3), (G2 -> G3 ; '$set_cp'(B), G4).
index ec289ecaf745df776f507220c0ebabcdf00dcafd..0da939d30e8504438633834f7371aad9fab8e4eb 100644 (file)
@@ -1,4 +1,7 @@
 macro_rules! clause_name {
+    ($name: expr, $tbl: expr) => (
+        ClauseName::User(TabledRc::new($name, $tbl.clone()))
+    ) ;
     ($name: expr) => (
         ClauseName::BuiltIn($name)
     )
index d52da58a5d5c3404305466a53c2682ef84274085..52034e3a66b694fd16b164c509c525aeaf28470a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit d52da58a5d5c3404305466a53c2682ef84274085
+Subproject commit 52034e3a66b694fd16b164c509c525aeaf28470a