fix bugs in call_with_inference_limit

This commit is contained in:
Mark Thom
2018-02-23 00:16:40 -07:00
parent 5c5257bdbd
commit 8d182b3f02
7 changed files with 65 additions and 50 deletions

View File

@@ -370,7 +370,7 @@ impl CallWithInferenceLimitCallPolicy {
*policy = Box::new(new_policy);
}
fn increment(&mut self) -> CallResult {
fn increment(&mut self) -> CallResult {
if let Some(&(ref limit, bp)) = self.limits.last() {
if self.count == **limit {
return Err(functor!(self.atom_tbl,
@@ -385,7 +385,6 @@ impl CallWithInferenceLimitCallPolicy {
Ok(())
}
// returns the count.
pub(crate) fn add_limit(&mut self, limit: Rc<BigInt>, b: usize) -> Rc<BigInt> {
let limit = Rc::new(&*limit + &self.count);
@@ -397,7 +396,6 @@ impl CallWithInferenceLimitCallPolicy {
Rc::new(self.count.clone())
}
// returns the count.
pub(crate) fn remove_limit(&mut self, b: usize) -> Rc<BigInt> {
if let Some((_, bp)) = self.limits.last().cloned() {
if bp == b {

View File

@@ -216,6 +216,7 @@ impl MachineState {
let tr = self.tr;
let val = self.trail[tr - 1];
self.trail[i] = val;
self.tr -= 1; // NEW.
},
Ref::StackCell(fr, _) => {
let b = self.b - 1;
@@ -232,6 +233,7 @@ impl MachineState {
let tr = self.tr;
let val = self.trail[tr - 1];
self.trail[i] = val;
self.tr -= 1; // NEW.
}
}
};
@@ -1313,9 +1315,9 @@ impl MachineState {
self.p += 1;
},
&BuiltInInstruction::InferenceLevel => { // X1 = R, X2 = B.
let a1 = self[temp_v!(1)].clone();
let a2 = self.store(self.deref(self[temp_v!(2)].clone()));
&BuiltInInstruction::InferenceLevel(r1, r2) => { // X1 = R, X2 = B.
let a1 = self[r1].clone();
let a2 = self.store(self.deref(self[r2].clone()));
match a2 {
Addr::Con(Constant::Usize(bp)) =>
@@ -1366,7 +1368,7 @@ impl MachineState {
match call_policy.downcast_mut::<CallWithInferenceLimitCallPolicy>().ok() {
Some(call_policy) => {
let count = call_policy.add_limit(n, bp);
self[r3] = Addr::Con(Constant::Number(Number::Integer(count)));
self[r3] = Addr::Con(Constant::Number(Number::Integer(count)));
},
None => panic!("install_inference_counter: should have installed \\
CallWithInferenceLimitCallPolicy.")
@@ -1457,10 +1459,10 @@ impl MachineState {
None
}
} else {
panic!("remove_inference_counter: expected Usize in A1.");
panic!("remove_call_policy_check: expected Usize in A1.");
}
},
None => panic!("remove_inference_counters: requires \\
None => panic!("remove_call_policy_check: requires \\
CallWithInferenceLimitCallPolicy.")
};
@@ -1470,15 +1472,14 @@ impl MachineState {
self.p += 1;
},
&BuiltInInstruction::RemoveInferenceCounter(r1, r2) => { // A1 = B, A2 = Count.
&BuiltInInstruction::RemoveInferenceCounter(r1, r2) => { // A1 = B
match call_policy.downcast_mut::<CallWithInferenceLimitCallPolicy>().ok() {
Some(call_policy) => {
let a1 = self.store(self.deref(self[r1].clone()));
if let Addr::Con(Constant::Usize(bp)) = a1 {
let count = call_policy.remove_limit(bp);
self[r2] = Addr::Con(Constant::Number(Number::Integer(count)));
self[r2] = Addr::Con(Constant::Number(Number::Integer(count)));
} else {
panic!("remove_inference_counter: expected Usize in A1.");
}
@@ -1844,9 +1845,9 @@ impl MachineState {
Ordering::Equal => atom!("=", self.atom_tbl),
Ordering::Less => atom!("<", self.atom_tbl)
});
self.unify(a1, c);
self.p += 1;
},
&ControlInstruction::CompareExecute => {
@@ -1859,9 +1860,9 @@ impl MachineState {
Ordering::Equal => atom!("=", self.atom_tbl),
Ordering::Less => atom!("<", self.atom_tbl)
});
self.unify(a1, c);
self.p = self.cp;
},
&ControlInstruction::CompareTermCall(qt) => {