]> Repositorios git - scryer-prolog.git/commitdiff
correct keysort type error (re: #34)
authorMark Thom <[email protected]>
Thu, 3 May 2018 17:52:33 +0000 (11:52 -0600)
committerMark Thom <[email protected]>
Thu, 3 May 2018 17:52:33 +0000 (11:52 -0600)
src/prolog/machine/machine_errors.rs
src/prolog/machine/machine_state_impl.rs

index 01a699fdd00b41e3cdf638fd93739a702a85d4ec..1cf34a04c924ef3bf80a8c749ac521aa25e96f54 100644 (file)
@@ -37,28 +37,16 @@ impl MachineState {
         }
     }
 
-    // see 8.4.4 of Draft Technical Corrigendum 2.
-    pub(super) fn check_keysort_errors(&self) -> Result<(), MachineError> {
-        let pairs  = self.store(self.deref(self[temp_v!(1)].clone()));
-        let sorted = self.store(self.deref(self[temp_v!(2)].clone()));
-
-        match self.detect_cycles(usize::max_value(), pairs.clone()) {
-            CycleSearchResult::PartialList(..) =>
-                Err(self.error_form(self.instantiation_error())),
-            CycleSearchResult::NotList =>
-                Err(self.error_form(self.type_error(ValidType::List, pairs))),
-            _ => Ok(())
-        }?;
-
-        match self.detect_cycles(usize::max_value(), sorted.clone()) {
-            CycleSearchResult::NotList if !sorted.is_ref() =>
-                Err(self.error_form(self.type_error(ValidType::List, sorted))),
+    fn check_for_list_pairs(&self, list: Addr) -> Result<(), MachineError> {
+        match self.detect_cycles(usize::max_value(), list.clone()) {
+            CycleSearchResult::NotList if !list.is_ref() =>
+                Err(self.error_form(self.type_error(ValidType::List, list))),
             _ => {
-                let mut addr = sorted;
+                let mut addr = list;
 
                 while let Addr::Lis(l) = self.store(self.deref(addr)) {
                     let mut new_l = l;
-                    
+
                     loop {
                         match self.heap[new_l].clone() {
                             HeapCellValue::Addr(Addr::Str(l)) => new_l = l,
@@ -79,6 +67,22 @@ impl MachineState {
         }
     }
 
+    // see 8.4.4 of Draft Technical Corrigendum 2.
+    pub(super) fn check_keysort_errors(&self) -> Result<(), MachineError> {
+        let pairs  = self.store(self.deref(self[temp_v!(1)].clone()));
+        let sorted = self.store(self.deref(self[temp_v!(2)].clone()));
+
+        match self.detect_cycles(usize::max_value(), pairs.clone()) {
+            CycleSearchResult::PartialList(..) =>
+                Err(self.error_form(self.instantiation_error())),
+            CycleSearchResult::NotList =>
+                Err(self.error_form(self.type_error(ValidType::List, pairs))),
+            _ => Ok(())
+        }?;
+
+        self.check_for_list_pairs(sorted)
+    }
+
     pub(super) fn evaluation_error(&self, eval_error: EvalError) -> MachineError {
         functor!("evaluation_error", 1, [heap_atom!(eval_error.as_str())])
     }
index b6f0d1d35cc57177b7ff86799a1a2248d23e9010..554b7e04014b9b5babcbfb511e2c2141f0df65cf 100644 (file)
@@ -1742,7 +1742,7 @@ impl MachineState {
                     _ => Err(self.error_form(self.type_error(ValidType::Pair,
                                                              self.heap[s].as_addr(s))))
                 },
-            a => Err(self.error_form(self.type_error(ValidType::Callable, a)))
+            a => Err(self.error_form(self.type_error(ValidType::Pair, a)))
         }
     }