Skip to content

Commit

Permalink
feat(interpreter): expose mutable access methods on stack and memory (b…
Browse files Browse the repository at this point in the history
…luealloy#1219)

* feat(interpreter): allow mutable stack access

* feat(interpreter): allow mutable memory access

* chore: inline
  • Loading branch information
DaniPopes authored Mar 22, 2024
1 parent 09df19c commit 1ce5a52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/interpreter/src/interpreter/shared_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
10 changes: 8 additions & 2 deletions crates/interpreter/src/interpreter/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U256> {
&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<U256> {
&mut self.data
}

/// Consumes the stack and returns the underlying data buffer.
#[inline]
pub fn into_data(self) -> Vec<U256> {
self.data
Expand Down

0 comments on commit 1ce5a52

Please sign in to comment.