print attribute goals alongside variable bindings as a single, unified goals

This commit is contained in:
Mark Thom
2019-03-24 00:26:29 -06:00
parent 0351936a58
commit 11198fdb31
3 changed files with 32 additions and 20 deletions

View File

@@ -22,7 +22,7 @@ freeze(X, Goal) :-
gather_freeze_goals(Attrs, _, _) :- gather_freeze_goals(Attrs, _, _) :-
var(Attrs), !. var(Attrs), !.
gather_freeze_goals([frozen(X) | _], Var, [frozen(Var, X) | _]) :- gather_freeze_goals([frozen(X) | _], Var, [freeze(Var, X) | _]) :-
!. !.
gather_freeze_goals([_ | Attrs], Var, Goals) :- gather_freeze_goals([_ | Attrs], Var, Goals) :-
gather_freeze_goals(Attrs, Var, Goals). gather_freeze_goals(Attrs, Var, Goals).

View File

@@ -250,13 +250,12 @@ impl Machine {
Ok(()) Ok(())
} }
pub fn remove_unbound_vars(&self, heap_locs: &mut HeapVarDict) { pub fn remove_unbound_vars(&self, orig_heap_locs: &HeapVarDict, heap_locs: &mut HeapVarDict) {
for (var, addr) in heap_locs.clone() { for (var, addr) in orig_heap_locs.iter() {
match self.machine_st.store(self.machine_st.deref(addr.clone())) { match self.machine_st.store(self.machine_st.deref(addr.clone())) {
new_addr => new_addr => if new_addr.is_ref() {
if addr.is_ref() && new_addr == addr { heap_locs.remove(var);
heap_locs.remove(&var); }
}
} }
} }
} }

View File

@@ -372,15 +372,24 @@ 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) => {
let orig_heap_locs = heap_locs.clone();
loop { loop {
wam.remove_unbound_vars(&mut heap_locs); wam.remove_unbound_vars(&orig_heap_locs, &mut heap_locs);
if wam.or_stack_is_empty() { if wam.or_stack_is_empty() {
if heap_locs.is_empty() { if heap_locs.is_empty() {
println!("true."); let attr_goals = wam.attribute_goals(&orig_heap_locs);
if !attr_goals.is_empty() {
println!("{}.", attr_goals);
} else {
println!("true.");
}
return; return;
} }
} else if heap_locs.is_empty() { } else if heap_locs.is_empty() && orig_heap_locs.is_empty() {
print!("true"); print!("true");
stdout().flush().unwrap(); stdout().flush().unwrap();
} }
@@ -393,11 +402,15 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
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(&orig_heap_locs);
if !attr_goals.is_empty() { if !attr_goals.is_empty() {
write!(raw_stdout, "\r\n{}\r\n", attr_goals).unwrap(); if heap_locs.is_empty() {
write!(raw_stdout, "{}", attr_goals).unwrap();
} else {
write!(raw_stdout, ", {}", attr_goals).unwrap();
} }
} }
@@ -427,7 +440,7 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
return; return;
} }
} else { } else {
if heap_locs.is_empty() { if heap_locs.is_empty() && attr_goals.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();