clear ball before setting it (#246)
This commit is contained in:
@@ -42,18 +42,26 @@ 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()
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl Ball {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
stub
|
stub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
@@ -591,7 +589,7 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
attr_var_init_queue_b,
|
attr_var_init_queue_b,
|
||||||
attr_var_init_bindings_b,
|
attr_var_init_bindings_b,
|
||||||
);
|
);
|
||||||
|
|
||||||
machine_st.b = machine_st.or_stack[b].b;
|
machine_st.b = machine_st.or_stack[b].b;
|
||||||
machine_st.or_stack.truncate(machine_st.b);
|
machine_st.or_stack.truncate(machine_st.b);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1074,18 +1072,18 @@ impl MachineState {
|
|||||||
(Number::Float(f), _) | (_, Number::Float(f)) => {
|
(Number::Float(f), _) | (_, Number::Float(f)) => {
|
||||||
let n = Addr::Con(Constant::Float(f));
|
let n = Addr::Con(Constant::Float(f));
|
||||||
let stub = MachineError::functor_stub(clause_name!("gcd"), 2);
|
let stub = MachineError::functor_stub(clause_name!("gcd"), 2);
|
||||||
|
|
||||||
Err(self.error_form(MachineError::type_error(ValidType::Integer, n), stub))
|
Err(self.error_form(MachineError::type_error(ValidType::Integer, n), stub))
|
||||||
}
|
}
|
||||||
(Number::Rational(r), _) | (_, Number::Rational(r)) => {
|
(Number::Rational(r), _) | (_, Number::Rational(r)) => {
|
||||||
let n = Addr::Con(Constant::Rational(r));
|
let n = Addr::Con(Constant::Rational(r));
|
||||||
let stub = MachineError::functor_stub(clause_name!("gcd"), 2);
|
let stub = MachineError::functor_stub(clause_name!("gcd"), 2);
|
||||||
|
|
||||||
Err(self.error_form(MachineError::type_error(ValidType::Integer, n), stub))
|
Err(self.error_form(MachineError::type_error(ValidType::Integer, n), stub))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn float_pow(&self, n1: Number, n2: Number) -> Result<Number, MachineStub> {
|
fn float_pow(&self, n1: Number, n2: Number) -> Result<Number, MachineStub> {
|
||||||
let f1 = result_f(&n1, rnd_f);
|
let f1 = result_f(&n1, rnd_f);
|
||||||
let f2 = result_f(&n2, rnd_f);
|
let f2 = result_f(&n2, rnd_f);
|
||||||
@@ -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,
|
||||||
@@ -3127,14 +3128,14 @@ impl MachineState {
|
|||||||
|
|
||||||
pub(super) fn allocate(&mut self, num_cells: usize) {
|
pub(super) fn allocate(&mut self, num_cells: usize) {
|
||||||
let gi = self.next_global_index();
|
let gi = self.next_global_index();
|
||||||
// let new_e = self.e + 1;
|
// let new_e = self.e + 1;
|
||||||
|
|
||||||
self.p += 1;
|
self.p += 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/* See issue #244 for an example of a program broken (at the
|
/* See issue #244 for an example of a program broken (at the
|
||||||
top level) by the inclusion of this code. A proper GC must determine if an
|
top level) by the inclusion of this code. A proper GC must determine if an
|
||||||
existing AND frame is safe to resize; the check here is not
|
existing AND frame is safe to resize; the check here is not
|
||||||
enough.
|
enough.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -3185,7 +3186,7 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_call_clause(
|
fn handle_call_clause(
|
||||||
&mut self,
|
&mut self,
|
||||||
indices: &mut IndexStore,
|
indices: &mut IndexStore,
|
||||||
|
|||||||
@@ -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
|
||||||
).
|
).
|
||||||
|
|||||||
Reference in New Issue
Block a user