From: Mark Thom Date: Sat, 5 Oct 2019 02:03:03 +0000 (-0600) Subject: fixes for issues #185 and #181 X-Git-Tag: v0.8.110~16 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=3fa168d35b8aa22da5e23c8faf34729c5b557535;p=scryer-prolog.git fixes for issues #185 and #181 --- diff --git a/Cargo.toml b/Cargo.toml index 4ae1b846..840f8b00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ lazy_static = "1.4.0" libc = "0.2.62" nix = "0.15.0" ordered-float = "0.5.0" -prolog_parser = "0.8.31" +prolog_parser = "0.8.32" ref_thread_local = "0.0.0" rug = "1.4.0" rustyline = "5.0.3" diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index aec99d5a..06898907 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -542,10 +542,10 @@ impl ClauseType { match self { &ClauseType::Op(_, ref spec, _) => Some(spec.clone()), &ClauseType::Inlined(InlinedClauseType::CompareNumber(..)) - | &ClauseType::BuiltIn(BuiltInClauseType::Is(..)) - | &ClauseType::BuiltIn(BuiltInClauseType::CompareTerm(_)) - | &ClauseType::BuiltIn(BuiltInClauseType::NotEq) - | &ClauseType::BuiltIn(BuiltInClauseType::Eq) => Some(SharedOpDesc::new(700, XFX)), + | &ClauseType::BuiltIn(BuiltInClauseType::Is(..)) + | &ClauseType::BuiltIn(BuiltInClauseType::CompareTerm(_)) + | &ClauseType::BuiltIn(BuiltInClauseType::NotEq) + | &ClauseType::BuiltIn(BuiltInClauseType::Eq) => Some(SharedOpDesc::new(700, XFX)), _ => None, } } diff --git a/src/prolog/forms.rs b/src/prolog/forms.rs index 38904435..aa5eb148 100644 --- a/src/prolog/forms.rs +++ b/src/prolog/forms.rs @@ -280,6 +280,15 @@ pub fn fetch_op_spec( spec: Option, op_dir: &OpDir, ) -> Option { + if let Some(ref op_desc) = &spec { + if op_desc.arity() != arity { + /* it's possible to extend operator functors with + * additional terms. When that happens, + * void the op_spec by returning None. */ + return None; + } + } + spec.or_else(|| match arity { 2 => op_dir .get(&(name, Fixity::In)) diff --git a/src/prolog/heap_print.rs b/src/prolog/heap_print.rs index 083d10ff..4609693b 100644 --- a/src/prolog/heap_print.rs +++ b/src/prolog/heap_print.rs @@ -922,7 +922,9 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { match heap_val { HeapCellValue::NamedStr(arity, name, spec) => { - if let Some(spec) = fetch_op_spec(name.clone(), arity, spec.clone(), self.op_dir) { + let spec = fetch_op_spec(name.clone(), arity, spec.clone(), self.op_dir); + + if let Some(spec) = spec { self.handle_op_as_struct( name, arity, diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index ba4f1b1b..713a8a01 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -1114,7 +1114,7 @@ impl MachineState { } fn pow(&self, n1: Number, n2: Number, culprit: &'static str) -> Result { - if n2.is_negative() { + if n2.is_negative() && n1.is_zero() { let stub = MachineError::functor_stub(clause_name!(culprit), 2); return Err(self.error_form(MachineError::evaluation_error(EvalError::Undefined), stub)); } @@ -1882,7 +1882,7 @@ impl MachineState { &IndexingInstruction::SwitchOnConstant(_, ref hm) => { let a1 = self.registers[1].clone(); let addr = self.store(self.deref(a1)); - + let offset = match addr { Addr::Con(constant) => match hm.get(&constant) { Some(offset) => *offset, diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 443ebda7..d30ba8fe 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -31,13 +31,9 @@ !. '$print_exception'(E) :- - ( E = error(_, _:_) -> true % if the error source contains a line - % number, a GNU-style error message - % is expected to be printed instead. - ; write_term('caught: ', [quoted(false)]), - writeq(E), - nl - ). + write_term('caught: ', [quoted(false)]), + writeq(E), + nl. '$predicate_indicator'(Source, PI) :- ( nonvar(PI) ->