allow toplevel answers to be passed back as queries

This commit is contained in:
Mark Thom
2019-03-22 10:00:07 -06:00
parent 33b581effc
commit 380375228b
2 changed files with 19 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "scryer-prolog" name = "scryer-prolog"
version = "0.8.12" version = "0.8.13"
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

@@ -371,35 +371,29 @@ fn next_step(mut stdout: RawTerminal<std::io::Stdout>) -> ContinueResult
pub fn print(wam: &mut Machine, result: EvalSession) { 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) => {
if wam.or_stack_is_empty() {
println!("true.");
if heap_locs.is_empty() {
return;
}
}
if !wam.or_stack_is_empty() {
print!("true .");
if !heap_locs.is_empty() {
println!("\r");
}
}
loop { loop {
let mut output = PrinterOutputter::new(); if wam.or_stack_is_empty() {
if heap_locs.is_empty() {
let bindings = wam.heap_view(&heap_locs, output).result(); println!("true.");
return;
}
} else if heap_locs.is_empty() {
print!("true");
stdout().flush().unwrap();
}
let mut raw_stdout = stdout().into_raw_mode().unwrap(); let mut raw_stdout = stdout().into_raw_mode().unwrap();
if !heap_locs.is_empty() { if !heap_locs.is_empty() {
let mut output = PrinterOutputter::new();
let bindings = wam.heap_view(&heap_locs, output).result();
write!(raw_stdout, "{}", bindings).unwrap(); write!(raw_stdout, "{}", bindings).unwrap();
raw_stdout.flush().unwrap(); raw_stdout.flush().unwrap();
let attr_goals = wam.attribute_goals(&heap_locs); let attr_goals = wam.attribute_goals(&heap_locs);
if !attr_goals.is_empty() { if !attr_goals.is_empty() {
write!(raw_stdout, "\r\n{}\r\n", attr_goals).unwrap(); write!(raw_stdout, "\r\n{}\r\n", attr_goals).unwrap();
} }
@@ -429,14 +423,14 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
write!(raw_stdout, "{}\r\n", error_string(e)).unwrap(); write!(raw_stdout, "{}\r\n", error_string(e)).unwrap();
raw_stdout.flush().unwrap(); raw_stdout.flush().unwrap();
return; return;
} }
} else { } else {
if heap_locs.is_empty() { if heap_locs.is_empty() {
write!(raw_stdout, "true.\r\n").unwrap(); write!(raw_stdout, "true.\r\n").unwrap();
} else { } else {
write!(raw_stdout, ".\r\n").unwrap(); write!(raw_stdout, ".\r\n").unwrap();
} }
break; break;
} }
} }