[][src]Struct stk::Vm

pub struct Vm { /* fields omitted */ }

A stack which references variables indirectly from a slab.

Implementations

impl Vm[src]

pub fn new() -> Self[src]

Construct a new stk virtual machine.

pub fn clear(&mut self)[src]

Reset this virtual machine, freeing all memory used.

pub fn ip(&self) -> usize[src]

Access the current instruction pointer.

pub fn modify_ip(&mut self, offset: isize) -> Result<(), VmError>[src]

Modify the current instruction pointer.

pub fn iter_stack_debug(
    &self
) -> impl Iterator<Item = (ValuePtr, Result<ValueRef, StackError>)> + '_
[src]

Iterate over the stack, producing the value associated with each stack item.

pub fn call_function<'a, A: 'a, T, I>(
    &'a mut self,
    context: &'a Context,
    unit: &'a CompilationUnit,
    name: I,
    args: A
) -> Result<Task<'a, T>, VmError> where
    I: IntoIterator,
    I::Item: AsRef<str>,
    A: IntoArgs,
    T: FromValue
[src]

Call the given function in the given compilation unit.

pub fn run<'a, T>(
    &'a mut self,
    context: &'a Context,
    unit: &'a CompilationUnit
) -> Task<'a, T> where
    T: FromValue
[src]

Run the given program on the virtual machine.

pub fn push(&mut self, value: ValuePtr)[src]

Push an unmanaged reference.

The reference count of the value being referenced won't be modified.

pub fn pop(&mut self) -> Result<ValuePtr, StackError>[src]

Pop a reference to a value from the stack.

pub fn external_allocate<T>(&mut self, value: T) -> ValuePtr where
    T: Any
[src]

Allocate and insert an external and return its reference.

This will leak memory unless the reference is pushed onto the stack to be managed.

pub unsafe fn external_allocate_ptr<T>(&mut self, value: *const T) -> ValuePtr where
    T: Any
[src]

Allocate an external slot for the given reference.

Safety

If the pointer was constructed from a reference, the reference passed in MUST NOT be used again until the VM has been cleared using clear since the VM is actively aliasing the reference for the duration of its life.

pub unsafe fn external_allocate_mut_ptr<T>(&mut self, value: *mut T) -> ValuePtr where
    T: Any
[src]

Allocate an external slot for the given mutable reference.

Safety

If the pointer was constructed from a reference, the reference passed in MUST NOT be used again until the VM has been cleared using clear since the VM is actively aliasing the reference for the duration of its life.

pub fn string_allocate(&mut self, value: String) -> ValuePtr[src]

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.

pub fn string_ref(&self, slot: Slot) -> Result<Ref<String>, StackError>[src]

Get a reference of the value at the given slot.

pub fn string_clone(&self, slot: Slot) -> Result<String, StackError>[src]

Get a cloned value from the given slot.

pub fn string_mut(&self, slot: Slot) -> Result<Mut<String>, StackError>[src]

Get a reference of the value at the given slot.

pub fn string_take(&mut self, slot: Slot) -> Result<String, StackError>[src]

Take the value at the given slot.

After taking the value, the caller is responsible for deallocating it.

pub fn array_allocate(&mut self, value: Vec<ValuePtr>) -> ValuePtr[src]

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.

pub fn array_ref(&self, slot: Slot) -> Result<Ref<Vec<ValuePtr>>, StackError>[src]

Get a reference of the value at the given slot.

pub fn array_clone(&self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>[src]

Get a cloned value from the given slot.

pub fn array_mut(&self, slot: Slot) -> Result<Mut<Vec<ValuePtr>>, StackError>[src]

Get a reference of the value at the given slot.

pub fn array_take(&mut self, slot: Slot) -> Result<Vec<ValuePtr>, StackError>[src]

Take the value at the given slot.

After taking the value, the caller is responsible for deallocating it.

pub fn object_allocate(&mut self, value: HashMap<String, ValuePtr>) -> ValuePtr[src]

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.

pub fn object_ref(
    &self,
    slot: Slot
) -> Result<Ref<HashMap<String, ValuePtr>>, StackError>
[src]

Get a reference of the value at the given slot.

pub fn object_clone(
    &self,
    slot: Slot
) -> Result<HashMap<String, ValuePtr>, StackError>
[src]

Get a cloned value from the given slot.

pub fn object_mut(
    &self,
    slot: Slot
) -> Result<Mut<HashMap<String, ValuePtr>>, StackError>
[src]

Get a reference of the value at the given slot.

pub fn object_take(
    &mut self,
    slot: Slot
) -> Result<HashMap<String, ValuePtr>, StackError>
[src]

Take the value at the given slot.

After taking the value, the caller is responsible for deallocating it.

pub fn external_ref<T>(&self, slot: Slot) -> Result<Ref<T>, StackError> where
    T: Any
[src]

Get a reference of the external value of the given type and the given slot.

pub fn external_mut<T>(&self, slot: Slot) -> Result<Mut<T>, StackError> where
    T: Any
[src]

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.

pub fn external_clone<T: Clone + Any>(
    &self,
    slot: Slot
) -> Result<T, StackError>
[src]

Get a clone of the given external.

pub fn external_take<T>(&mut self, slot: Slot) -> Result<T, StackError> where
    T: Any
[src]

Take an external value from the virtual machine by its slot.

pub fn external_ref_dyn(&self, slot: Slot) -> Result<Ref<Any>, StackError>[src]

Get a reference of the external value of the given type and the given slot.

pub fn external_take_dyn(&mut self, slot: Slot) -> Result<Any, StackError>[src]

Take an external value by dyn, assuming you have exlusive access to it.

pub fn slot_type_name(&self, slot: Slot) -> Result<&'static str, StackError>[src]

Access the type name of the slot.

pub fn slot_type_id(&self, slot: Slot) -> Result<TypeId, StackError>[src]

Access the type id of the slot.

pub fn value_take(&mut self, value: ValuePtr) -> Result<Value, StackError>[src]

Convert a value reference into an owned value.

pub fn value_ref(&self, value: ValuePtr) -> Result<ValueRef, StackError>[src]

Convert the given ptr into a type-erase ValueRef.

pub fn value_array_ref(
    &self,
    values: &[ValuePtr]
) -> Result<Vec<ValueRef>, StackError>
[src]

Convert the given value pointers into an array.

pub fn value_object_ref(
    &self,
    object: &HashMap<String, ValuePtr>
) -> Result<HashMap<String, ValueRef>, StackError>
[src]

Convert the given value pointers into an array.

pub async fn run_for<'_, '_, '_>(
    &'_ mut self,
    context: &'_ Context,
    unit: &'_ CompilationUnit,
    __arg3: Option<usize>
) -> Result<(), VmError>
[src]

Evaluate a single instruction.

Trait Implementations

impl Debug for Vm[src]

Auto Trait Implementations

impl !RefUnwindSafe for Vm

impl !Send for Vm

impl !Sync for Vm

impl Unpin for Vm

impl UnwindSafe for Vm

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,