mthom's changes fixing the panic
This commit is contained in:
@@ -35,6 +35,28 @@ impl Machine {
|
|||||||
self.run_module_predicate(atom!("loader"), (atom!("consult_stream"), 2));
|
self.run_module_predicate(atom!("loader"), (atom!("consult_stream"), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allocate_stub_choice_point(&mut self) {
|
||||||
|
// NOTE: create a choice point to terminate the dispatch_loop
|
||||||
|
// if an exception is thrown. since the and/or stack is presumed empty,
|
||||||
|
|
||||||
|
let stub_b = self.machine_st.stack.allocate_or_frame(0);
|
||||||
|
let or_frame = self.machine_st.stack.index_or_frame_mut(0);
|
||||||
|
|
||||||
|
or_frame.prelude.num_cells = 0;
|
||||||
|
or_frame.prelude.e = 0;
|
||||||
|
or_frame.prelude.cp = 0;
|
||||||
|
or_frame.prelude.b = 0;
|
||||||
|
or_frame.prelude.bp = BREAK_FROM_DISPATCH_LOOP_LOC;
|
||||||
|
or_frame.prelude.boip = 0;
|
||||||
|
or_frame.prelude.biip = 0;
|
||||||
|
or_frame.prelude.tr = 0;
|
||||||
|
or_frame.prelude.h = 0;
|
||||||
|
or_frame.prelude.b0 = 0;
|
||||||
|
or_frame.prelude.attr_var_queue_len = 0;
|
||||||
|
|
||||||
|
self.machine_st.b = stub_b;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run_query(&mut self, query: String) -> QueryResult {
|
pub fn run_query(&mut self, query: String) -> QueryResult {
|
||||||
println!("Query: {}", query);
|
println!("Query: {}", query);
|
||||||
// Parse the query so we can analyze and then call the term
|
// Parse the query so we can analyze and then call the term
|
||||||
@@ -64,6 +86,10 @@ impl Machine {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
self.allocate_stub_choice_point();
|
||||||
|
|
||||||
|
let stub_b = self.machine_st.b;
|
||||||
|
|
||||||
let mut matches: Vec<QueryResolutionLine> = Vec::new();
|
let mut matches: Vec<QueryResolutionLine> = Vec::new();
|
||||||
// Call the term
|
// Call the term
|
||||||
loop {
|
loop {
|
||||||
@@ -75,6 +101,14 @@ impl Machine {
|
|||||||
println!("false");
|
println!("false");
|
||||||
matches.push(QueryResolutionLine::False);
|
matches.push(QueryResolutionLine::False);
|
||||||
break;
|
break;
|
||||||
|
} else if self.machine_st.ball.stub.len() != 0 {
|
||||||
|
// NOTE: this means an exception was thrown, at which
|
||||||
|
// point we backtracked to the stub choice point.
|
||||||
|
// this should halt the search for solutions as it
|
||||||
|
// does in the Scryer top-level. the exception term is
|
||||||
|
// contained in self.machine_st.ball.
|
||||||
|
println!("exception thrown");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
|
let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
|
||||||
@@ -109,11 +143,14 @@ impl Machine {
|
|||||||
|
|
||||||
matches.push(QueryResolutionLine::Match(bindings));
|
matches.push(QueryResolutionLine::Match(bindings));
|
||||||
|
|
||||||
if self.machine_st.b > 0 {
|
|
||||||
println!("b: {}", self.machine_st.b);
|
|
||||||
// NOTE: there are outstanding choicepoints, backtrack
|
// NOTE: there are outstanding choicepoints, backtrack
|
||||||
// through them for further solutions.
|
// through them for further solutions. if
|
||||||
|
// self.machine_st.b == stub_b we've backtracked to the stub
|
||||||
|
// choice point, so we should break.
|
||||||
self.machine_st.backtrack();
|
self.machine_st.backtrack();
|
||||||
|
|
||||||
|
if self.machine_st.b > stub_b {
|
||||||
|
println!("b: {}", self.machine_st.b);
|
||||||
} else {
|
} else {
|
||||||
println!("breaking");
|
println!("breaking");
|
||||||
// NOTE: out of choicepoints to backtrack through, no
|
// NOTE: out of choicepoints to backtrack through, no
|
||||||
@@ -122,6 +159,11 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: deallocate stub choice point
|
||||||
|
if self.machine_st.b == stub_b {
|
||||||
|
self.trust_me();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(QueryResolution::from(matches))
|
Ok(QueryResolution::from(matches))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user