pub struct VM {
ip: usize,
stack: Vec<Value>,
scopes: Vec<Scope>,
frames: Vec<CallFrame>,
current_frame: Option<usize>,
}
Expand description
Virtual Machine that executes bytecode
Fields§
§ip: usize
Instruction pointer
stack: Vec<Value>
Stack for values
scopes: Vec<Scope>
Stack of scopes, with global scope at index 0
frames: Vec<CallFrame>
Call frames for function calls
current_frame: Option<usize>
Index of the current call frame
Implementations§
Source§impl VM
impl VM
Sourcefn register_native_functions(&mut self)
fn register_native_functions(&mut self)
Registers built-in functions
Sourcefn define_native(
&mut self,
name: &str,
arity: u8,
function: fn(&[Value]) -> Result<Value, String>,
)
fn define_native( &mut self, name: &str, arity: u8, function: fn(&[Value]) -> Result<Value, String>, )
Defines a native (built-in) function
§Arguments
name
- Name of the native functionarity
- Number of parametersfunction
- The Rust function implementing this native function
Sourcefn get_variable(&self, name: &str) -> Option<&Value>
fn get_variable(&self, name: &str) -> Option<&Value>
Helper method to find a variable in any scope (from innermost to outermost)
Sourcefn set_variable(&mut self, name: String, value: Value)
fn set_variable(&mut self, name: String, value: Value)
Helper method to set a variable (creates in current scope or updates existing)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VM
impl RefUnwindSafe for VM
impl Send for VM
impl Sync for VM
impl Unpin for VM
impl UnwindSafe for VM
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