From: Mark Thom Date: Sun, 24 Mar 2019 16:10:43 +0000 (-0600) Subject: fix toplevel heap view X-Git-Tag: v0.8.110~155 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=155c54c99d85bfeb9ba7d3177c29a77589059b47;p=scryer-prolog.git fix toplevel heap view --- diff --git a/Cargo.toml b/Cargo.toml index 3e537a6b..e113c926 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.8.16" +version = "0.8.17" authors = ["Mark Thom "] repository = "https://github.com/mthom/scryer-prolog" description = "A modern Prolog implementation written mostly in Rust." diff --git a/src/prolog/write.rs b/src/prolog/write.rs index 721394d9..c667c0f9 100644 --- a/src/prolog/write.rs +++ b/src/prolog/write.rs @@ -373,10 +373,15 @@ pub fn print(wam: &mut Machine, result: EvalSession) { match result { EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => loop { - if wam.or_stack_is_empty() { - if heap_locs.is_empty() { - let attr_goals = wam.attribute_goals(&heap_locs); + let bindings = { + let mut output = PrinterOutputter::new(); + wam.toplevel_heap_view(&heap_locs, output).result() + }; + let attr_goals = wam.attribute_goals(&heap_locs); + + if wam.or_stack_is_empty() { + if bindings.is_empty() { if !attr_goals.is_empty() { println!("{}.", attr_goals); } else { @@ -385,29 +390,20 @@ pub fn print(wam: &mut Machine, result: EvalSession) { return; } - } else if heap_locs.is_empty() { + } else if bindings.is_empty() && attr_goals.is_empty() { print!("true"); stdout().flush().unwrap(); } let mut raw_stdout = stdout().into_raw_mode().unwrap(); - let bindings = if !heap_locs.is_empty() { - let mut output = PrinterOutputter::new(); - wam.toplevel_heap_view(&heap_locs, output).result() - } else { - "".to_string() - }; - - let attr_goals = wam.attribute_goals(&heap_locs); - if !attr_goals.is_empty() { if bindings.is_empty() { write!(raw_stdout, "{}", attr_goals).unwrap(); } else { write!(raw_stdout, "{}, {}", bindings, attr_goals).unwrap(); } - } else { + } else if !bindings.is_empty() { write!(raw_stdout, "{}", bindings).unwrap(); } @@ -445,7 +441,7 @@ pub fn print(wam: &mut Machine, result: EvalSession) { break; } - }, + }, EvalSession::Error(e) => println!("{}", e), _ => {} };