]> Repositorios git - scryer-prolog.git/commitdiff
fix syntax regressions (#1198, #1164)
authorMark Thom <[email protected]>
Thu, 13 Jan 2022 06:55:40 +0000 (23:55 -0700)
committerMark Thom <[email protected]>
Fri, 14 Jan 2022 06:54:55 +0000 (23:54 -0700)
src/forms.rs
src/heap_print.rs

index 167b937ed1f4ba1ee3563695db8ceb507e873061..372613b819769c35668bb776e94013909b32774d 100644 (file)
@@ -384,8 +384,8 @@ pub(crate) fn fetch_atom_op_spec(
     spec: Option<OpDesc>,
     op_dir: &OpDir,
 ) -> Option<OpDesc> {
-    fetch_op_spec_from_existing(name, 1, spec, op_dir)
-        .or_else(|| fetch_op_spec_from_existing(name, 2, spec, op_dir))
+    fetch_op_spec_from_existing(name, 2, spec, op_dir)
+        .or_else(|| fetch_op_spec_from_existing(name, 1, spec, op_dir))
 }
 
 pub(crate) fn fetch_op_spec_from_existing(
@@ -430,6 +430,9 @@ pub(crate) fn fetch_op_spec(name: Atom, arity: usize, op_dir: &OpDir) -> Option<
                 }
             })
         }
+        0 => {
+            fetch_atom_op_spec(name, None, op_dir)
+        }
         _ => None,
     }
 }
index f7ba606ca8d7be9fffcbfc880ba20f1f88a8a84d..cb8e34e5cd085df5342f84fb55665c7322a78b55 100644 (file)
@@ -88,7 +88,7 @@ fn needs_bracketing(child_desc: OpDesc, op: &DirectedOp) -> bool {
                 true
             } else if (is_postfix!(spec) || is_infix!(spec)) && !is_postfix!(child_desc.get_spec())
             {
-                *cell == child_desc && child_desc.get_prec() == priority
+                *cell != child_desc && child_desc.get_prec() == priority
             } else {
                 false
             }
@@ -191,10 +191,10 @@ enum NumberFocus {
 }
 
 impl NumberFocus {
-    fn is_positive(&self) -> bool {
+    fn is_negative(&self) -> bool {
         match self {
-            NumberFocus::Unfocused(n) => n.is_positive(),
-            NumberFocus::Denominator(r) | NumberFocus::Numerator(r) => **r > 0,
+            NumberFocus::Unfocused(n) => n.is_negative(),
+            NumberFocus::Denominator(r) | NumberFocus::Numerator(r) => **r < 0,
         }
     }
 }
@@ -922,7 +922,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
 
     fn print_number(&mut self, n: NumberFocus, op: &Option<DirectedOp>) {
         let add_brackets = if let Some(op) = op {
-            op.is_negative_sign() && n.is_positive()
+            op.is_negative_sign() && !n.is_negative()
         } else {
             false
         };
@@ -934,23 +934,20 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
         match n {
             NumberFocus::Unfocused(n) => match n {
                 Number::Float(fl) => {
-                    if &fl == &OrderedFloat(0f64) {
-                        push_space_if_amb!(self, "0.0", {
-                            append_str!(self, "0.0");
-                        });
-                    } else {
-                        let OrderedFloat(fl) = fl;
-                        let output_str = format!("{0:<20?}", fl);
+                    let OrderedFloat(fl) = fl;
+                    let output_str = format!("{0:<20?}", fl);
 
-                        push_space_if_amb!(self, &output_str, {
-                            append_str!(self, &output_str.trim());
-                        });
-                    }
+                    push_space_if_amb!(self, &output_str, {
+                        append_str!(self, &output_str.trim());
+                    });
                 }
                 Number::Rational(r) => {
                     self.print_rational(r, add_brackets);
                     return;
                 }
+                Number::Fixnum(n) => {
+                    append_str!(self, &format!("{}", n.get_num()));
+                }
                 n => {
                     let output_str = format!("{}", n);
 
@@ -1427,7 +1424,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
                 }
             }
             (HeapCellValueTag::Fixnum, n) => {
-                append_str!(self, &format!("{}", n.get_num()));
+                self.print_number(NumberFocus::Unfocused(Number::Fixnum(n)), &op);
             }
             (HeapCellValueTag::F64, f) => {
                 self.print_number(NumberFocus::Unfocused(Number::Float(**f)), &op);