From: Mark Date: Wed, 11 Oct 2023 18:41:45 +0000 (-0600) Subject: fix control construct bugs, iter indentation (#947) X-Git-Tag: remove~34 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=1163d14ea1e71442255671776c2522de75b88028;p=scryer-prolog.git fix control construct bugs, iter indentation (#947) --- diff --git a/src/heap_iter.rs b/src/heap_iter.rs index b8fd9dae..d36855da 100644 --- a/src/heap_iter.rs +++ b/src/heap_iter.rs @@ -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]; diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index b7b60df9..34f607f6 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -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. diff --git a/src/machine/unify.rs b/src/machine/unify.rs index f9c03189..104c5157 100644 --- a/src/machine/unify.rs +++ b/src/machine/unify.rs @@ -691,6 +691,9 @@ pub(crate) trait Unifier: DerefMut { (HeapCellValueTag::Cons, ptr_1) => { Self::unify_constant(self, ptr_1, d2); } + (HeapCellValueTag::CutPoint, n1) => { + Self::unify_fixnum(self, n1, d2); + } _ => { unreachable!(); }