]> Repositorios git - scryer-prolog.git/commitdiff
pop AND stack frames after unwinding the trail (#250)
authorMark Thom <[email protected]>
Wed, 4 Dec 2019 06:11:57 +0000 (23:11 -0700)
committerMark Thom <[email protected]>
Wed, 4 Dec 2019 06:11:57 +0000 (23:11 -0700)
src/prolog/machine/machine_state.rs
src/prolog/machine/machine_state_impl.rs

index deb79e0049588f49737aca9c5a82cf916cca3e62..fddfb264626322c3428902eaf9da145cf32f18d8 100644 (file)
@@ -510,8 +510,8 @@ pub(crate) trait CallPolicy: Any {
             machine_st.registers[i] = machine_st.or_stack[b][i].clone();
         }
 
-        machine_st.pop_stack_frames();
-
+        let old_e = machine_st.e;
+        
         machine_st.num_of_args = n;
         machine_st.e = machine_st.or_stack[b].e;
         machine_st.cp = machine_st.or_stack[b].cp.clone();
@@ -522,6 +522,8 @@ pub(crate) trait CallPolicy: Any {
         machine_st.unwind_trail(old_tr, curr_tr);
         machine_st.tr = machine_st.or_stack[b].tr;
 
+        machine_st.pop_stack_frames(old_e);
+
         machine_st.trail.truncate(machine_st.tr);
 
         let old_pstr_tr = machine_st.or_stack[b].pstr_tr;
@@ -558,7 +560,7 @@ pub(crate) trait CallPolicy: Any {
             machine_st.registers[i] = machine_st.or_stack[b][i].clone();
         }
 
-        machine_st.pop_stack_frames();
+        let old_e = machine_st.e;
 
         machine_st.num_of_args = n;
         machine_st.e = machine_st.or_stack[b].e;
@@ -570,6 +572,8 @@ pub(crate) trait CallPolicy: Any {
         machine_st.unwind_trail(old_tr, curr_tr);
         machine_st.tr = machine_st.or_stack[b].tr;
 
+        machine_st.pop_stack_frames(old_e);
+
         machine_st.trail.truncate(machine_st.tr);
 
         let old_pstr_tr = machine_st.or_stack[b].pstr_tr;
index c98a80ed6750d5de2a24dd5c250003f264a5340f..63ace01f2c7caee48518a857d601ebb539af9b79 100644 (file)
@@ -3172,9 +3172,9 @@ impl MachineState {
         self.p += 1;
     }
 
-    pub(super) fn pop_stack_frames(&mut self) {
-       if self.and_stack.len() > self.e {
-            let and_gi = self.and_stack[self.e].global_index;
+    pub(super) fn pop_stack_frames(&mut self, e: usize) {
+       if self.and_stack.len() > e {
+            let and_gi = self.and_stack[e].global_index;
             let or_gi = self
                 .or_stack
                 .top()
@@ -3182,7 +3182,7 @@ impl MachineState {
                 .unwrap_or(0);
 
             if and_gi > or_gi {
-                self.and_stack.truncate(self.e + 1);
+                self.and_stack.truncate(e + 1);
             }
         }
     }