process float/1 and pi/0

This commit is contained in:
Mark Thom
2019-05-12 22:21:29 -04:00
parent f344150322
commit 59ab4cd67c
3 changed files with 10 additions and 1 deletions

View File

@@ -40,6 +40,10 @@ impl<'a> ArithInstructionIterator<'a> {
match ClauseType::from(name.clone(), terms.len(), fixity.clone()) {
ct @ ClauseType::Named(..) | ct @ ClauseType::Op(..) =>
Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms)),
ClauseType::Inlined(InlinedClauseType::IsFloat(_)) => {
let ct = ClauseType::Named(clause_name!("float"), 1, CodeIndex::default());
Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms))
},
_ => Err(ArithmeticError::NonEvaluableFunctor(Constant::Atom(name.clone(),
fixity.clone()),
terms.len()))
@@ -233,6 +237,8 @@ impl<'a> ArithmeticEvaluator<'a>
self.interm.push(ArithmeticTerm::Number(Number::Float(n.clone()))),
&Constant::Rational(ref n) =>
self.interm.push(ArithmeticTerm::Number(Number::Rational(n.clone()))),
&Constant::Atom(ref name, _) if name.as_str() == "pi" =>
self.interm.push(ArithmeticTerm::Number(Number::Float(OrderedFloat(f64::consts::PI)))),
_ =>
return Err(ArithmeticError::NonEvaluableFunctor(c.clone(), 0))
}

View File

@@ -930,6 +930,9 @@ impl MachineState {
interms.push(Number::Float(n)),
HeapCellValue::Addr(Addr::Con(Constant::Rational(n))) =>
interms.push(Number::Rational(n)),
HeapCellValue::Addr(Addr::Con(Constant::Atom(ref name, _)))
if name.as_str() == "pi" =>
interms.push(Number::Float(OrderedFloat(f64::consts::PI))),
_ =>
return Err(self.error_form(MachineError::instantiation_error(), caller))
}