stack_assembly/memory.rs
1use std::fmt;
2
3use crate::Value;
4
5/// # A linear memory, freely addressable per word
6///
7/// The memory can be accessed from a script through the `read` and `write`
8/// operators.
9///
10/// Aside from this, the stack is an important communication channel between
11/// script and host. Please refer to [`Eval`]'s [`memory`] field for more
12/// information on that.
13///
14/// [`Eval`]: crate::Eval
15/// [`memory`]: struct.Eval.html#structfield.memory
16pub struct Memory {
17 /// # The values in the memory
18 pub values: Vec<Value>,
19}
20
21impl fmt::Debug for Memory {
22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23 // This is not perfect, but it's way more compact than the derived
24 // implementation.
25
26 let mut values = self.values.iter().peekable();
27
28 write!(f, "[")?;
29
30 while let Some(value) = values.next() {
31 write!(f, "{value:?}")?;
32
33 if values.peek().is_some() {
34 write!(f, ", ")?;
35 }
36 }
37
38 write!(f, "]")?;
39
40 Ok(())
41 }
42}