slvm::vm

Struct GVm

Source
pub struct GVm<ENV> {
Show 17 fields interner: Interner, heap: Option<Heap>, stack: *mut Value, registers: *mut Value, globals: Globals, buitins: Vec<CallFunc<ENV>>, this_fn: Option<Value>, on_error: Option<Value>, err_frame: Option<CallFrame>, stack_top: usize, k_stack_top: Option<usize>, stack_max: usize, ip_ptr: *const u8, current_ip_ptr: *const u8, callframe_id: usize, defers: Vec<Value>, env: ENV,
}

Fields§

§interner: Interner§heap: Option<Heap>§stack: *mut Value§registers: *mut Value§globals: Globals§buitins: Vec<CallFunc<ENV>>§this_fn: Option<Value>§on_error: Option<Value>§err_frame: Option<CallFrame>§stack_top: usize§k_stack_top: Option<usize>§stack_max: usize§ip_ptr: *const u8§current_ip_ptr: *const u8§callframe_id: usize§defers: Vec<Value>§env: ENV

Implementations§

Source§

impl<ENV> GVm<ENV>

Source

pub(super) fn list(&mut self, wide: bool) -> VMResult<()>

Source

pub(super) fn append(&mut self, wide: bool) -> VMResult<()>

Source

pub(super) fn xar(&mut self, wide: bool) -> VMResult<()>

Source

pub(super) fn xdr(&mut self, wide: bool) -> VMResult<()>

Source§

impl<ENV> GVm<ENV>

Source

pub fn clear_err_frame(&mut self)

Source

pub fn err_frame(&self) -> &Option<CallFrame>

Source

pub fn get_registers(&self, start: usize, end: usize) -> &[Value]

Source

pub fn get_current_registers(&self) -> &[Value]

Source

pub fn get_stack(&self, idx: usize) -> Value

Source

pub fn stack_max(&self) -> usize

Source

pub fn get_interned(&self, i: Interned) -> &'static str

Source

