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>
impl<ENV> GVm<ENV>
pub fn clear_err_frame(&mut self)
pub fn err_frame(&self) -> &Option<CallFrame>
pub fn get_registers(&self, start: usize, end: usize) -> &[Value]
pub fn get_current_registers(&self) -> &[Value]
pub fn get_stack(&self, idx: usize) -> Value
pub fn stack_max(&self) -> usize
pub fn get_interned(&self, i: Interned) -> &'static str
pub fn intern_static(&mut self, string: &'static str) -> Interned
pub fn intern(&mut self, string: &str) -> Interned
pub fn get_if_interned(&self, string: &str) -> Option<Interned>
pub fn set_global(&mut self, slot: u32, value: Value)
pub fn reserve_global(&mut self) -> u32
pub fn get_call_stack(&self) -> CallStackIter<'_, ENV> ⓘ
pub fn sizeof_heap_object() -> usize
pub fn alloc_pair(&mut self, car: Value, cdr: Value) -> Value
pub fn alloc_pair_ro(&mut self, car: Value, cdr: Value) -> Value
pub fn alloc_string(&mut self, s: String) -> Value
pub fn alloc_string_ro(&mut self, s: String) -> Value
pub fn alloc_char(&mut self, ch: &str) -> Value
pub fn alloc_vector(&mut self, v: Vec<Value>) -> Value
pub fn alloc_vector_ro(&mut self, v: Vec<Value>) -> Value
pub fn alloc_map(&mut self, map: VMHashMap) -> Value
pub fn alloc_map_ro(&mut self, map: VMHashMap) -> Value
pub fn alloc_list_ro(&mut self, v: Vec<Value>) -> Value
pub fn alloc_bytes(&mut self, v: Vec<u8>) -> Value
pub fn alloc_lambda(&mut self, l: Arc<Chunk>) -> Value
pub fn alloc_closure(&mut self, l: Arc<Chunk>, v: Vec<Handle>) -> Value
pub fn alloc_continuation(&mut self, k: Continuation) -> Value
pub fn alloc_callframe(&mut self, frame: CallFrame) -> Value
Sourcepub fn alloc_value(&mut self, val: Value) -> Value
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.
Sourcepub fn alloc_error(&mut self, err: Error) -> Value
pub fn alloc_error(&mut self, err: Error) -> Value
Allocate an Error on the heap.
Sourcepub fn alloc_io(&mut self, io: HeapIo) -> Value
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.
pub fn heap_immutable(&mut self, val: Value)
pub fn heap_sticky(&mut self, val: Value)
pub fn heap_unsticky(&mut self, val: Value)
Sourcepub fn pause_gc(&mut self)
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).
Sourcepub fn unpause_gc(&mut self)
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).
pub fn get_heap_property(&self, key_val: Value, prop: &str) -> Option<Value>
pub fn set_heap_property(&mut self, key_val: Value, prop: &str, value: Value)
pub fn get_heap_property_interned( &self, key_val: Value, prop: Interned, ) -> Option<Value>
pub fn set_heap_property_interned( &mut self, key_val: Value, prop: Interned, value: Value, )
pub fn get_global_property(&self, global: u32, prop: Interned) -> Option<Value>
pub fn set_global_property(&mut self, global: u32, prop: Interned, value: Value)
pub fn get_global(&self, idx: u32) -> Value
pub fn get_string(&self, handle: Handle) -> &str
pub fn get_string_mut(&mut self, handle: Handle) -> VMResult<&mut String>
pub fn get_vector(&self, handle: Handle) -> &[Value]
pub fn get_vector_mut(&mut self, handle: Handle) -> VMResult<&mut Vec<Value>>
pub fn get_map(&self, handle: Handle) -> &VMHashMap
pub fn get_map_mut(&mut self, handle: Handle) -> VMResult<&mut VMHashMap>
pub fn get_bytes(&self, handle: Handle) -> &[u8] ⓘ
pub fn get_pair(&self, handle: Handle) -> (Value, Value)
pub fn get_pair_mut( &mut self, handle: Handle, ) -> VMResult<(&mut Value, &mut Value)>
pub fn get_pair_mut_override( &mut self, handle: Handle, ) -> (&mut Value, &mut Value)
pub fn get_lambda(&self, handle: Handle) -> Arc<Chunk>
pub fn get_closure(&self, handle: Handle) -> (Arc<Chunk>, &[Handle])
pub fn get_continuation(&self, handle: Handle) -> &Continuation
pub fn get_callframe(&self, handle: Handle) -> &CallFrame
pub fn get_value(&self, handle: Handle) -> Value
pub fn get_value_mut(&mut self, handle: Handle) -> &mut Value
pub fn get_error(&self, handle: Handle) -> Error
pub fn get_io(&self, handle: Handle) -> &HeapIo ⓘ
pub fn new_upval(&mut self, val: Value) -> Value
pub fn call_frame(&self) -> Option<&CallFrame>
pub fn make_err(&mut self, key: &'static str, data: Value) -> Value
pub(super) fn call_frame_idx(&self, idx: usize) -> Option<&CallFrame>
pub(super) fn copy_frame_defers(&mut self)
fn mark_roots(&mut self, heap: &mut Heap) -> VMResult<()>
Source§impl<ENV> GVm<ENV>
impl<ENV> GVm<ENV>
Sourcepub(crate) fn setup_rest(
&mut self,
chunk: &Arc<Chunk>,
first_reg: u16,
num_args: u16,
) -> (usize, Value)
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.
fn k_defers(&self, k: &Continuation) -> Option<usize>
Sourcepub(crate) fn make_call_frame(
&mut self,
chunk: Arc<Chunk>,
called: Value,
with_defers: bool,
) -> CallFrame
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.
fn finish_special_call( &mut self, chunk: Arc<Chunk>, tail_call: bool, first_reg: u16, res: Value, ) -> Arc<Chunk>
Sourcepub 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>)>
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.
Sourcefn clear_opts(&mut self, l: &Chunk, first_reg: u16, num_args: u16)
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>
impl<ENV> GVm<ENV>
pub(crate) fn call_map( &mut self, handle: Handle, first_reg: u16, num_args: u16, ) -> VMResult<Value>
pub(crate) fn call_vector( &mut self, handle: Handle, first_reg: u16, num_args: u16, ) -> VMResult<Value>
pub(crate) fn call_list( &mut self, head: Value, first_reg: u16, num_args: u16, ) -> VMResult<Value>
Source§impl<ENV> GVm<ENV>
impl<ENV> GVm<ENV>
fn map_destructure(&mut self, decodes: (u16, u16, u16)) -> VMResult<()>
fn get_line(&self, wide: bool, chunk: &Chunk) -> Option<u32>
fn get_string_idx(&mut self, val: Value, i: u16) -> VMResult<Value>
fn get(&mut self, wide: bool) -> VMResult<()>
fn set_data(&mut self, wide: bool) -> VMResult<()>
Sourcefn tail_builtin_exit(&self, lambda: Value) -> bool
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.
pub(super) fn exec_loop( &mut self, chunk: Arc<Chunk>, skip_init: bool, ) -> Result<(), (VMError, Arc<Chunk>)>
Source§impl<ENV> GVm<ENV>
impl<ENV> GVm<ENV>
pub fn new_with_env(env: ENV) -> Self
pub fn this_fn(&self) -> Option<Value>
pub fn stack(&self, idx: usize) -> Value
pub fn stack_mut(&mut self, idx: usize) -> &mut Value
pub fn stack_slice(&self) -> &[Value]
pub fn stack_slice_mut(&mut self) -> &mut [Value]
pub fn register_slice<'b>(&self) -> &'b [Value]
Sourcepub fn register_int(&self, idx: usize) -> VMResult<i64>
pub fn register_int(&self, idx: usize) -> VMResult<i64>
Return the int representation of register idx or error if not an integral type.
Sourcepub fn register_unref(&self, idx: usize) -> Value
pub fn register_unref(&self, idx: usize) -> Value
Return the current register for idx, if it is stored on heap then dereference it first.
pub fn register_mut<'b>(&self, idx: usize) -> &'b mut Value
pub fn env(&self) -> &ENV
pub fn env_mut(&mut self) -> &mut ENV
fn heap(&self) -> &Heap
fn heap_mut(&mut self) -> &mut Heap
Sourcefn make_registers(&mut self)
fn make_registers(&mut self)
Set the internal registers pointer, do this when the registers start position changes.
fn mk_str(&mut self, reg1: u16, reg2: u16) -> VMResult<Value>
fn is_identical(&self, reg1: u16, reg2: u16) -> VMResult<Value>
pub fn add_builtin(&mut self, func: CallFuncSig<ENV>) -> Value
Sourcepub fn get_builtin(&self, idx: u32) -> &CallFuncSig<ENV>
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.
pub fn is_equal_pair(&self, val1: Value, val2: Value) -> VMResult<Value>
Sourcefn is_equal(&self, reg1: u16, reg2: u16) -> VMResult<Value>
fn is_equal(&self, reg1: u16, reg2: u16) -> VMResult<Value>
test if the operands are = (more lenient than identical)
Sourcefn save_state(&mut self) -> VmState
fn save_state(&mut self) -> VmState
Return the current VM state (for re-entrant VM calls).
Sourcefn restore_state(&mut self, state: &mut VmState)
fn restore_state(&mut self, state: &mut VmState)
Restore saved VM state (for cleaning up after re-entrant VM calls).
Sourcepub fn do_call(
&mut self,
chunk: Arc<Chunk>,
params: &[Value],
caps: Option<&[Handle]>,
) -> VMResult<Value>
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.
Sourcepub fn execute(&mut self, chunk: Arc<Chunk>) -> VMResult<Value>
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.
Sourcepub fn reset(&mut self)
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.