From: Nicolas Luck Date: Mon, 18 Sep 2023 11:25:27 +0000 (+0200) Subject: Construct and return exception string X-Git-Tag: remove^2~15 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=65f64e428e04d4d02ab61b294b3fa75bde319ef1;p=scryer-prolog.git Construct and return exception string --- diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index d1b6445e..6c4c262f 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -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::>() + .join(" "); + + return Err(error_string); } let mut bindings: BTreeMap = 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")) ); }