]> Repositorios git - scryer-prolog.git/commitdiff
add fixes, further test cases.
authorMark Thom <[email protected]>
Mon, 26 Feb 2018 05:38:28 +0000 (22:38 -0700)
committerMark Thom <[email protected]>
Mon, 26 Feb 2018 05:38:28 +0000 (22:38 -0700)
src/prolog/ast.rs
src/prolog/builtins.rs
src/prolog/io.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/macros.rs
src/tests.rs

index ac52c74b2b166d7bcc949bf6bb7e31d538e28aa6..1b719c2b056cdf1f98910f2214f64b8512fa58dd 100644 (file)
@@ -951,8 +951,9 @@ pub enum ArithmeticInstruction {
 
 pub enum BuiltInInstruction {
     CleanUpBlock,
-    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
+    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),    
     DefaultTrustMe,
+    DefaultSetCutPoint(RegType),
     DynamicCompareNumber(CompareNumberQT),
     EraseBall,
     Fail,
index 649fc3aedf497508d5b55f1bb818dddf9a76b967..feff8fa4a39db9de838de5221960a2e9f7c979be 100644 (file)
@@ -119,7 +119,7 @@ fn get_builtins() -> Code {
                unify_variable!(temp_v!(1)),
                unify_variable!(temp_v!(2))],
          set_cp!(temp_v!(3)),
-         goto_execute!(83, 3),
+         goto_execute!(77, 3),
          retry_me_else!(4),
          fact![get_constant!(atom!("!"), temp_v!(1)),
                get_constant!(atom!("!"), temp_v!(2))],
@@ -142,7 +142,7 @@ fn get_builtins() -> Code {
                 put_unsafe_value!(1, 2),
                 put_value!(perm_v!(3), 3)],
          deallocate!(),
-         goto_execute!(83, 3),
+         goto_execute!(77, 3),
          retry_me_else!(10),
          allocate!(2),
          get_level!(perm_v!(2)),
@@ -475,7 +475,7 @@ fn get_builtins() -> Code {
          query![put_var!(perm_v!(1), 1)],
          get_ball!(),
          get_level!(perm_v!(2)),
-         set_cp!(perm_v!(2)),
+         default_set_cp!(perm_v!(2)),
          goto_call!(342, 0), // goto run_cleaners_with_handling/0, 342.
          query![put_unsafe_value!(1, 1)],
          deallocate!(),
@@ -494,7 +494,7 @@ fn get_builtins() -> Code {
                 put_var!(temp_v!(4), 2),
                 put_constant!(Level::Shallow, atom!("true"), temp_v!(3))],
          goto_call!(5, 3), // goto catch/3, 5.
-         set_cp!(perm_v!(1)),
+         default_set_cp!(perm_v!(1)),
          deallocate!(),
          goto_execute!(342, 0), // goto run_cleaners_with_handling/0, 342.
          trust_me!(),
@@ -506,7 +506,7 @@ fn get_builtins() -> Code {
          get_cleaner_call!(),
          query![put_value!(perm_v!(2), 1)],
          call_n!(1),
-         set_cp!(perm_v!(1)),
+         default_set_cp!(perm_v!(1)),
          deallocate!(),
          goto_execute!(354, 0), // goto run_cleaners_without_handling/0, 354.
          trust_me!(),
index 8418d88ec1908bd2e2cff39e6ffc7e1156263560..a91c8603a59f2d786af752f04a3b776e785b4e8a 100644 (file)
@@ -205,6 +205,8 @@ impl fmt::Display for BuiltInInstruction {
         match self {
             &BuiltInInstruction::CleanUpBlock =>
                 write!(f, "clean_up_block"),
+            &BuiltInInstruction::DefaultSetCutPoint(r) =>
+                write!(f, "default_set_cp {}", r),
             &BuiltInInstruction::DefaultTrustMe =>
                 write!(f, "default_trust_me"),
             &BuiltInInstruction::InstallInferenceCounter(r1, r2, r3) =>
index 5d5059bf64641678472149850036a7d5df27c95f..4cc71ee7bf2bbb15800b2914dbf6f01888231a9b 100644 (file)
@@ -1218,6 +1218,10 @@ impl MachineState {
 
                 self.compare_numbers(cmp, n1, n2);
             },
+            &BuiltInInstruction::DefaultSetCutPoint(r) => {
+                let mut default_cut_policy = DefaultCutPolicy {};
+                default_cut_policy.cut(self, r);
+            },
             &BuiltInInstruction::DefaultTrustMe => {
                 let mut call_policy = DefaultCallPolicy {};
                 try_or_fail!(self, call_policy.trust_me(self));
@@ -1472,7 +1476,9 @@ impl MachineState {
 
                 self.p += 1;
             },
-            &BuiltInInstruction::SetCutPoint(r) => {
+            &BuiltInInstruction::SetCutPoint(r) =>
+                cut_policy.cut(self, r),
+            /*{
                 let addr = self.store(self.deref(self[r].clone()));
 
                 match addr {
@@ -1487,7 +1493,7 @@ impl MachineState {
                     },
                     _ => self.fail = true
                 };
-            },
+            },*/
             &BuiltInInstruction::CleanUpBlock => {
                 let nb = self.store(self.deref(self[temp_v!(1)].clone()));
 
index 4dc1e785477e16155c097ea860b766ff1628adca..d06aa922505febe3157741d1908d14c91686400a 100644 (file)
@@ -657,6 +657,12 @@ macro_rules! inference_level {
     )
 }
 
+macro_rules! default_set_cp {
+    ($r:expr) => (
+        Line::BuiltIn(BuiltInInstruction::DefaultSetCutPoint($r))
+    )
+}
+
 macro_rules! default_trust_me {
     () => (
         Line::BuiltIn(BuiltInInstruction::DefaultTrustMe)
index b6b227df9ecaf290b97363b1d21f3c71e48702b4..d5f316ceb7aefa85e05ec3096da03e2b36a992f6 100644 (file)
@@ -1387,6 +1387,12 @@ fn test_queries_on_builtins()
     assert_prolog_success!(&mut wam, "?- [X,Y,Z] =@= [V,W,Z].");
     assert_prolog_success!(&mut wam, "?- [X,Y,X] =@= [V,W,V].");
     assert_prolog_success!(&mut wam, "?- g(B) = B, g(A) = A, A =@= B.");
+
+    assert_prolog_success!(&mut wam, "?- call(((G = 2 ; fail), B=3, !)).",
+                           [["G = 2", "B = 3"]]);
+
+    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"]]);
 }
 
 #[test]