pub struct Vm { /* private fields */ }Expand description
A stack which references variables indirectly from a slab.
Implementations§
Source§impl Vm
impl Vm
Sourcepub fn modify_ip(&mut self, offset: isize) -> Result<(), VmError>
pub fn modify_ip(&mut self, offset: isize) -> Result<(), VmError>
Modify the current instruction pointer.
Sourcepub fn iter_stack_debug(
&self,
) -> impl Iterator<Item = (ValuePtr, Result<ValueRef<'_>, StackError>)> + '_
pub fn iter_stack_debug( &self, ) -> impl Iterator<Item = (ValuePtr, Result<ValueRef<'_>, StackError>)> + '_
Iterate over the stack, producing the value associated with each stack item.
Sourcepub fn call_function<'a, A, T, I>(
&'a mut self,
context: &'a Context,
unit: &'a CompilationUnit,
name: I,
args: A,
) -> Result<Task<'a, T>, VmError>
pub fn call_function<'a, A, T, I>( &'a mut self, context: &'a Context, unit: &'a CompilationUnit, name: I, args: A, ) -> Result<Task<'a, T>, VmError>
Call the given function in the given compilation unit.
Sourcepub fn run<'a, T>(
&'a mut self,
context: &'a Context,
unit: &'a CompilationUnit,
) -> Task<'a, T>where
T: FromValue,
pub fn run<'a, T>(
&'a mut self,
context: &'a Context,
unit: &'a CompilationUnit,
) -> Task<'a, T>where
T: FromValue,
Run the given program on the virtual machine.
Sourcepub fn push(&mut self, value: ValuePtr)
pub fn push(&mut self, value: ValuePtr)
Push an unmanaged reference.
The reference count of the value being referenced won’t be modified.
Sourcepub fn pop(&mut self) -> Result<ValuePtr, StackError>
pub fn pop(&mut self) -> Result<ValuePtr, StackError>
Pop a reference to a value from the stack.
Sourcepub fn external_allocate<T>(&mut self, value: T) -> ValuePtrwhere
T: Any,
pub fn external_allocate<T>(&mut self, value: T) -> ValuePtrwhere
T: Any,
Allocate and insert an external and return its reference.
This will leak memory unless the reference is pushed onto the stack to be managed.
Sourcepub unsafe fn external_allocate_ptr<T>(&mut self, value: *const T) -> ValuePtrwhere
T: Any,
pub unsafe fn external_allocate_ptr<T>(&mut self, value: *const T) -> ValuePtrwhere
T: Any,
Sourcepub unsafe fn external_allocate_mut_ptr<T>(&mut self, value: *mut T) -> ValuePtrwhere
T: Any,
pub unsafe fn external_allocate_mut_ptr<T>(&mut self, value: *mut T) -> ValuePtrwhere
T: Any,
Sourcepub fn string_allocate(&mut self, value: String) -> ValuePtr
pub fn string_allocate(&mut self, value: String) -> ValuePtr
Allocate a value and return its ptr.
This operation can leak memory unless the returned slot is pushed onto the stack.
Newly allocated items already have a refcount of 1. And should be pushed on the stack using [push], rather than [push.
Sourcepub fn string_ref(&self, slot: Slot) -> Result<Ref<'_, String>, StackError>
pub fn string_ref(&self, slot: Slot) -> Result<Ref<'_, String>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn string_clone(&self, slot: Slot) -> Result<String, StackError>
pub fn string_clone(&self, slot: Slot) -> Result<String, StackError>
Get a cloned value from the given slot.
Sourcepub fn string_mut(&self, slot: Slot) -> Result<Mut<'_, String>, StackError>
pub fn string_mut(&self, slot: Slot) -> Result<Mut<'_, String>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn string_take(&mut self, slot: Slot) -> Result<String, StackError>
pub fn string_take(&mut self, slot: Slot) -> Result<String, StackError>
Take the value at the given slot.
After taking the value, the caller is responsible for deallocating it.
Sourcepub fn array_allocate(&mut self, value: Vec<ValuePtr>) -> ValuePtr
pub fn array_allocate(&mut self, value: Vec<ValuePtr>) -> ValuePtr
Allocate a value and return its ptr.
This operation can leak memory unless the returned slot is pushed onto the stack.
Newly allocated items already have a refcount of 1. And should be pushed on the stack using [push], rather than [push.
Sourcepub fn array_ref(
&self,
slot: Slot,
) -> Result<Ref<'_, Vec<ValuePtr>>, StackError>
pub fn array_ref( &self, slot: Slot, ) -> Result<Ref<'_, Vec<ValuePtr>>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn array_clone(&self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>
pub fn array_clone(&self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>
Get a cloned value from the given slot.
Sourcepub fn array_mut(
&self,
slot: Slot,
) -> Result<Mut<'_, Vec<ValuePtr>>, StackError>
pub fn array_mut( &self, slot: Slot, ) -> Result<Mut<'_, Vec<ValuePtr>>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn array_take(&mut self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>
pub fn array_take(&mut self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>
Take the value at the given slot.
After taking the value, the caller is responsible for deallocating it.
Sourcepub fn object_allocate(&mut self, value: HashMap<String, ValuePtr>) -> ValuePtr
pub fn object_allocate(&mut self, value: HashMap<String, ValuePtr>) -> ValuePtr
Allocate a value and return its ptr.
This operation can leak memory unless the returned slot is pushed onto the stack.
Newly allocated items already have a refcount of 1. And should be pushed on the stack using [push], rather than [push.
Sourcepub fn object_ref(
&self,
slot: Slot,
) -> Result<Ref<'_, HashMap<String, ValuePtr>>, StackError>
pub fn object_ref( &self, slot: Slot, ) -> Result<Ref<'_, HashMap<String, ValuePtr>>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn object_clone(
&self,
slot: Slot,
) -> Result<HashMap<String, ValuePtr>, StackError>
pub fn object_clone( &self, slot: Slot, ) -> Result<HashMap<String, ValuePtr>, StackError>
Get a cloned value from the given slot.
Sourcepub fn object_mut(
&self,
slot: Slot,
) -> Result<Mut<'_, HashMap<String, ValuePtr>>, StackError>
pub fn object_mut( &self, slot: Slot, ) -> Result<Mut<'_, HashMap<String, ValuePtr>>, StackError>
Get a reference of the value at the given slot.
Sourcepub fn object_take(
&mut self,
slot: Slot,
) -> Result<HashMap<String, ValuePtr>, StackError>
pub fn object_take( &mut self, slot: Slot, ) -> Result<HashMap<String, ValuePtr>, StackError>
Take the value at the given slot.
After taking the value, the caller is responsible for deallocating it.
Sourcepub fn external_ref<T>(&self, slot: Slot) -> Result<Ref<'_, T>, StackError>where
T: Any,
pub fn external_ref<T>(&self, slot: Slot) -> Result<Ref<'_, T>, StackError>where
T: Any,
Get a reference of the external value of the given type and the given slot.
Sourcepub fn external_mut<T>(&self, slot: Slot) -> Result<Mut<'_, T>, StackError>where
T: Any,
pub fn external_mut<T>(&self, slot: Slot) -> Result<Mut<'_, T>, StackError>where
T: Any,
Get a mutable reference of the external value of the given type and the given slot.
Mark the given value as mutably used, preventing it from being used again.
Sourcepub fn external_clone<T: Clone + Any>(
&self,
slot: Slot,
) -> Result<T, StackError>
pub fn external_clone<T: Clone + Any>( &self, slot: Slot, ) -> Result<T, StackError>
Get a clone of the given external.
Sourcepub fn external_take<T>(&mut self, slot: Slot) -> Result<T, StackError>where
T: Any,
pub fn external_take<T>(&mut self, slot: Slot) -> Result<T, StackError>where
T: Any,
Take an external value from the virtual machine by its slot.
Sourcepub fn external_ref_dyn(&self, slot: Slot) -> Result<Ref<'_, Any>, StackError>
pub fn external_ref_dyn(&self, slot: Slot) -> Result<Ref<'_, Any>, StackError>
Get a reference of the external value of the given type and the given slot.
Sourcepub fn external_take_dyn(&mut self, slot: Slot) -> Result<Any, StackError>
pub fn external_take_dyn(&mut self, slot: Slot) -> Result<Any, StackError>
Take an external value by dyn, assuming you have exlusive access to it.
Sourcepub fn slot_type_name(&self, slot: Slot) -> Result<&'static str, StackError>
pub fn slot_type_name(&self, slot: Slot) -> Result<&'static str, StackError>
Access the type name of the slot.
Sourcepub fn slot_type_id(&self, slot: Slot) -> Result<TypeId, StackError>
pub fn slot_type_id(&self, slot: Slot) -> Result<TypeId, StackError>
Access the type id of the slot.
Sourcepub fn value_take(&mut self, value: ValuePtr) -> Result<Value, StackError>
pub fn value_take(&mut self, value: ValuePtr) -> Result<Value, StackError>
Convert a value reference into an owned value.
Sourcepub fn value_ref(&self, value: ValuePtr) -> Result<ValueRef<'_>, StackError>
pub fn value_ref(&self, value: ValuePtr) -> Result<ValueRef<'_>, StackError>
Convert the given ptr into a type-erase ValueRef.
Sourcepub fn value_array_ref(
&self,
values: &[ValuePtr],
) -> Result<Vec<ValueRef<'_>>, StackError>
pub fn value_array_ref( &self, values: &[ValuePtr], ) -> Result<Vec<ValueRef<'_>>, StackError>
Convert the given value pointers into an array.
Sourcepub fn value_object_ref(
&self,
object: &HashMap<String, ValuePtr>,
) -> Result<HashMap<String, ValueRef<'_>>, StackError>
pub fn value_object_ref( &self, object: &HashMap<String, ValuePtr>, ) -> Result<HashMap<String, ValueRef<'_>>, StackError>
Convert the given value pointers into an array.