]> Repositorios git - scryer-prolog.git/commitdiff
process float/1 and pi/0
authorMark Thom <[email protected]>
Mon, 13 May 2019 02:21:29 +0000 (22:21 -0400)
committerMark Thom <[email protected]>
Mon, 13 May 2019 02:21:29 +0000 (22:21 -0400)
README.md
src/prolog/arithmetic.rs
src/prolog/machine/machine_state_impl.rs

index e0a009eea64aaf5acd4cfe8dc43dceb0c712d863..721d2f345528d5460892dcb498f4464921bb34f1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -138,7 +138,7 @@ The following predicates are built-in to Scryer.
       `(rem)/2`, `(mod)/2`, `(/\)/2`, `(\/)/2`, `(>>)/2`,`(<<)/2`,
       `(\)/1`, `abs/1`, `sin/1`, `cos/1`, `tan/1`, `asin/1`, `acos/1`,
       `atan/1`, `atan2/2`, `log/1`, `exp/1`, `sqrt/1`, `float/1`,
-      `truncate/1`, `round/1`, `floor/1`, `ceiling/1`
+      `truncate/1`, `round/1`, `floor/1`, `ceiling/1`, `pi/0`
     * Comparison operators: `>`, `<`, `=<`, `>=`, `=:=`, `=\=`.
 * `(:)/2`
 * `(@>)/2`
index f3b677785e0f00e886b4cf795d90cb10466a80f7..cad6f04cd67c5a4b7ccfccb7b746a6da81eff6a0 100644 (file)
@@ -40,6 +40,10 @@ impl<'a> ArithInstructionIterator<'a> {
                 match ClauseType::from(name.clone(), terms.len(), fixity.clone()) {
                     ct @ ClauseType::Named(..) | ct @ ClauseType::Op(..) =>
                         Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms)),
+                    ClauseType::Inlined(InlinedClauseType::IsFloat(_)) => {
+                        let ct = ClauseType::Named(clause_name!("float"), 1, CodeIndex::default());
+                        Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms))
+                    },
                     _ => Err(ArithmeticError::NonEvaluableFunctor(Constant::Atom(name.clone(),
                                                                                  fixity.clone()),
                                                                   terms.len()))
@@ -233,6 +237,8 @@ impl<'a> ArithmeticEvaluator<'a>
                 self.interm.push(ArithmeticTerm::Number(Number::Float(n.clone()))),
             &Constant::Rational(ref n) =>
                 self.interm.push(ArithmeticTerm::Number(Number::Rational(n.clone()))),
+            &Constant::Atom(ref name, _) if name.as_str() == "pi" =>
+                self.interm.push(ArithmeticTerm::Number(Number::Float(OrderedFloat(f64::consts::PI)))),
             _ =>
                 return Err(ArithmeticError::NonEvaluableFunctor(c.clone(), 0))
         }
index cd2c9214ec3fcbe7c99fc3e75691be10175cc823..c378a54f5bf7544d624571d1d1a897b01a033ebd 100644 (file)
@@ -930,6 +930,9 @@ impl MachineState {
                     interms.push(Number::Float(n)),
                 HeapCellValue::Addr(Addr::Con(Constant::Rational(n))) =>
                     interms.push(Number::Rational(n)),
+                HeapCellValue::Addr(Addr::Con(Constant::Atom(ref name, _)))
+                    if name.as_str() == "pi" =>
+                      interms.push(Number::Float(OrderedFloat(f64::consts::PI))),
                 _ =>
                     return Err(self.error_form(MachineError::instantiation_error(), caller))
             }