From 1ce5a52dc0f5701800d496605ad3d20cbd0d967f Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:51:39 +0100 Subject: [PATCH] feat(interpreter): expose mutable access methods on stack and memory (#1219) * feat(interpreter): allow mutable stack access * feat(interpreter): allow mutable memory access * chore: inline --- crates/interpreter/src/interpreter/shared_memory.rs | 2 +- crates/interpreter/src/interpreter/stack.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/interpreter/src/interpreter/shared_memory.rs b/crates/interpreter/src/interpreter/shared_memory.rs index b330412418..c49cc319ed 100644 --- a/crates/interpreter/src/interpreter/shared_memory.rs +++ b/crates/interpreter/src/interpreter/shared_memory.rs @@ -296,7 +296,7 @@ impl SharedMemory { /// Returns a mutable reference to the memory of the current context. #[inline] - fn context_memory_mut(&mut self) -> &mut [u8] { + pub fn context_memory_mut(&mut self) -> &mut [u8] { let buf_len = self.buffer.len(); // SAFETY: access bounded by buffer length unsafe { self.buffer.get_unchecked_mut(self.last_checkpoint..buf_len) } diff --git a/crates/interpreter/src/interpreter/stack.rs b/crates/interpreter/src/interpreter/stack.rs index 9692695cf2..2b2c9b6d7f 100644 --- a/crates/interpreter/src/interpreter/stack.rs +++ b/crates/interpreter/src/interpreter/stack.rs @@ -58,13 +58,19 @@ impl Stack { self.data.is_empty() } - /// Returns the underlying data of the stack. + /// Returns a reference to the underlying data buffer. #[inline] pub fn data(&self) -> &Vec { &self.data } - /// Consumes the stack and returns the underlying data. + /// Returns a mutable reference to the underlying data buffer. + #[inline] + pub fn data_mut(&mut self) -> &mut Vec { + &mut self.data + } + + /// Consumes the stack and returns the underlying data buffer. #[inline] pub fn into_data(self) -> Vec { self.data