From 37e34c5209e48624d5e272c5b1dcf2bea7fdc1d3 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 31 Jan 2022 21:24:19 -0700 Subject: [PATCH] reset instruction pointers with calls, make HCPrinter::range_from safe (#1233) --- src/heap_print.rs | 2 +- src/machine/dispatch.rs | 4 ++++ src/machine/machine_state.rs | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/heap_print.rs b/src/heap_print.rs index af9503df..40afdbfc 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -376,7 +376,7 @@ impl HCValueOutputter for PrinterOutputter { } fn range_from(&self, index: RangeFrom) -> &str { - &self.contents.as_str()[index] + &self.contents.as_str().get(index).unwrap_or("") } } diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 4c02ea8b..8663a407 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -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 => { diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index 27a35884..5d8e591d 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -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 { -- 2.54.0