]> Repositorios git - scryer-prolog.git/commitdiff
correct comma printing
authorMark Thom <[email protected]>
Sun, 31 Mar 2019 08:13:58 +0000 (02:13 -0600)
committerMark Thom <[email protected]>
Sun, 31 Mar 2019 08:13:58 +0000 (02:13 -0600)
Cargo.toml
src/prolog/heap_print.rs
src/prolog/machine/compile.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/mod.rs

index 81bb8127dc7c1a4bc1a225a65500ee60e827338a..2868ac9e1e278743eb6e91dd8a0e82d348bb1e95 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.29"
+version = "0.8.30"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
@@ -14,7 +14,7 @@ cfg-if = "0.1.7"
 downcast = "0.10.0"
 num = "0.2"
 ordered-float = "0.5.0"
-prolog_parser = "0.8.7"
+prolog_parser = "0.8.8"
 readline_rs_compat = { version = "0.1.7", optional = true }
 ref_thread_local = "0.0.0"
 
index a02a9d8edd9a20923bbfddb627c3ce790291cf1d..1b774d19c2a4354a67b27093f6c5514134ae1efd 100644 (file)
@@ -537,29 +537,40 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
         })
     }
 
-    fn print_atom(&mut self, atom: &ClauseName, spec: Option<(usize, Specifier)>) {
+    fn print_atom(&mut self, atom: &ClauseName) {
         push_space_if_amb!(self, atom.as_str(), {
             match atom.as_str() {
                 "" => self.append_str("''"),
-                "," if spec.is_some() => self.append_str(atom.as_str()),
-                ";" | "!" => self.append_str(atom.as_str()),
-                s => if !self.quoted || non_quoted_token(s.chars()) {
-                    self.append_str(atom.as_str());
-                } else {
-                    if self.quoted {
-                        self.push_char('\'');
-                    }
+                //"," => self.append_str("(,)"),                
+                s => self.print_op_addendum(s)
+            }
+        });
+    }
 
-                    for c in atom.as_str().chars() {
-                        self.print_char(c);
-                    }
+    fn print_op_addendum(&mut self, atom: &str) {
+        if !self.quoted || non_quoted_token(atom.chars()) {
+            self.append_str(atom);
+        } else {
+            if self.quoted {
+                self.push_char('\'');
+            }
 
-                    if self.quoted {
-                        self.push_char('\'');
-                    }
-                }
+            for c in atom.chars() {
+                self.print_char(c);
             }
-        });
+
+            if self.quoted {
+                self.push_char('\'');
+            }
+        }            
+    }
+    
+    fn print_op(&mut self, atom: &str) {
+        if atom == "," {
+            self.push_char(',');
+        } else {
+            self.print_op_addendum(atom);
+        }
     }
 
     fn print_char(&mut self, c: char) {
@@ -617,7 +628,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
 
     fn print_constant(&mut self, c: Constant, op: &Option<DirectedOp>) {
         match c {
-            Constant::Atom(ref atom, Some(spec)) => {
+            Constant::Atom(ref atom, Some(_)) => {
                 if let Some(ref op) = op {
                     if self.outputter.ends_with(&format!(" {}", op.as_str())) {
                         self.push_char(' ');
@@ -626,7 +637,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
                     self.push_char('(');
                 }
 
-                self.print_atom(atom, Some(spec));
+                self.print_atom(atom);
 
                 if op.is_some() {
                     self.push_char(')');
@@ -634,7 +645,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
             },
             Constant::Atom(ref atom, None) =>
                 push_space_if_amb!(self, atom.as_str(), {
-                    self.print_atom(atom, None);
+                    self.print_atom(atom);
                 }),
             Constant::Char(c) if non_quoted_token(once(c)) =>
                 self.print_char(c),
@@ -772,9 +783,9 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
             if let Some(loc_data) = self.state_stack.pop() {
                 match loc_data {
                     TokenOrRedirect::Atom(atom) =>
-                        self.print_atom(&atom, None),
-                    TokenOrRedirect::Op(atom, spec) =>
-                        self.print_atom(&atom, Some(spec)),
+                        self.print_atom(&atom),
+                    TokenOrRedirect::Op(atom, _) =>
+                        self.print_op(atom.as_str()),
                     TokenOrRedirect::NumberedVar(num_var) =>
                         self.append_str(num_var.as_str()),
                     TokenOrRedirect::CompositeRedirect(op) =>
index 8e49fa5b35c655b5af10ac954932e6050df86322..8b7c6d763c31f1a7f2e369820cb87b688cf82f79 100644 (file)
@@ -559,17 +559,8 @@ impl ListingCompiler {
                 
                     get_desc(op_decl.name(), comp_ops)
                 };
-
-                if op_decl.0 == 0 {
-                    // remove all instances of the operator.
-                    if self.module.is_none() {
-                        op_decl.remove(&mut wam_indices.op_dir);                        
-                    }
-
-                    Ok(())
-                } else {
-                    op_decl.submit(self.get_module_name(), existing_desc, &mut indices.op_dir)
-                }
+                
+                op_decl.submit(self.get_module_name(), existing_desc, &mut indices.op_dir)
             },
             Declaration::UseModule(name) =>
                 self.use_module(name, code_repo, flags, wam_indices, indices),
index 828f7a7271539633d0425061fa3556100b138ef7..481482cca76d7e8d71c2ce570f34aa3b8d5241a6 100644 (file)
@@ -188,7 +188,10 @@ impl MachineState {
       where Outputter: HCValueOutputter
     {
         let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict);
+        
         printer.see_all_locs();
+        printer.quoted = true;
+        
         printer.print(addr)
     }
 
index 4b5c42bf0ed0574d991568dc62abc912a1910b55..5b7dc287b32be48f2e52a4c3957a8edefea2fb8e 100644 (file)
@@ -272,7 +272,13 @@ impl Machine {
 
     #[inline]
     pub fn add_batched_ops(&mut self, op_dir: OpDir) {
-        self.indices.op_dir.extend(op_dir.into_iter());
+        for ((name, fixity), info) in op_dir {
+            if info.1 == 0 {
+                self.indices.op_dir.remove(&(name, fixity));
+            } else {
+                self.indices.op_dir.insert((name, fixity), info);
+            }
+        }
     }
 
     #[inline]