]> Repositorios git - scryer-prolog.git/commitdiff
fix term_variables, add (^)/2 as an actual evaluable functor
authorMark Thom <[email protected]>
Mon, 1 Apr 2019 15:04:50 +0000 (09:04 -0600)
committerMark Thom <[email protected]>
Mon, 1 Apr 2019 15:04:50 +0000 (09:04 -0600)
src/prolog/arithmetic.rs
src/prolog/instructions.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/system_calls.rs
src/prolog/write.rs

index 8cb0a8e1d639b49d92b53f79224e03813978b951..d5e5246c7e697000a0e1f4bc0e5490c055bc90c2 100644 (file)
@@ -131,7 +131,8 @@ impl<'a> ArithmeticEvaluator<'a>
             "div"  => Ok(ArithmeticInstruction::FIDiv(a1, a2, t)),
             "rdiv" => Ok(ArithmeticInstruction::RDiv(a1, a2, t)),
             "*"    => Ok(ArithmeticInstruction::Mul(a1, a2, t)),
-            "**"    => Ok(ArithmeticInstruction::Pow(a1, a2, t)),
+            "**"   => Ok(ArithmeticInstruction::Pow(a1, a2, t)),
+            "^"    => Ok(ArithmeticInstruction::IntPow(a1, a2, t)),
             ">>"   => Ok(ArithmeticInstruction::Shr(a1, a2, t)),
             "<<"   => Ok(ArithmeticInstruction::Shl(a1, a2, t)),
             "/\\"  => Ok(ArithmeticInstruction::And(a1, a2, t)),
index 1d5c42af9a5b3cd3dbbaaa79c83de9f6629b599b..826cf93bc9b6f2a82020f363e8d18283624df1b0 100644 (file)
@@ -59,6 +59,7 @@ pub enum ArithmeticInstruction {
     Sub(ArithmeticTerm, ArithmeticTerm, usize),
     Mul(ArithmeticTerm, ArithmeticTerm, usize),
     Pow(ArithmeticTerm, ArithmeticTerm, usize),
+    IntPow(ArithmeticTerm, ArithmeticTerm, usize),
     IDiv(ArithmeticTerm, ArithmeticTerm, usize),
     Max(ArithmeticTerm, ArithmeticTerm, usize),
     FIDiv(ArithmeticTerm, ArithmeticTerm, usize),
index 69e12db607346064c261aea12b4c3c71bdc02f3c..8aac7e2ba4c7dcb571f67fde7018989775517725 100644 (file)
@@ -714,6 +714,7 @@ impl MachineState {
                         "*" => interms.push(a1 * a2),
                         "/" => interms.push(self.div(a1, a2)?),
                         "**" => interms.push(self.pow(a1, a2)?),
+                        "^"  => interms.push(self.pow(a1, a2)?),
                         "max"  => interms.push(self.max(a1, a2)?),
                         "rdiv" => {
                             let r1 = self.get_rational(&ArithmeticTerm::Number(a1), &caller)?;
@@ -1009,13 +1010,20 @@ impl MachineState {
                 self.interms[t - 1] = try_or_fail!(self, self.max(n1, n2));
                 self.p += 1;
             },
-            &ArithmeticInstruction::Pow(ref a1, ref a2, t) => {
+            &ArithmeticInstruction::IntPow(ref a1, ref a2, t) => {
                 let n1 = try_or_fail!(self, self.get_number(a1));
                 let n2 = try_or_fail!(self, self.get_number(a2));
 
                 self.interms[t - 1] = try_or_fail!(self, self.pow(n1, n2));
                 self.p += 1;
             },
+            &ArithmeticInstruction::Pow(ref a1, ref a2, t) => {
+                let n1 = try_or_fail!(self, self.get_number(a1));
+                let n2 = try_or_fail!(self, self.get_number(a2));
+
+                self.interms[t - 1] = try_or_fail!(self, self.pow(n1, n2));
+                self.p += 1;
+            },            
             &ArithmeticInstruction::RDiv(ref a1, ref a2, t) => {
                 let stub = MachineError::functor_stub(clause_name!("(rdiv)"), 2);
 
index 2f2955047a2db9c241cd7cf27899265aff4ba423..7821de660416155683c2c5382a423b08db7436e9 100644 (file)
@@ -3,7 +3,6 @@ use prolog_parser::parser::{get_desc, get_clause_spec};
 use prolog_parser::tabled_rc::*;
 
 use prolog::clause_types::*;
-use prolog::heap_iter::*;
 use prolog::heap_print::*;
 use prolog::machine::copier::*;
 use prolog::machine::machine_errors::*;
@@ -1112,7 +1111,7 @@ impl MachineState {
                 let mut vars = Vec::new();
 
                 {
-                    let iter = HCPreOrderIterator::new(self, a1);
+                    let iter = self.acyclic_pre_order_iter(a1);
 
                     for item in iter {
                         match item {
index 51e658270618751391587971774adfce59533f81..f413e1e31895ffd53dc8ebc8486ca5d328df67c4 100644 (file)
@@ -298,7 +298,9 @@ impl fmt::Display for ArithmeticInstruction {
             &ArithmeticInstruction::Mul(ref a1, ref a2, ref t) =>
                 write!(f, "mul {}, {}, @{}", a1, a2, t),
             &ArithmeticInstruction::Pow(ref a1, ref a2, ref t) =>
-                write!(f, "pow {}, {}, @{}", a1, a2, t),
+                write!(f, "** {}, {}, @{}", a1, a2, t),
+            &ArithmeticInstruction::IntPow(ref a1, ref a2, ref t) =>
+                write!(f, "^ {}, {}, @{}", a1, a2, t),            
             &ArithmeticInstruction::Div(ref a1, ref a2, ref t) =>
                 write!(f, "div {}, {}, @{}", a1, a2, t),
             &ArithmeticInstruction::IDiv(ref a1, ref a2, ref t) =>