]> Repositorios git - scryer-prolog.git/commitdiff
fix control construct bugs, iter indentation (#947)
authorMark <[email protected]>
Wed, 11 Oct 2023 18:41:45 +0000 (12:41 -0600)
committerMark <[email protected]>
Wed, 11 Oct 2023 18:41:45 +0000 (12:41 -0600)
src/heap_iter.rs
src/lib/builtins.pl
src/machine/unify.rs

index b8fd9dae5ed7057bf5251080dd8866b1fee71eab..d36855dafe980abe68cbb3e05b7f4e0c2f46c146 100644 (file)
@@ -86,22 +86,22 @@ impl<'a> EagerStackfulPreOrderHeapIter<'a> {
                     let arity = cell_as_atom_cell!(self.heap[s]).get_arity();
 
                     for idx in (s + 1 .. s + arity + 1).rev() {
-                       if self.heap[idx].get_mark_bit() != self.mark_phase {
+                                   if self.heap[idx].get_mark_bit() != self.mark_phase {
                             self.iter_stack.push(self.heap[idx]);
                             self.heap[idx].set_mark_bit(self.mark_phase);
-                       }
+                                   }
                     }
                 }
                 (HeapCellValueTag::Lis, l) => {
-                   if self.heap[l+1].get_mark_bit() != self.mark_phase {
-                       self.iter_stack.push(self.heap[l+1]);
-                       self.heap[l+1].set_mark_bit(self.mark_phase);
-                   }
-
-                   if self.heap[l].get_mark_bit() != self.mark_phase {
-                       self.iter_stack.push(self.heap[l]);
-                       self.heap[l].set_mark_bit(self.mark_phase);
-                   }
+                           if self.heap[l+1].get_mark_bit() != self.mark_phase {
+                                   self.iter_stack.push(self.heap[l+1]);
+                                   self.heap[l+1].set_mark_bit(self.mark_phase);
+                           }
+
+                           if self.heap[l].get_mark_bit() != self.mark_phase {
+                                   self.iter_stack.push(self.heap[l]);
+                                   self.heap[l].set_mark_bit(self.mark_phase);
+                           }
                 }
                 (HeapCellValueTag::AttrVar | HeapCellValueTag::Var, h) => {
                     let var_value = self.heap[h];
index b7b60df9aa5ae9f1318588be8dc3cf50f29ad707..34f607f64ab084b50263c5339de12a859c25f140 100644 (file)
@@ -328,6 +328,9 @@ staggered_sc(_, G) :- call(G).
 % to reason about the programs. Also restricts the ability to run the program with alternative execution strategies
 !.
 
+:- non_counted_backtracking get_cp/1.
+get_cp(B) :- '$get_cp'(B).
+
 :- non_counted_backtracking set_cp/1.
 
 set_cp(B) :- '$set_cp'(B).
@@ -359,24 +362,21 @@ cont_list_goal(Conts, '$call'(builtins:dispatch_call_list(Conts))).
 
 :- non_counted_backtracking dispatch_prep/3.
 
-dispatch_prep(Gs, B, [Cont|Conts]) :-
+dispatch_prep(Gs, B, Conts) :-
     (  callable(Gs) ->
        strip_module(Gs, M, Gs0),
        (  nonvar(Gs0),
-          dispatch_prep_(Gs0, B, [Cont|Conts]) ->
+          dispatch_prep_(Gs0, B, Conts) ->
           true
        ;  Gs0 == ! ->
-          Cont = '$call'(builtins:set_cp(B)),
-          Conts = []
+          Conts = ['$call'(builtins:set_cp(B))]
        ;  nonvar(Gs0),
           \+ callable(Gs0) ->
           throw(dispatch_prep_error)
-       ;  Cont = Gs,
-          Conts = []
+       ;  Conts = [Gs]
        )
     ;  var(Gs) ->
-       Cont = Gs,
-       Conts = []
+       Conts = [Gs]
     ;  throw(dispatch_prep_error)
     ).
 
@@ -387,20 +387,32 @@ dispatch_prep_((G1, G2), B, [Cont|Conts]) :-
     dispatch_prep(G1, B, IConts1),
     cont_list_goal(IConts1, Cont),
     dispatch_prep(G2, B, Conts).
-dispatch_prep_((G1 ; G2), B, [Cont|Conts]) :-
-    dispatch_prep(G1, B, IConts0),
+dispatch_prep_((G1 ; G2), B, Conts) :-
+    (  nonvar(G1) ->
+       (  G1 = (G11 -> G12) ->
+          dispatch_prep(G11, B, IConts2),
+          dispatch_prep(G12, B, IConts3),
+          cont_list_goal(IConts2, Cont2),
+          cont_list_goal(IConts3, Cont3),
+          Cont0 = '$call'(builtins:staggered_if_then(Cont2, Cont3))
+       ;  dispatch_prep(G1, B, IConts0),
+          dispatch_prep(G2, B, IConts1),
+          cont_list_goal(IConts0, Cont0)
+       )
+    ;  dispatch_prep(G1, B1, IConts0),
+       cont_list_goal(IConts0, Cont0)
+    ),
     dispatch_prep(G2, B, IConts1),
     cont_list_goal(IConts0, Cont0),
     cont_list_goal(IConts1, Cont1),
-    Cont = '$call'(builtins:staggered_sc(Cont0, Cont1)),
-    Conts = [].
-dispatch_prep_((G1 -> G2), B, [Cont|Conts]) :-
-    dispatch_prep(G1, B, IConts1),
+    Conts = ['$call'(builtins:staggered_sc(Cont0, Cont1))].
+dispatch_prep_((G1 -> G2), B, Conts) :-
+    dispatch_prep(G1, B1, IConts1),
     dispatch_prep(G2, B, IConts2),
     cont_list_goal(IConts1, Cont1),
     cont_list_goal(IConts2, Cont2),
-    Cont = '$call'(builtins:staggered_if_then(Cont1, Cont2)),
-    Conts = [].
+    Conts = ['$call'(builtins:get_cp(B1)),
+             '$call'(builtins:staggered_if_then(Cont1, Cont2))].
 
 
 :- non_counted_backtracking dispatch_call_list/1.
index f9c031891ae657fb931ec4d9b208885af9485a35..104c515746763d3b66b3b85958df444b9b87b6d8 100644 (file)
@@ -691,6 +691,9 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
                     (HeapCellValueTag::Cons, ptr_1) => {
                         Self::unify_constant(self, ptr_1, d2);
                     }
+                    (HeapCellValueTag::CutPoint, n1) => {
+                        Self::unify_fixnum(self, n1, d2);
+                    }
                     _ => {
                         unreachable!();
                     }