fix term_variables, add (^)/2 as an actual evaluable functor

This commit is contained in:
Mark Thom
2019-04-01 09:04:50 -06:00
parent 2240418a25
commit e3e0473b69
5 changed files with 16 additions and 5 deletions

View 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)),

View 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),

View 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);

View 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 {

View 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) =>