]> Repositorios git - scryer-prolog.git/commitdiff
reset instruction pointers with calls, make HCPrinter::range_from safe (#1233)
authorMark Thom <[email protected]>
Tue, 1 Feb 2022 04:24:19 +0000 (21:24 -0700)
committerMark Thom <[email protected]>
Tue, 1 Feb 2022 04:24:19 +0000 (21:24 -0700)
src/heap_print.rs
src/machine/dispatch.rs
src/machine/machine_state.rs

index af9503df04ae9a78381866052a6bd4b96c0ded26..40afdbfcadd0f5d3955e4045a28a3b13174842e6 100644 (file)
@@ -376,7 +376,7 @@ impl HCValueOutputter for PrinterOutputter {
     }
 
     fn range_from(&self, index: RangeFrom<usize>) -> &str {
-        &self.contents.as_str()[index]
+        &self.contents.as_str().get(index).unwrap_or("")
     }
 }
 
index 4c02ea8bfae24d84ac36bace64eae34ba5e0bdb2..8663a407870e70626f3fa9aa5f2e9f77e04574fd 100644 (file)
@@ -962,6 +962,8 @@ impl Machine {
                     match self.find_living_dynamic_else(p) {
                         Some((p, next_i)) => {
                             self.machine_st.p = p;
+                            self.machine_st.oip = 0;
+                            self.machine_st.iip = 0;
 
                             match self.machine_st.dynamic_mode {
                                 FirstOrNext::First if next_i == 0 => {
@@ -1044,6 +1046,8 @@ impl Machine {
                     match self.find_living_dynamic_else(p) {
                         Some((p, next_i)) => {
                             self.machine_st.p = p;
+                            self.machine_st.oip = 0;
+                            self.machine_st.iip = 0;
 
                             match self.machine_st.dynamic_mode {
                                 FirstOrNext::First if next_i == 0 => {
index 27a358845b2c88150a26d7d6778c59fe30dc57fb..5d8e591d615fb5e8c3d50dc2dea8cb9394c95702 100644 (file)
@@ -439,15 +439,19 @@ impl MachineState {
     pub(super) fn call_at_index(&mut self, arity: usize, p: usize) {
         self.cp = self.p + 1;
         self.p = p;
+        self.oip = 0;
+        self.iip = 0;
         self.num_of_args = arity;
         self.b0 = self.b;
     }
 
     #[inline(always)]
     pub(super) fn execute_at_index(&mut self, arity: usize, p: usize) {
+        self.p = p;
+        self.oip = 0;
+        self.iip = 0;
         self.num_of_args = arity;
         self.b0 = self.b;
-        self.p = p;
     }
 
     pub fn read_term(&mut self, stream: Stream, indices: &mut IndexStore) -> CallResult {