correct delayed evaluation for negation, rational decls
This commit is contained in:
@@ -262,15 +262,7 @@ impl MachineState {
|
|||||||
|
|
||||||
fn get_number(&self, at: &ArithmeticTerm) -> Result<Number, Vec<HeapCellValue>> {
|
fn get_number(&self, at: &ArithmeticTerm) -> Result<Number, Vec<HeapCellValue>> {
|
||||||
match at {
|
match at {
|
||||||
&ArithmeticTerm::Reg(r) => {
|
&ArithmeticTerm::Reg(r) => self.arith_eval_by_metacall(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::Interm(i) => Ok(self.interms[i-1].clone()),
|
&ArithmeticTerm::Interm(i) => Ok(self.interms[i-1].clone()),
|
||||||
&ArithmeticTerm::Number(ref n) => Ok(n.clone()),
|
&ArithmeticTerm::Number(ref n) => Ok(n.clone()),
|
||||||
}
|
}
|
||||||
@@ -325,13 +317,13 @@ impl MachineState {
|
|||||||
"+" => interms.push(a1 + a2),
|
"+" => interms.push(a1 + a2),
|
||||||
"-" => interms.push(a1 - a2),
|
"-" => interms.push(a1 - a2),
|
||||||
"*" => interms.push(a1 * a2),
|
"*" => interms.push(a1 * a2),
|
||||||
"rdiv" =>
|
"rdiv" => {
|
||||||
match NumberPair::from(a1, a2) {
|
let r1 = self.get_rational(&ArithmeticTerm::Number(a1))?;
|
||||||
NumberPair::Rational(r1, r2) =>
|
let r2 = self.get_rational(&ArithmeticTerm::Number(a2))?;
|
||||||
interms.push(Number::Rational(self.rdiv(r1, r2)?)),
|
|
||||||
_ =>
|
let result = Number::Rational(self.rdiv(r1, r2)?);
|
||||||
return Err(instantiation_err)
|
interms.push(result)
|
||||||
},
|
},
|
||||||
"//" => interms.push(Number::Integer(self.idiv(a1, a2)?)),
|
"//" => interms.push(Number::Integer(self.idiv(a1, a2)?)),
|
||||||
"div" => interms.push(Number::Integer(self.fidiv(a1, a2)?)),
|
"div" => interms.push(Number::Integer(self.fidiv(a1, a2)?)),
|
||||||
">>" => interms.push(Number::Integer(self.shr(a1, a2)?)),
|
">>" => interms.push(Number::Integer(self.shr(a1, a2)?)),
|
||||||
|
|||||||
Reference in New Issue
Block a user