From e3e0473b6933cd3bb98d939bef61242501c6a497 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 1 Apr 2019 09:04:50 -0600 Subject: [PATCH] fix term_variables, add (^)/2 as an actual evaluable functor --- src/prolog/arithmetic.rs | 3 ++- src/prolog/instructions.rs | 1 + src/prolog/machine/machine_state_impl.rs | 10 +++++++++- src/prolog/machine/system_calls.rs | 3 +-- src/prolog/write.rs | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/prolog/arithmetic.rs b/src/prolog/arithmetic.rs index 8cb0a8e1..d5e5246c 100644 --- a/src/prolog/arithmetic.rs +++ b/src/prolog/arithmetic.rs @@ -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)), diff --git a/src/prolog/instructions.rs b/src/prolog/instructions.rs index 1d5c42af..826cf93b 100644 --- a/src/prolog/instructions.rs +++ b/src/prolog/instructions.rs @@ -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), diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index 69e12db6..8aac7e2b 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -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); diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 2f295504..7821de66 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -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 { diff --git a/src/prolog/write.rs b/src/prolog/write.rs index 51e65827..f413e1e3 100644 --- a/src/prolog/write.rs +++ b/src/prolog/write.rs @@ -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) => -- 2.54.0