pub struct Interpreter {
pub stack: Vec<StackValue>,
pub locals: Vec<StackValue>,
pub ip: usize,
pub call_stack: Vec<usize>,
}Expand description
A simple stack-based bytecode interpreter.
Fields§
§stack: Vec<StackValue>§locals: Vec<StackValue>§ip: usize§call_stack: Vec<usize>Implementations§
Source§impl Interpreter
impl Interpreter
Sourcepub fn push(&mut self, v: StackValue)
pub fn push(&mut self, v: StackValue)
Push a value onto the operand stack.
Sourcepub fn pop(&mut self) -> Option<StackValue>
pub fn pop(&mut self) -> Option<StackValue>
Pop a value from the operand stack.
Sourcepub fn peek(&self) -> Option<&StackValue>
pub fn peek(&self) -> Option<&StackValue>
Peek at the top of the operand stack without removing it.
Sourcepub fn execute_chunk(
&mut self,
chunk: &BytecodeChunk,
) -> Result<StackValue, String>
pub fn execute_chunk( &mut self, chunk: &BytecodeChunk, ) -> Result<StackValue, String>
Execute all opcodes in chunk and return the top-of-stack value.
Sourcepub fn execute_op(
&mut self,
op: &Opcode,
_chunk: &BytecodeChunk,
) -> Result<bool, String>
pub fn execute_op( &mut self, op: &Opcode, _chunk: &BytecodeChunk, ) -> Result<bool, String>
Execute a single opcode.
Returns Ok(true) to continue, Ok(false) to halt.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interpreter
impl RefUnwindSafe for Interpreter
impl Send for Interpreter
impl Sync for Interpreter
impl Unpin for Interpreter
impl UnsafeUnpin for Interpreter
impl UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more