From 380375228b020fca5a3361dc27cc290af06a5fbf Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 22 Mar 2019 10:00:07 -0600 Subject: [PATCH] allow toplevel answers to be passed back as queries --- Cargo.toml | 2 +- src/prolog/write.rs | 42 ++++++++++++++++++------------------------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 88a1df3e..b4805eff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.8.12" +version = "0.8.13" 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 a036240f..59c82ac2 100644 --- a/src/prolog/write.rs +++ b/src/prolog/write.rs @@ -371,35 +371,29 @@ fn next_step(mut stdout: RawTerminal) -> ContinueResult pub fn print(wam: &mut Machine, result: EvalSession) { match result { - 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"); - } - } - + EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => { loop { - let mut output = PrinterOutputter::new(); - - let bindings = wam.heap_view(&heap_locs, output).result(); + if wam.or_stack_is_empty() { + if heap_locs.is_empty() { + println!("true."); + return; + } + } else if heap_locs.is_empty() { + print!("true"); + stdout().flush().unwrap(); + } + let mut raw_stdout = stdout().into_raw_mode().unwrap(); if !heap_locs.is_empty() { + let mut output = PrinterOutputter::new(); + let bindings = wam.heap_view(&heap_locs, output).result(); + write!(raw_stdout, "{}", bindings).unwrap(); raw_stdout.flush().unwrap(); - + let attr_goals = wam.attribute_goals(&heap_locs); - + if !attr_goals.is_empty() { 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(); raw_stdout.flush().unwrap(); return; - } + } } else { if heap_locs.is_empty() { write!(raw_stdout, "true.\r\n").unwrap(); } else { write!(raw_stdout, ".\r\n").unwrap(); } - + break; } } -- 2.54.0