throw type_error(number, E) in arith_eval_by_metacall (#392)
This commit is contained in:
@@ -143,12 +143,10 @@ impl MachineState {
|
||||
|
||||
pub(crate)
|
||||
fn arith_eval_by_metacall(&self, r: RegType) -> Result<Number, MachineStub> {
|
||||
let a = self[r].clone();
|
||||
|
||||
let caller = MachineError::functor_stub(clause_name!("(is)"), 2);
|
||||
let mut interms: Vec<Number> = Vec::with_capacity(64);
|
||||
|
||||
for addr in self.post_order_iter(a) {
|
||||
for addr in self.post_order_iter(self[r]) {
|
||||
match self.heap.index_addr(&addr).as_ref() {
|
||||
&HeapCellValue::NamedStr(2, ref name, _) => {
|
||||
let a2 = interms.pop().unwrap();
|
||||
@@ -241,10 +239,12 @@ impl MachineState {
|
||||
&HeapCellValue::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,
|
||||
val => {
|
||||
return Err(self.type_error(
|
||||
ValidType::Number,
|
||||
val.context_free_clone(),
|
||||
clause_name!("(is)"),
|
||||
2,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,21 @@ impl TypeError for Addr {
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeError for HeapCellValue {
|
||||
fn type_error(self, _: usize, valid_type: ValidType) -> MachineError {
|
||||
let stub = functor!(
|
||||
"type_error",
|
||||
[atom(valid_type.as_str()), value(self)]
|
||||
);
|
||||
|
||||
MachineError {
|
||||
stub,
|
||||
location: None,
|
||||
from: ErrorProvenance::Received
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeError for MachineStub {
|
||||
fn type_error(self, h: usize, valid_type: ValidType) -> MachineError {
|
||||
let stub = functor!(
|
||||
@@ -502,7 +517,7 @@ pub enum ValidType {
|
||||
InCharacter,
|
||||
Integer,
|
||||
List,
|
||||
// Number,
|
||||
Number,
|
||||
Pair,
|
||||
// PredicateIndicator,
|
||||
// Variable
|
||||
@@ -525,7 +540,7 @@ impl ValidType {
|
||||
ValidType::InCharacter => "in_character",
|
||||
ValidType::Integer => "integer",
|
||||
ValidType::List => "list",
|
||||
// ValidType::Number => "number",
|
||||
ValidType::Number => "number",
|
||||
ValidType::Pair => "pair",
|
||||
// ValidType::PredicateIndicator => "predicate_indicator",
|
||||
// ValidType::Variable => "variable"
|
||||
|
||||
@@ -121,6 +121,9 @@ macro_rules! functor_term {
|
||||
(atom($e:expr), $arity:expr, $aux_lens:expr, $addendum: ident) => (
|
||||
HeapCellValue::Atom(clause_name!($e), None)
|
||||
);
|
||||
(value($e:expr), $arity:expr, $aux_lens:expr, $addendum: ident) => (
|
||||
$e
|
||||
);
|
||||
(string($h:expr, $e:expr), $arity:expr, $aux_lens:expr, $addendum: ident) => ({
|
||||
let len: usize = $aux_lens.iter().sum();
|
||||
let h = len + $arity + 1 + $addendum.h() + $h;
|
||||
|
||||
Reference in New Issue
Block a user