fix odd response, toplevel issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "scryer-prolog"
|
name = "scryer-prolog"
|
||||||
version = "0.8.72"
|
version = "0.8.73"
|
||||||
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."
|
||||||
|
|||||||
@@ -195,7 +195,11 @@ impl HCValueOutputter for PrinterOutputter {
|
|||||||
PrinterOutputter { contents: String::new() }
|
PrinterOutputter { contents: String::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(&mut self, contents: &str) {
|
fn append(&mut self, contents: &str) {
|
||||||
|
if requires_space(&self.contents, contents) {
|
||||||
|
self.push_char(' ');
|
||||||
|
}
|
||||||
|
|
||||||
self.contents += contents;
|
self.contents += contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +316,7 @@ macro_rules! push_space_if_amb {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn requires_space(atom: &str, op: &str) -> bool {
|
pub fn requires_space(atom: &str, op: &str) -> bool {
|
||||||
match atom.chars().last() {
|
match atom.chars().last() {
|
||||||
Some(ac) => op.chars().next().map(|oc| {
|
Some(ac) => op.chars().next().map(|oc| {
|
||||||
if ac == '0' {
|
if ac == '0' {
|
||||||
@@ -571,7 +575,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn append_str(&mut self, s: &str) {
|
fn append_str(&mut self, s: &str) {
|
||||||
self.last_item_idx = self.outputter.len();
|
self.last_item_idx = self.outputter.len();
|
||||||
self.outputter.append(s);
|
self.outputter.append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn offset_as_string(&self, addr: Addr) -> Option<String> {
|
fn offset_as_string(&self, addr: Addr) -> Option<String> {
|
||||||
|
|||||||
@@ -440,6 +440,18 @@ impl Machine {
|
|||||||
self.machine_st.p = CodePtr::Local(p);
|
self.machine_st.p = CodePtr::Local(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn propagate_exception_to_toplevel(&mut self, snapshot: MachineState) {
|
||||||
|
let ball = self.machine_st.ball.take();
|
||||||
|
|
||||||
|
self.machine_st.absorb_snapshot(snapshot);
|
||||||
|
self.machine_st.ball = ball;
|
||||||
|
|
||||||
|
let stub = self.machine_st.copy_and_align_ball();
|
||||||
|
self.machine_st.throw_exception(stub);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_eval_session(&mut self, result: EvalSession, snapshot: MachineState) {
|
fn handle_eval_session(&mut self, result: EvalSession, snapshot: MachineState) {
|
||||||
match result {
|
match result {
|
||||||
EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) =>
|
EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) =>
|
||||||
@@ -471,12 +483,15 @@ impl Machine {
|
|||||||
|
|
||||||
if !attr_goals.is_empty() {
|
if !attr_goals.is_empty() {
|
||||||
if bindings.is_empty() {
|
if bindings.is_empty() {
|
||||||
write!(raw_stdout, "{}", attr_goals).unwrap();
|
let space = if requires_space(&attr_goals, ".") { " " } else { "" };
|
||||||
|
write!(raw_stdout, "{}{}", attr_goals, space).unwrap();
|
||||||
} else {
|
} else {
|
||||||
write!(raw_stdout, "{}, {}", bindings, attr_goals).unwrap();
|
let space = if requires_space(&attr_goals, ".") { " " } else { "" };
|
||||||
|
write!(raw_stdout, "{}, {}{}", bindings, attr_goals, space).unwrap();
|
||||||
}
|
}
|
||||||
} else if !bindings.is_empty() {
|
} else if !bindings.is_empty() {
|
||||||
write!(raw_stdout, "{}", bindings).unwrap();
|
let space = if requires_space(&bindings, ".") { " " } else { "" };
|
||||||
|
write!(raw_stdout, "{}{}", bindings, space).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.machine_st.b > 0 {
|
if self.machine_st.b > 0 {
|
||||||
@@ -494,13 +509,17 @@ impl Machine {
|
|||||||
let mut raw_stdout = stdout().into_raw_mode().unwrap();
|
let mut raw_stdout = stdout().into_raw_mode().unwrap();
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
EvalSession::QueryFailure => {
|
EvalSession::QueryFailure =>
|
||||||
write!(raw_stdout, "false.\r\n").unwrap();
|
if self.machine_st.ball.stub.len() > 0 {
|
||||||
raw_stdout.flush().unwrap();
|
self.propagate_exception_to_toplevel(snapshot);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
write!(raw_stdout, "false.\r\n").unwrap();
|
||||||
|
raw_stdout.flush().unwrap();
|
||||||
|
|
||||||
self.machine_st.absorb_snapshot(snapshot);
|
self.machine_st.absorb_snapshot(snapshot);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
EvalSession::Error(err) => {
|
EvalSession::Error(err) => {
|
||||||
self.machine_st.absorb_snapshot(snapshot);
|
self.machine_st.absorb_snapshot(snapshot);
|
||||||
self.throw_session_error(err, (clause_name!("repl"), 0));
|
self.throw_session_error(err, (clause_name!("repl"), 0));
|
||||||
@@ -525,15 +544,7 @@ impl Machine {
|
|||||||
},
|
},
|
||||||
EvalSession::QueryFailure =>
|
EvalSession::QueryFailure =>
|
||||||
if self.machine_st.ball.stub.len() > 0 {
|
if self.machine_st.ball.stub.len() > 0 {
|
||||||
let ball = self.machine_st.ball.take();
|
return self.propagate_exception_to_toplevel(snapshot);
|
||||||
|
|
||||||
self.machine_st.absorb_snapshot(snapshot);
|
|
||||||
self.machine_st.ball = ball;
|
|
||||||
|
|
||||||
let stub = self.machine_st.copy_and_align_ball();
|
|
||||||
self.machine_st.throw_exception(stub);
|
|
||||||
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
println!("false.");
|
println!("false.");
|
||||||
},
|
},
|
||||||
@@ -658,20 +669,27 @@ impl Machine {
|
|||||||
|
|
||||||
|
|
||||||
impl MachineState {
|
impl MachineState {
|
||||||
fn print_query(&self, addr: Addr, op_dir: &OpDir, var_dict: &HeapVarDict) -> PrinterOutputter
|
fn print_query(&mut self, addr: Addr, op_dir: &OpDir, var_dict: &HeapVarDict) -> PrinterOutputter
|
||||||
{
|
{
|
||||||
let output = PrinterOutputter::new();
|
let flags = self.flags;
|
||||||
let mut printer = HCPrinter::from_heap_locs(&self, op_dir, output, var_dict);
|
|
||||||
|
let mut output = {
|
||||||
|
self.flags = MachineFlags { double_quotes: DoubleQuotes::Atom };
|
||||||
|
|
||||||
|
let output = PrinterOutputter::new();
|
||||||
|
let mut printer = HCPrinter::from_heap_locs(&self, op_dir, output, var_dict);
|
||||||
|
|
||||||
printer.quoted = true;
|
printer.quoted = true;
|
||||||
printer.numbervars = false;
|
printer.numbervars = false;
|
||||||
printer.drop_toplevel_spec();
|
printer.drop_toplevel_spec();
|
||||||
|
|
||||||
printer.see_all_locs();
|
printer.see_all_locs();
|
||||||
|
printer.print(addr)
|
||||||
|
};
|
||||||
|
|
||||||
let mut output = printer.print(addr);
|
self.flags = flags;
|
||||||
|
|
||||||
output.push_char('.');
|
output.append(".");
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -818,9 +836,9 @@ impl MachineState {
|
|||||||
if self.fail {
|
if self.fail {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cp = self.p.local();
|
let cp = self.p.local();
|
||||||
self.run_verify_attr_interrupt(cp);
|
self.run_verify_attr_interrupt(cp);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ =>
|
_ =>
|
||||||
|
|||||||
Reference in New Issue
Block a user