Skip to main content

FramedInterpreter

Struct FramedInterpreter 

Source
pub struct FramedInterpreter {
    pub stack: Vec<StackValue>,
    pub locals: Vec<StackValue>,
    pub frames: Vec<CallFrame>,
    pub ip: usize,
    pub max_depth: usize,
}
Expand description

An interpreter that manages a proper call frame stack.

Fields§

§stack: Vec<StackValue>

The operand stack.

§locals: Vec<StackValue>

All local variables across all frames (flat layout).

§frames: Vec<CallFrame>

Frame stack (innermost at the back).

§ip: usize

Current instruction pointer.

§max_depth: usize

Maximum frame depth (0 = unlimited).

Implementations§

Source§

impl FramedInterpreter

Source

pub fn new() -> Self

Create a new framed interpreter.

Source

pub fn with_max_depth(self, d: usize) -> Self

Set the maximum call depth.

Source

pub fn push_frame( &mut self, return_ip: usize, fn_name: &str, ) -> Result<(), String>

Push a new call frame, saving return_ip and recording locals_base.

Source

pub fn pop_frame(&mut self) -> Option<usize>

Pop the top call frame and restore the instruction pointer.

Source

pub fn depth(&self) -> usize

Current call depth.

Source

pub fn frame(&self, depth: usize) -> Option<&CallFrame>

Get a frame by depth (0 = innermost).

Source

pub fn stack_trace(&self) -> String

Pretty-print the current call stack trace.

Source

pub fn reset(&mut self)

Reset the interpreter to a clean state.

Trait Implementations§

Source§

impl Default for FramedInterpreter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.