]> Repositorios git - scryer-prolog.git/commitdiff
fix exception handling when thrown by throw_exception, and within setup_call_cleanup...
authorMark Thom <[email protected]>
Mon, 26 Feb 2018 06:43:37 +0000 (23:43 -0700)
committerMark Thom <[email protected]>
Mon, 26 Feb 2018 06:43:37 +0000 (23:43 -0700)
src/prolog/ast.rs
src/prolog/builtins.rs
src/prolog/io.rs
src/prolog/machine/machine_state.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/macros.rs
src/tests.rs

index 1b719c2b056cdf1f98910f2214f64b8512fa58dd..9721aea18b28974dd998b69d74bb9f26907f9b24 100644 (file)
@@ -951,7 +951,8 @@ pub enum ArithmeticInstruction {
 
 pub enum BuiltInInstruction {
     CleanUpBlock,
-    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),    
+    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
+    DefaultRetryMeElse(usize),
     DefaultTrustMe,
     DefaultSetCutPoint(RegType),
     DynamicCompareNumber(CompareNumberQT),
index feff8fa4a39db9de838de5221960a2e9f7c979be..2ad9fa705e7f936f54dc11418a98c0e80c3fbe93 100644 (file)
@@ -48,7 +48,7 @@ fn get_builtins() -> Code {
                 put_unsafe_value!(1, 2)],
          deallocate!(),
          goto_execute!(44, 2), //21: goto end_block/2.
-         trust_me!(),
+         default_trust_me!(),
          allocate!(3),
          fact![get_var_in_fact!(perm_v!(2), 2),
                get_var_in_fact!(perm_v!(1), 3)],
@@ -72,7 +72,7 @@ fn get_builtins() -> Code {
          query![put_value!(perm_v!(2), 1)],
          deallocate!(),
          execute_n!(1),
-         trust_me!(),
+         default_trust_me!(),
          unwind_stack!(),
          try_me_else!(9), // end_block/2, 44.
          allocate!(1),
@@ -83,7 +83,7 @@ fn get_builtins() -> Code {
          deallocate!(),
          reset_block!(),
          proceed!(),
-         trust_me!(), // 53.
+         default_trust_me!(), // 53.
          allocate!(0),
          query![get_var_in_query!(temp_v!(3), 1),
                 put_value!(temp_v!(2), 1)],
@@ -446,7 +446,7 @@ fn get_builtins() -> Code {
                               atom!("instantiation_error"),
                               temp_v!(1))],
          goto_execute!(59, 1),
-         trust_me!(),
+         default_trust_me!(),
          query![get_var_in_query!(temp_v!(4), 2),
                 put_value!(temp_v!(3), 2),
                 get_var_in_query!(temp_v!(5), 3),
@@ -468,7 +468,7 @@ fn get_builtins() -> Code {
                 put_value!(perm_v!(1), 2)],
          deallocate!(),
          check_cp_execute!(),
-         retry_me_else!(12),
+         default_retry_me_else!(12),
          allocate!(2),
          query![put_value!(temp_v!(3), 1)],
          reset_block!(),
@@ -480,7 +480,7 @@ fn get_builtins() -> Code {
          query![put_unsafe_value!(1, 1)],
          deallocate!(),
          goto_execute!(59, 1), // goto throw/1, 59.
-         trust_me!(),
+         default_trust_me!(),
          allocate!(0),
          goto_call!(354, 0), // goto run_cleaners_without_handling/0, 354.
          deallocate!(),
@@ -497,7 +497,7 @@ fn get_builtins() -> Code {
          default_set_cp!(perm_v!(1)),
          deallocate!(),
          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.
          try_me_else!(10), // run_cleaners_without_handling/1, 354.
          allocate!(2),
@@ -509,7 +509,7 @@ fn get_builtins() -> Code {
          default_set_cp!(perm_v!(1)),
          deallocate!(),
          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.
          allocate!(1), // sgc_on_success/2, 366.
          fact![get_var_in_fact!(perm_v!(1), 2)],
index a91c8603a59f2d786af752f04a3b776e785b4e8a..71139aeae102122543650f1b1ff5168592d7d42c 100644 (file)
@@ -207,6 +207,8 @@ impl fmt::Display for BuiltInInstruction {
                 write!(f, "clean_up_block"),
             &BuiltInInstruction::DefaultSetCutPoint(r) =>
                 write!(f, "default_set_cp {}", r),
+            &BuiltInInstruction::DefaultRetryMeElse(o) =>
+                write!(f, "default_retry_me_else {}", o),
             &BuiltInInstruction::DefaultTrustMe =>
                 write!(f, "default_trust_me"),
             &BuiltInInstruction::InstallInferenceCounter(r1, r2, r3) =>
index 55e5fcc88921a742b03fa07af44edbe8b3c34a82..b5f9838b2225d6d8353e1927986df605d4763ddc 100644 (file)
@@ -71,7 +71,7 @@ pub(super) struct DuplicateBallTerm<'a> {
 impl<'a> DuplicateBallTerm<'a> {
     pub(super) fn new(state: &'a mut MachineState) -> Self {
         let hb = state.heap.len();
-        DuplicateBallTerm { state: state, heap_boundary: hb }
+        DuplicateBallTerm { state, heap_boundary: hb }
     }
 }
 
index 4cc71ee7bf2bbb15800b2914dbf6f01888231a9b..7bb6be194c26cb57bcad654c345b4fe8d54148fc 100644 (file)
@@ -216,7 +216,7 @@ impl MachineState {
                         let tr = self.tr;
                         let val = self.trail[tr - 1];
                         self.trail[i] = val;
-                        self.tr -= 1; // NEW.
+                        self.tr -= 1;
                     },
                 Ref::StackCell(fr, _) => {
                     let b = self.b - 1;
@@ -233,7 +233,7 @@ impl MachineState {
                         let tr = self.tr;
                         let val = self.trail[tr - 1];
                         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>) {
         let h = self.heap.h;
 
+        self.ball.0 = 0;
+        self.ball.1.truncate(0);
+                
         self.registers[1] = Addr::HeapCell(h);
 
         self.heap.append(hcv);
@@ -1219,8 +1222,12 @@ impl MachineState {
                 self.compare_numbers(cmp, n1, n2);
             },
             &BuiltInInstruction::DefaultSetCutPoint(r) => {
-                let mut default_cut_policy = DefaultCutPolicy {};
-                default_cut_policy.cut(self, r);
+                let mut cut_policy = DefaultCutPolicy {};
+                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 => {
                 let mut call_policy = DefaultCallPolicy {};
index d06aa922505febe3157741d1908d14c91686400a..fd0b5ea613227b88e3c6297eb354f4982d1b5432 100644 (file)
@@ -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 {
     () => (
         Line::BuiltIn(BuiltInInstruction::DefaultTrustMe)
index d5f316ceb7aefa85e05ec3096da03e2b36a992f6..5b29072e54c4b8f2a6573afdd194f13235574f89 100644 (file)
@@ -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).",
                            [["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]