pub fn intern_static(&mut self, string: &'static str) -> Interned

Source

pub fn intern(&mut self, string: &str) -> Interned

Source

pub fn get_if_interned(&self, string: &str) -> Option<Interned>

Source

pub fn set_global(&mut self, slot: u32, value: Value)

Source

pub fn reserve_global(&mut self) -> u32

Source

pub fn get_call_stack(&self) -> CallStackIter<'_, ENV>

Source

pub fn sizeof_heap_object() -> usize

Source

pub fn alloc_pair(&mut self, car: Value, cdr: Value) -> Value

Source

pub fn alloc_pair_ro(&mut self, car: Value, cdr: Value) -> Value

Source

pub fn alloc_string(&mut self, s: String) -> Value

Source

pub fn alloc_string_ro(&mut self, s: String) -> Value

Source

pub fn alloc_char(&mut self, ch: &str) -> Value

Source

pub fn alloc_vector(&mut self, v: Vec<Value>) -> Value

Source

pub fn alloc_vector_ro(&mut self, v: Vec<Value>) -> Value

Source

pub fn alloc_map(&mut self, map: VMHashMap) -> Value

Source

pub fn alloc_map_ro(&mut self, map: VMHashMap) -> Value

Source

pub fn alloc_list_ro(&mut self, v: Vec<Value>) -> Value

Source

pub fn alloc_bytes(&mut self, v: Vec<u8>) -> Value

Source

pub fn alloc_lambda(&mut self, l: Arc<Chunk>) -> Value

Source

pub fn alloc_closure(&mut self, l: Arc<Chunk>, v: Vec<Handle>) -> Value

Source

pub fn alloc_continuation(&mut self, k: Continuation) -> Value

Source

pub fn alloc_callframe(&mut self, frame: CallFrame) -> Value

Source

pub fn alloc_value(&mut self, val: Value) -> Value

Allocate a Value on the heap. Moving a value to the heap is useful for captured variable for instance.

Source

pub fn alloc_error(&mut self, err: Error) -> Value

Allocate an Error on the heap.

Source

pub fn alloc_io(&mut self, io: HeapIo) -> Value

Allocate a Value on the heap. Moving a value to the heap is useful for captured variable for instance.

Source

pub fn heap_immutable(&mut self, val: Value)

Source

pub fn heap_sticky(&mut self, val: Value)

Source

pub fn heap_unsticky(&mut self, val: Value)

Source

pub fn pause_gc(&mut self)

Pause garbage collection. Each pause_gc must have an unpause_gc before GC resumes (it is a counter that must be 0).

Source

pub fn unpause_gc(&mut self)

UnPause garbage collection. Each pause_gc must have an unpause_gc before GC resumes (it is a counter that must be 0).

Source

pub fn get_heap_property(&self, key_val: Value, prop: &str) -> Option<Value>

Source

pub fn set_heap_property(&mut self, key_val: Value, prop: &str, value: Value)

Source

pub fn get_heap_property_interned( &self, key_val: Value, prop: Interned, ) -> Option<Value>

Source

pub fn set_heap_property_interned( &mut self, key_val: Value, prop: Interned, value: Value, )

Source

pub fn get_global_property(&self, global: u32, prop: Interned) -> Option<Value>

Source

pub fn set_global_property(&mut self, global: u32, prop: Interned, value: Value)

Source

pub fn get_global(&self, idx: u32) -> Value

Source

pub fn get_string(&self, handle: Handle) -> &str

Source

pub fn get_string_mut(&mut self, handle: Handle) -> VMResult<&mut String>

Source

pub fn get_vector(&self, handle: Handle) -> &[Value]

Source

pub fn get_vector_mut(&mut self, handle: Handle) -> VMResult<&mut Vec<Value>>

Source

pub fn get_map(&self, handle: Handle) -> &VMHashMap

Source

pub fn get_map_mut(&mut self, handle: Handle) -> VMResult<&mut VMHashMap>

Source

pub fn get_bytes(&self, handle: Handle) -> &[u8]

Source

pub fn get_pair(&self, handle: Handle) -> (Value, Value)

Source

pub fn get_pair_mut( &mut self, handle: Handle, ) -> VMResult<(&mut Value, &mut Value)>

Source

pub fn get_pair_mut_override( &mut self, handle: Handle, ) -> (&mut Value, &mut Value)

Source

pub fn get_lambda(&self, handle: Handle) -> Arc<Chunk>

Source

pub fn get_closure(&self, handle: Handle) -> (Arc<Chunk>, &[Handle])

Source

pub fn get_continuation(&self, handle: Handle) -> &Continuation

Source

pub fn get_callframe(&self, handle: Handle) -> &CallFrame

Source

pub fn get_value(&self, handle: Handle) -> Value

Source

pub fn get_value_mut(&mut self, handle: Handle) -> &mut Value

Source

pub fn get_error(&self, handle: Handle) -> Error

Source

pub fn get_io(&self, handle: Handle) -> &HeapIo

Source

pub fn new_upval(&mut self, val: Value) -> Value

Source

pub fn call_frame(&self) -> Option<&CallFrame>

Source

pub fn make_err(&mut self, key: &'static str, data: Value) -> Value

Source

pub(super) fn call_frame_idx(&self, idx: usize) -> Option<&CallFrame>

Source

pub(super) fn copy_frame_defers(&mut self)

Source

fn mark_roots(&mut self, heap: &mut Heap) -> VMResult<()>

Source§

impl<ENV> GVm<ENV>

Source

pub(crate) fn setup_rest( &mut self, chunk: &Arc<Chunk>, first_reg: u16, num_args: u16, ) -> (usize, Value)

Setup the rest (&) arguments for a callable.

Source

fn k_unshared_stack( &self, stack_top: usize, k: &Continuation, ) -> Option<(usize, &Vec<Value>)>

Source

fn k_defers(&self, k: &Continuation) -> Option<usize>

Source

pub(crate) fn make_call_frame( &mut self, chunk: Arc<Chunk>, called: Value, with_defers: bool, ) -> CallFrame

Build a call frame to be placed on the stack before transferring to a new chunk.

Source

fn finish_special_call( &mut self, chunk: Arc<Chunk>, tail_call: bool, first_reg: u16, res: Value, ) -> Arc<Chunk>

Source

pub fn make_call( &mut self, lambda: Value, chunk: Arc<Chunk>, first_reg: u16, num_args: u16, tail_call: bool, ) -> Result<Arc<Chunk>, (VMError, Arc<Chunk>)>

Main function to match and execute anything that is callable.

Source

fn clear_opts(&mut self, l: &Chunk, first_reg: u16, num_args: u16)

Clear out the unused optional regs. Will clear working set to avoid writing to globals or closures by accident.

Source§

impl<ENV> GVm<ENV>

Source

pub(crate) fn call_map( &mut self, handle: Handle, first_reg: u16, num_args: u16, ) -> VMResult<Value>

Source

pub(crate) fn call_vector( &mut self, handle: Handle, first_reg: u16, num_args: u16, ) -> VMResult<Value>

Source

pub(crate) fn call_list( &mut self, head: Value, first_reg: u16, num_args: u16, ) -> VMResult<Value>

Source§

impl<ENV> GVm<ENV>

Source

fn map_destructure(&mut self, decodes: (u16, u16, u16)) -> VMResult<()>

Source

fn get_line(&self, wide: bool, chunk: &Chunk) -> Option<u32>

Source

fn get_string_idx(&mut self, val: Value, i: u16) -> VMResult<Value>

Source

fn get(&mut self, wide: bool) -> VMResult<()>

Source

fn set_data(&mut self, wide: bool) -> VMResult<()>

Source

fn tail_builtin_exit(&self, lambda: Value) -> bool

If we are tail calling a builtin with no call frame then exit loop early. Need to check this for some lambda -> builtin tail calls so SRET does not execute and munge the return.

Source

fn inc_val(&mut self, wide: bool) -> VMResult<()>

Implementation of the INC bytecode.

Source

fn dec_val(&mut self, wide: bool) -> VMResult<()>

Implementation of the DEC bytecode.

Source

pub(super) fn exec_loop( &mut self, chunk: Arc<Chunk>, skip_init: bool, ) -> Result<(), (VMError, Arc<Chunk>)>

Source§

impl GVm<()>

Source

pub fn new() -> Self

Source§

impl<ENV> GVm<ENV>

Source

pub fn new_with_env(env: ENV) -> Self

Source

pub fn this_fn(&self) -> Option<Value>

Source

pub fn stack(&self, idx: usize) -> Value

Source

pub fn stack_mut(&mut self, idx: usize) -> &mut Value

Source

pub fn stack_slice(&self) -> &[Value]

Source

pub fn stack_slice_mut(&mut self) -> &mut [Value]

Source

pub fn register(&self, idx: usize) -> Value

Return the register for idx.

Source

pub fn register_slice<'b>(&self) -> &'b [Value]

Source

pub fn register_int(&self, idx: usize) -> VMResult<i64>

Return the int representation of register idx or error if not an integral type.

Source

pub fn register_unref(&self, idx: usize) -> Value

Return the current register for idx, if it is stored on heap then dereference it first.

Source

pub fn register_mut<'b>(&self, idx: usize) -> &'b mut Value

Source

pub fn env(&self) -> &ENV

Source

pub fn env_mut(&mut self) -> &mut ENV

Source

fn heap(&self) -> &Heap

Source

fn heap_mut(&mut self) -> &mut Heap

Source

fn make_registers(&mut self)

Set the internal registers pointer, do this when the registers start position changes.

Source

fn mk_str(&mut self, reg1: u16, reg2: u16) -> VMResult<Value>

Source

fn is_identical(&self, reg1: u16, reg2: u16) -> VMResult<Value>

Source

pub fn add_builtin(&mut self, func: CallFuncSig<ENV>) -> Value

Source

pub fn get_builtin(&self, idx: u32) -> &CallFuncSig<ENV>

Return the builtin function at idx. Note, will panic if idx is not a valid builtin index.

Source

pub fn is_equal_pair(&self, val1: Value, val2: Value) -> VMResult<Value>

Source

fn is_equal(&self, reg1: u16, reg2: u16) -> VMResult<Value>

test if the operands are = (more lenient than identical)

Source

fn save_state(&mut self) -> VmState

Return the current VM state (for re-entrant VM calls).

Source

fn restore_state(&mut self, state: &mut VmState)

Restore saved VM state (for cleaning up after re-entrant VM calls).

Source

pub fn do_call( &mut self, chunk: Arc<Chunk>, params: &[Value], caps: Option<&[Handle]>, ) -> VMResult<Value>

Runs a lambda. Will save and restore the VM state even on error, chunk is expected to be a callable with params and any captures (closure) in caps. This is useful for macro expansion, eval and things like that. It can be safely used while the VM is currently executing bytecode.

Source

pub fn execute(&mut self, chunk: Arc<Chunk>) -> VMResult<Value>

Executes chunk. Will save the current VM state and restore on success or leave it on error. This allows a debugger to work with the “broken” image.

Source

pub fn reset(&mut self)

Reset the VM to default settings. Useful for cleaning up if you want to abort an execute() that errored out.

Source

fn execute2(&mut self, chunk: Arc<Chunk>) -> VMResult<()>

Trait Implementations§

Source§

impl Default for GVm<()>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<ENV> Freeze for GVm<ENV>
where ENV: Freeze,

§

impl<ENV> RefUnwindSafe for GVm<ENV>
where ENV: RefUnwindSafe,

§

impl<ENV> !Send for GVm<ENV>

§

impl<ENV> !Sync for GVm<ENV>

§

impl<ENV> Unpin for GVm<ENV>
where ENV: Unpin,

§

impl<ENV> UnwindSafe for GVm<ENV>
where ENV: UnwindSafe,

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.