fix exception handling when thrown by throw_exception, and within setup_call_cleanup and call_with_inference_limit.
This commit is contained in:
@@ -951,7 +951,8 @@ pub enum ArithmeticInstruction {
|
|||||||
|
|
||||||
pub enum BuiltInInstruction {
|
pub enum BuiltInInstruction {
|
||||||
CleanUpBlock,
|
CleanUpBlock,
|
||||||
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
|
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
|
||||||
|
DefaultRetryMeElse(usize),
|
||||||
DefaultTrustMe,
|
DefaultTrustMe,
|
||||||
DefaultSetCutPoint(RegType),
|
DefaultSetCutPoint(RegType),
|
||||||
DynamicCompareNumber(CompareNumberQT),
|
DynamicCompareNumber(CompareNumberQT),
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ fn get_builtins() -> Code {
|
|||||||
put_unsafe_value!(1, 2)],
|
put_unsafe_value!(1, 2)],
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
goto_execute!(44, 2), //21: goto end_block/2.
|
goto_execute!(44, 2), //21: goto end_block/2.
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
allocate!(3),
|
allocate!(3),
|
||||||
fact![get_var_in_fact!(perm_v!(2), 2),
|
fact![get_var_in_fact!(perm_v!(2), 2),
|
||||||
get_var_in_fact!(perm_v!(1), 3)],
|
get_var_in_fact!(perm_v!(1), 3)],
|
||||||
@@ -72,7 +72,7 @@ fn get_builtins() -> Code {
|
|||||||
query![put_value!(perm_v!(2), 1)],
|
query![put_value!(perm_v!(2), 1)],
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
execute_n!(1),
|
execute_n!(1),
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
unwind_stack!(),
|
unwind_stack!(),
|
||||||
try_me_else!(9), // end_block/2, 44.
|
try_me_else!(9), // end_block/2, 44.
|
||||||
allocate!(1),
|
allocate!(1),
|
||||||
@@ -83,7 +83,7 @@ fn get_builtins() -> Code {
|
|||||||
deallocate!(),
|
deallocate!(),
|
||||||
reset_block!(),
|
reset_block!(),
|
||||||
proceed!(),
|
proceed!(),
|
||||||
trust_me!(), // 53.
|
default_trust_me!(), // 53.
|
||||||
allocate!(0),
|
allocate!(0),
|
||||||
query![get_var_in_query!(temp_v!(3), 1),
|
query![get_var_in_query!(temp_v!(3), 1),
|
||||||
put_value!(temp_v!(2), 1)],
|
put_value!(temp_v!(2), 1)],
|
||||||
@@ -446,7 +446,7 @@ fn get_builtins() -> Code {
|
|||||||
atom!("instantiation_error"),
|
atom!("instantiation_error"),
|
||||||
temp_v!(1))],
|
temp_v!(1))],
|
||||||
goto_execute!(59, 1),
|
goto_execute!(59, 1),
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
query![get_var_in_query!(temp_v!(4), 2),
|
query![get_var_in_query!(temp_v!(4), 2),
|
||||||
put_value!(temp_v!(3), 2),
|
put_value!(temp_v!(3), 2),
|
||||||
get_var_in_query!(temp_v!(5), 3),
|
get_var_in_query!(temp_v!(5), 3),
|
||||||
@@ -468,7 +468,7 @@ fn get_builtins() -> Code {
|
|||||||
put_value!(perm_v!(1), 2)],
|
put_value!(perm_v!(1), 2)],
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
check_cp_execute!(),
|
check_cp_execute!(),
|
||||||
retry_me_else!(12),
|
default_retry_me_else!(12),
|
||||||
allocate!(2),
|
allocate!(2),
|
||||||
query![put_value!(temp_v!(3), 1)],
|
query![put_value!(temp_v!(3), 1)],
|
||||||
reset_block!(),
|
reset_block!(),
|
||||||
@@ -480,7 +480,7 @@ fn get_builtins() -> Code {
|
|||||||
query![put_unsafe_value!(1, 1)],
|
query![put_unsafe_value!(1, 1)],
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
goto_execute!(59, 1), // goto throw/1, 59.
|
goto_execute!(59, 1), // goto throw/1, 59.
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
allocate!(0),
|
allocate!(0),
|
||||||
goto_call!(354, 0), // goto run_cleaners_without_handling/0, 354.
|
goto_call!(354, 0), // goto run_cleaners_without_handling/0, 354.
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
@@ -497,7 +497,7 @@ fn get_builtins() -> Code {
|
|||||||
default_set_cp!(perm_v!(1)),
|
default_set_cp!(perm_v!(1)),
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
goto_execute!(342, 0), // goto run_cleaners_with_handling/0, 342.
|
goto_execute!(342, 0), // goto run_cleaners_with_handling/0, 342.
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
goto_execute!(382, 0), // goto restore_cut_points/0, 382.
|
goto_execute!(382, 0), // goto restore_cut_points/0, 382.
|
||||||
try_me_else!(10), // run_cleaners_without_handling/1, 354.
|
try_me_else!(10), // run_cleaners_without_handling/1, 354.
|
||||||
allocate!(2),
|
allocate!(2),
|
||||||
@@ -509,7 +509,7 @@ fn get_builtins() -> Code {
|
|||||||
default_set_cp!(perm_v!(1)),
|
default_set_cp!(perm_v!(1)),
|
||||||
deallocate!(),
|
deallocate!(),
|
||||||
goto_execute!(354, 0), // goto run_cleaners_without_handling/0, 354.
|
goto_execute!(354, 0), // goto run_cleaners_without_handling/0, 354.
|
||||||
trust_me!(),
|
default_trust_me!(),
|
||||||
goto_execute!(382, 0), // goto restore_cut_points/0, 382.
|
goto_execute!(382, 0), // goto restore_cut_points/0, 382.
|
||||||
allocate!(1), // sgc_on_success/2, 366.
|
allocate!(1), // sgc_on_success/2, 366.
|
||||||
fact![get_var_in_fact!(perm_v!(1), 2)],
|
fact![get_var_in_fact!(perm_v!(1), 2)],
|
||||||
|
|||||||
@@ -207,6 +207,8 @@ impl fmt::Display for BuiltInInstruction {
|
|||||||
write!(f, "clean_up_block"),
|
write!(f, "clean_up_block"),
|
||||||
&BuiltInInstruction::DefaultSetCutPoint(r) =>
|
&BuiltInInstruction::DefaultSetCutPoint(r) =>
|
||||||
write!(f, "default_set_cp {}", r),
|
write!(f, "default_set_cp {}", r),
|
||||||
|
&BuiltInInstruction::DefaultRetryMeElse(o) =>
|
||||||
|
write!(f, "default_retry_me_else {}", o),
|
||||||
&BuiltInInstruction::DefaultTrustMe =>
|
&BuiltInInstruction::DefaultTrustMe =>
|
||||||
write!(f, "default_trust_me"),
|
write!(f, "default_trust_me"),
|
||||||
&BuiltInInstruction::InstallInferenceCounter(r1, r2, r3) =>
|
&BuiltInInstruction::InstallInferenceCounter(r1, r2, r3) =>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ pub(super) struct DuplicateBallTerm<'a> {
|
|||||||
impl<'a> DuplicateBallTerm<'a> {
|
impl<'a> DuplicateBallTerm<'a> {
|
||||||
pub(super) fn new(state: &'a mut MachineState) -> Self {
|
pub(super) fn new(state: &'a mut MachineState) -> Self {
|
||||||
let hb = state.heap.len();
|
let hb = state.heap.len();
|
||||||
DuplicateBallTerm { state: state, heap_boundary: hb }
|
DuplicateBallTerm { state, heap_boundary: hb }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ impl MachineState {
|
|||||||
let tr = self.tr;
|
let tr = self.tr;
|
||||||
let val = self.trail[tr - 1];
|
let val = self.trail[tr - 1];
|
||||||
self.trail[i] = val;
|
self.trail[i] = val;
|
||||||
self.tr -= 1; // NEW.
|
self.tr -= 1;
|
||||||
},
|
},
|
||||||
Ref::StackCell(fr, _) => {
|
Ref::StackCell(fr, _) => {
|
||||||
let b = self.b - 1;
|
let b = self.b - 1;
|
||||||
@@ -233,7 +233,7 @@ impl MachineState {
|
|||||||
let tr = self.tr;
|
let tr = self.tr;
|
||||||
let val = self.trail[tr - 1];
|
let val = self.trail[tr - 1];
|
||||||
self.trail[i] = val;
|
self.trail[i] = val;
|
||||||
self.tr -= 1; // NEW.
|
self.tr -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -937,6 +937,9 @@ impl MachineState {
|
|||||||
fn throw_exception(&mut self, hcv: Vec<HeapCellValue>) {
|
fn throw_exception(&mut self, hcv: Vec<HeapCellValue>) {
|
||||||
let h = self.heap.h;
|
let h = self.heap.h;
|
||||||
|
|
||||||
|
self.ball.0 = 0;
|
||||||
|
self.ball.1.truncate(0);
|
||||||
|
|
||||||
self.registers[1] = Addr::HeapCell(h);
|
self.registers[1] = Addr::HeapCell(h);
|
||||||
|
|
||||||
self.heap.append(hcv);
|
self.heap.append(hcv);
|
||||||
@@ -1219,8 +1222,12 @@ impl MachineState {
|
|||||||
self.compare_numbers(cmp, n1, n2);
|
self.compare_numbers(cmp, n1, n2);
|
||||||
},
|
},
|
||||||
&BuiltInInstruction::DefaultSetCutPoint(r) => {
|
&BuiltInInstruction::DefaultSetCutPoint(r) => {
|
||||||
let mut default_cut_policy = DefaultCutPolicy {};
|
let mut cut_policy = DefaultCutPolicy {};
|
||||||
default_cut_policy.cut(self, r);
|
cut_policy.cut(self, r);
|
||||||
|
},
|
||||||
|
&BuiltInInstruction::DefaultRetryMeElse(o) => {
|
||||||
|
let mut call_policy = DefaultCallPolicy {};
|
||||||
|
try_or_fail!(self, call_policy.retry_me_else(self, o));
|
||||||
},
|
},
|
||||||
&BuiltInInstruction::DefaultTrustMe => {
|
&BuiltInInstruction::DefaultTrustMe => {
|
||||||
let mut call_policy = DefaultCallPolicy {};
|
let mut call_policy = DefaultCallPolicy {};
|
||||||
|
|||||||
@@ -663,6 +663,12 @@ macro_rules! default_set_cp {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! default_retry_me_else {
|
||||||
|
($o:expr) => (
|
||||||
|
Line::BuiltIn(BuiltInInstruction::DefaultRetryMeElse($o))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! default_trust_me {
|
macro_rules! default_trust_me {
|
||||||
() => (
|
() => (
|
||||||
Line::BuiltIn(BuiltInInstruction::DefaultTrustMe)
|
Line::BuiltIn(BuiltInInstruction::DefaultTrustMe)
|
||||||
|
|||||||
@@ -1393,6 +1393,8 @@ fn test_queries_on_builtins()
|
|||||||
|
|
||||||
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),display(S+G>B)), B=3, !), 100, R).",
|
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),display(S+G>B)), B=3, !), 100, R).",
|
||||||
[["G = 2", "B = 3", "R = !", "S = 1"]]);
|
[["G = 2", "B = 3", "R = !", "S = 1"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),display(S+G>B)), B=3, !), 10, R).",
|
||||||
|
[["S = _1", "G = _4", "B = _14", "R = inference_limit_exceeded"]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user