]> Repositorios git - scryer-prolog.git/commitdiff
re: #73
authorMark Thom <[email protected]>
Sat, 30 Mar 2019 18:38:26 +0000 (12:38 -0600)
committerMark Thom <[email protected]>
Sat, 30 Mar 2019 18:38:26 +0000 (12:38 -0600)
Cargo.toml
src/prolog/heap_print.rs
src/prolog/machine/machine_state_impl.rs

index a5b3a0bf0e1d1882270974a37fa7bd4a2a356e34..32288857b7878cb0b36c104163050bf4e7f17eb8 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.24"
+version = "0.8.25"
 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.4"
+prolog_parser = "0.8.5"
 readline_rs_compat = { version = "0.1.7", optional = true }
 ref_thread_local = "0.0.0"
 
index dbef0a5311cb2aab1a653a02ec0c3e86cbb30b40..e283fe33379e08a6b492d30e613e613c3db7223c 100644 (file)
@@ -181,11 +181,7 @@ impl HCValueOutputter for PrinterOutputter {
 
 #[inline]
 fn is_numbered_var(ct: &ClauseType, arity: usize) -> bool {
-    arity == 1 && if let &ClauseType::Named(ref name, ..) = ct {
-        name.as_str() == "$VAR"
-    } else {
-        false
-    }
+    arity == 1 && ct.name().as_str() == "$VAR"
 }
 
 #[inline]
@@ -435,26 +431,40 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
         self.state_stack.push(TokenOrRedirect::LeftCurly);
     }
 
+    fn format_numbered_vars(&mut self, iter: &mut HCPreOrderIterator) -> bool
+    {
+        let addr = iter.stack().last().cloned().unwrap();
+
+        // 7.10.4
+        if let Some(var) = iter.machine_st().numbervar(&self.numbervars_offset, addr) {
+            iter.stack().pop();
+            self.state_stack.push(TokenOrRedirect::NumberedVar(var));
+            return true;
+        }
+
+        false
+    }
+    
     fn format_clause(&mut self, iter: &mut HCPreOrderIterator, arity: usize, ct: ClauseType)
     {
         if let Some(spec) = ct.spec() {
+            if self.numbervars && is_numbered_var(&ct, arity) {
+                if self.format_numbered_vars(iter) {
+                    return;
+                }
+            }
+            
             if !self.ignore_ops {
                 return self.enqueue_op(ct, spec);
             }
         } else if self.numbervars && is_numbered_var(&ct, arity) {
-            let addr = iter.stack().last().cloned().unwrap();
-
-            // 7.10.4
-            if let Some(var) = iter.machine_st().numbervar(&self.numbervars_offset, addr) {
-                iter.stack().pop();
-                self.state_stack.push(TokenOrRedirect::NumberedVar(var));
+            if self.format_numbered_vars(iter) {
                 return;
             }
         }
 
         match (ct.name().as_str(), arity) {
-            ("-", 1) => self.format_negated_operand(),
-            ("{}", 1) => self.format_curly_braces(),
+            ("{}", 1) if !self.ignore_ops => self.format_curly_braces(),
             _ =>  self.format_struct(arity, ct.name())
         };
     }
index 01803becbceb0ece43bcdb91026f3557b0c11ad1..828f7a7271539633d0425061fa3556100b138ef7 100644 (file)
@@ -1747,7 +1747,7 @@ impl MachineState {
                 (HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_))) =>
                     continue,
                 (HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::NamedStr(ar, n, _))
-                    | (HeapCellValue::NamedStr(ar, n, _), HeapCellValue::Addr(Addr::Lis(_))) =>
+              | (HeapCellValue::NamedStr(ar, n, _), HeapCellValue::Addr(Addr::Lis(_))) =>
                     if ar == 2 && n.as_str() == "." {
                         continue;
                     } else if ar < 2 {
@@ -1932,12 +1932,12 @@ impl MachineState {
                     match name {
                         Addr::Con(_) if arity == 0 =>
                             self.unify(a1, name),
-                        Addr::Con(Constant::Atom(name, _)) => {
+                        Addr::Con(Constant::Atom(name, spec)) => {
                             let f_a = if name.as_str() == "." && arity == 2 {
                                 Addr::Lis(self.heap.h)
                             } else {
                                 let h = self.heap.h;
-                                self.heap.push(HeapCellValue::NamedStr(arity as usize, name, None));
+                                self.heap.push(HeapCellValue::NamedStr(arity as usize, name, spec));
                                 Addr::Str(h)
                             };