clear ball before setting it (#246)

This commit is contained in:
Mark Thom
2019-12-01 03:04:01 -07:00
parent 77e83a390c
commit e48f87fcf0
4 changed files with 31 additions and 25 deletions

View File

@@ -42,19 +42,27 @@ impl AndStack {
AndStack(mem::replace(&mut self.0, vec![])) AndStack(mem::replace(&mut self.0, vec![]))
} }
#[inline]
pub fn push(&mut self, global_index: usize, e: usize, cp: LocalCodePtr, n: usize) { pub fn push(&mut self, global_index: usize, e: usize, cp: LocalCodePtr, n: usize) {
let len = self.0.len(); let len = self.0.len();
self.0.push(Frame::new(global_index, len, e, cp, n)); self.0.push(Frame::new(global_index, len, e, cp, n));
} }
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
} }
#[inline]
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.0.clear() self.0.clear()
} }
#[inline]
pub fn top(&self) -> Option<&Frame> {
self.0.last()
}
/* /*
// See MachineState::allocate for why this is commented out. // See MachineState::allocate for why this is commented out.

View File

@@ -486,7 +486,6 @@ pub(crate) trait CallPolicy: Any {
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr; machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr); machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.or_stack[b].h); machine_st.heap.truncate(machine_st.or_stack[b].h);
let attr_var_init_queue_b = machine_st.or_stack[b].attr_var_init_queue_b; let attr_var_init_queue_b = machine_st.or_stack[b].attr_var_init_queue_b;
@@ -532,7 +531,6 @@ pub(crate) trait CallPolicy: Any {
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr; machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr); machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.or_stack[b].h); machine_st.heap.truncate(machine_st.or_stack[b].h);
let attr_var_init_queue_b = machine_st.or_stack[b].attr_var_init_queue_b; let attr_var_init_queue_b = machine_st.or_stack[b].attr_var_init_queue_b;
@@ -578,8 +576,8 @@ pub(crate) trait CallPolicy: Any {
let curr_pstr_tr = machine_st.pstr_tr; let curr_pstr_tr = machine_st.pstr_tr;
machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr); machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr);
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr); machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.or_stack[b].h); machine_st.heap.truncate(machine_st.or_stack[b].h);

View File

@@ -125,16 +125,14 @@ impl MachineState {
pub(super) fn next_global_index(&self) -> usize { pub(super) fn next_global_index(&self) -> usize {
max( max(
if self.and_stack.len() > 0 { self.or_stack
self.and_stack[self.e].global_index .top()
} else { .map(|or_fr| or_fr.global_index)
0 .unwrap_or(0),
}, self.and_stack
if self.b > 0 { .top()
self.or_stack[self.b - 1].global_index .map(|or_fr| or_fr.global_index)
} else { .unwrap_or(0),
0
},
) + 1 ) + 1
} }
@@ -2039,8 +2037,11 @@ impl MachineState {
} }
pub(super) fn set_ball(&mut self) { pub(super) fn set_ball(&mut self) {
self.ball.reset();
let addr = self[temp_v!(1)].clone(); let addr = self[temp_v!(1)].clone();
self.ball.boundary = self.heap.h; self.ball.boundary = self.heap.h;
copy_term( copy_term(
CopyBallTerm::new(&mut self.and_stack, &mut self.heap, &mut self.ball.stub), CopyBallTerm::new(&mut self.and_stack, &mut self.heap, &mut self.ball.stub),
addr, addr,

View File

@@ -42,8 +42,7 @@
( expand_goals(Term0, Term) -> true ( expand_goals(Term0, Term) -> true
; Term = Term0 ; Term = Term0
), ),
( '$get_b_value'(B), call(Term), ( '$get_b_value'(B), call(Term), '$write_eqs_and_read_input'(B, VarList),
'$write_eqs_and_read_input'(B, VarList),
! !
; write('false.'), nl ; write('false.'), nl
). ).