]> Repositorios git - scryer-prolog.git/commitdiff
Construct and return exception string
authorNicolas Luck <[email protected]>
Mon, 18 Sep 2023 11:25:27 +0000 (13:25 +0200)
committerNicolas Luck <[email protected]>
Mon, 18 Sep 2023 11:25:27 +0000 (13:25 +0200)
src/machine/lib_machine.rs

index d1b6445e51219f9a4fe312f96441916a3b7ab8f2..6c4c262f8a74d0e5f7dfbfd34b28b2e6eb8987c1 100644 (file)
@@ -107,8 +107,27 @@ impl Machine {
                 // this should halt the search for solutions as it
                 // does in the Scryer top-level. the exception term is
                 // contained in self.machine_st.ball.
-                println!("exception thrown");
-                break;
+                let error_string = self.machine_st.ball.stub
+                    .iter()
+                    .filter(|h| match h.get_tag() {
+                        HeapCellValueTag::Atom => true,
+                        HeapCellValueTag::Fixnum => true,
+                        _ => false,
+                    })
+                    .map(|h| match h.get_tag() {
+                        HeapCellValueTag::Atom => {
+                            let (name, _) = cell_as_atom_cell!(h).get_name_and_arity();
+                            name.as_str().to_string()
+                        }
+                        HeapCellValueTag::Fixnum => {
+                            h.get_value().clone().to_string()
+                        },
+                        _ => unreachable!(),
+                    })
+                    .collect::<Vec<String>>() 
+                    .join(" ");
+                
+                return Err(error_string);
             }
 
             let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
@@ -221,7 +240,7 @@ mod tests {
         let output = machine.run_query(query);
         assert_eq!(
             output,
-            Err(String::from("error(existence_error(procedure,triple/3),triple/3)."))
+            Err(String::from("error existence_error procedure / triple 3 / triple 3"))
         );
     }