correct delayed evaluation for negation, rational decls
@@ -262,15 +262,7 @@ fn write_constant_to_var(&mut self, addr: Addr, c: Constant) {
fn get_number(&self, at: &ArithmeticTerm) -> Result<Number, Vec<HeapCellValue>> {
match at {
- &ArithmeticTerm::Reg(r) => {
- let addr = self[r].clone();
- let item = self.store(self.deref(addr));
-
- match item {
- Addr::Con(Constant::Number(n)) => Ok(n),
- _ => Err(functor!("instantiation_error", 1, [heap_atom!("(is)/2")]))
- }
- },
+ &ArithmeticTerm::Reg(r) => self.arith_eval_by_metacall(r),
&ArithmeticTerm::Interm(i) => Ok(self.interms[i-1].clone()),
&ArithmeticTerm::Number(ref n) => Ok(n.clone()),
}
@@ -325,12 +317,12 @@ pub(super) fn arith_eval_by_metacall(&self, r: RegType) -> Result<Number, Vec<He
"+" => interms.push(a1 + a2),
"-" => interms.push(a1 - a2),
"*" => interms.push(a1 * a2),
- "rdiv" =>
- match NumberPair::from(a1, a2) {
- NumberPair::Rational(r1, r2) =>
- interms.push(Number::Rational(self.rdiv(r1, r2)?)),
- _ =>
- return Err(instantiation_err)
+ "rdiv" => {
+ let r1 = self.get_rational(&ArithmeticTerm::Number(a1))?;
+ let r2 = self.get_rational(&ArithmeticTerm::Number(a2))?;
+
+ let result = Number::Rational(self.rdiv(r1, r2)?);
+ interms.push(result)
},
"//" => interms.push(Number::Integer(self.idiv(a1, a2)?)),
"div" => interms.push(Number::Integer(self.fidiv(a1, a2)?)),
