fix toplevel heap view

This commit is contained in:
Mark Thom
2019-03-24 10:10:43 -06:00
parent ca5138ccea
commit 155c54c99d
2 changed files with 12 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "scryer-prolog" name = "scryer-prolog"
version = "0.8.16" version = "0.8.17"
authors = ["Mark Thom <markjordanthom@gmail.com>"] authors = ["Mark Thom <markjordanthom@gmail.com>"]
repository = "https://github.com/mthom/scryer-prolog" repository = "https://github.com/mthom/scryer-prolog"
description = "A modern Prolog implementation written mostly in Rust." description = "A modern Prolog implementation written mostly in Rust."

View File

@@ -373,10 +373,15 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
match result { match result {
EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) =>
loop { loop {
if wam.or_stack_is_empty() { let bindings = {
if heap_locs.is_empty() { let mut output = PrinterOutputter::new();
wam.toplevel_heap_view(&heap_locs, output).result()
};
let attr_goals = wam.attribute_goals(&heap_locs); let attr_goals = wam.attribute_goals(&heap_locs);
if wam.or_stack_is_empty() {
if bindings.is_empty() {
if !attr_goals.is_empty() { if !attr_goals.is_empty() {
println!("{}.", attr_goals); println!("{}.", attr_goals);
} else { } else {
@@ -385,29 +390,20 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
return; return;
} }
} else if heap_locs.is_empty() { } else if bindings.is_empty() && attr_goals.is_empty() {
print!("true"); print!("true");
stdout().flush().unwrap(); stdout().flush().unwrap();
} }
let mut raw_stdout = stdout().into_raw_mode().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 !attr_goals.is_empty() {
if bindings.is_empty() { if bindings.is_empty() {
write!(raw_stdout, "{}", attr_goals).unwrap(); write!(raw_stdout, "{}", attr_goals).unwrap();
} else { } else {
write!(raw_stdout, "{}, {}", bindings, attr_goals).unwrap(); write!(raw_stdout, "{}, {}", bindings, attr_goals).unwrap();
} }
} else { } else if !bindings.is_empty() {
write!(raw_stdout, "{}", bindings).unwrap(); write!(raw_stdout, "{}", bindings).unwrap();
} }