]> Repositorios git - scryer-prolog.git/commitdiff
fixes for issues #185 and #181
authorMark Thom <[email protected]>
Sat, 5 Oct 2019 02:03:03 +0000 (20:03 -0600)
committerMark Thom <[email protected]>
Sat, 5 Oct 2019 02:03:03 +0000 (20:03 -0600)
Cargo.toml
src/prolog/clause_types.rs
src/prolog/forms.rs
src/prolog/heap_print.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/toplevel.pl

index 4ae1b84603cd9382d6c09f0142e7d99d593ca7d0..840f8b00056ecb724f2ad0655b898cef5fa6b8a9 100644 (file)
@@ -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"
index aec99d5a9fabfa552898dee04c60d71db225a973..06898907ca7fe64b9c7ea3e77f04ce8df72b9545 100644 (file)
@@ -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,
         }
     }
index 38904435f017cb6865699d3d07db0d681855209c..aa5eb148d42bd05e2641b78fa01c9effb37fbe4e 100644 (file)
@@ -280,6 +280,15 @@ pub fn fetch_op_spec(
     spec: Option<SharedOpDesc>,
     op_dir: &OpDir,
 ) -> Option<SharedOpDesc> {
+    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))
index 083d10ff9b2b8f6482e678467129060d7517b5a3..4609693b0a00fd8579399b205be7def9a9238bf7 100644 (file)
@@ -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,
index ba4f1b1b9f999b1f48ebbcd82ed43780d58d1062..713a8a01ffb9b8eb3b27514b01783d9b8f90026d 100644 (file)
@@ -1114,7 +1114,7 @@ impl MachineState {
     }
 
     fn pow(&self, n1: Number, n2: Number, culprit: &'static str) -> Result<Number, MachineStub> {
-        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,
index 443ebda75dca81c40ba59826bebf810306c1aa3a..d30ba8fed18730e1a3eaa91a320a848d53722637 100644 (file)
     !.
 
 '$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) ->