[][src]Struct runestick::Vm

pub struct Vm { /* fields omitted */ }

A stack which references variables indirectly from a slab.

Implementations

impl Vm[src]

pub const fn new(context: Arc<RuntimeContext>, unit: Arc<Unit>) -> Self[src]

Construct a new runestick virtual machine.

pub const fn new_with_stack(
    context: Arc<RuntimeContext>,
    unit: Arc<Unit>,
    stack: Stack
) -> Self
[src]

Construct a new runestick virtual machine.

pub fn complete(self) -> Result<Value, VmError>[src]

Run the given vm to completion.

If any async instructions are encountered, this will error.

pub async fn async_complete(self) -> Result<Value, VmError>[src]

Run the given vm to completion with support for async functions.

pub fn is_same(&self, context: &Arc<RuntimeContext>, unit: &Arc<Unit>) -> bool[src]

Test if the virtual machine is the same context and unit as specified.

pub fn set_ip(&mut self, ip: usize)[src]

Set the current instruction pointer.

pub fn call_frames(&self) -> &[CallFrame]

Notable traits for &'_ mut [u8]

impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
[src]

Get the stack.

pub fn stack(&self) -> &Stack[src]

Get the stack.

pub fn stack_mut(&mut self) -> &mut Stack[src]

Get the stack mutably.

pub fn context(&self) -> &Arc<RuntimeContext>[src]

Access the context related to the virtual machine.

pub fn unit(&self) -> &Arc<Unit>[src]

Access the underlying unit of the virtual machine.

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

Access the current instruction pointer.

pub fn clear(&mut self)[src]

Reset this virtual machine, freeing all memory used.

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

Modify the current instruction pointer.

pub fn execute<A, N>(
    mut self: Self,
    name: N,
    args: A
) -> Result<VmExecution, VmError> where
    N: IntoTypeHash,
    A: Args
[src]

Call the function identified by the given name.

Computing the function hash from the name can be a bit costly, so it's worth noting that it can be precalculated:

use runestick::{Hash, Item};

let name = Hash::type_hash(&["main"]);

Examples

use runestick::{Context, Unit, FromValue, Source};
use std::sync::Arc;

fn main() -> runestick::Result<()> {
    let context = Context::with_default_modules()?;
    let context = Arc::new(context.runtime());
    let unit = Arc::new(Unit::default());
    // NB: normally the unit would be created by compiling some source,
    // and since this one is empty it won't do anything.

    let vm = runestick::Vm::new(context, unit);

    let output = vm.execute(&["main"], (33i64,))?.complete()?;
    let output = i64::from_value(output)?;

    println!("output: {}", output);
    Ok(())
}

pub fn send_execute<A, N>(
    mut self: Self,
    name: N,
    args: A
) -> Result<VmSendExecution, VmError> where
    N: IntoTypeHash,
    A: Send + Args
[src]

An execute variant that returns an execution which implements Send, allowing it to be sent and executed on a different thread.

This is accomplished by preventing values escaping from being non-exclusively sent with the execution or escaping the execution. We only support encoding arguments which themselves are Send.

pub fn call<A, N>(mut self: Self, name: N, args: A) -> Result<Value, VmError> where
    N: IntoTypeHash,
    A: GuardedArgs
[src]

Call the given function immediately, returning the produced value.

This function permits for using references since it doesn't defer its execution.

Panics

If any of the arguments passed in are references, and that references is captured somewhere in the call as Mut<T> or Ref<T> this call will panic as we are trying to free the metadata relatedc to the reference.

pub async fn async_call<A, N>(self, name: N, args: A) -> Result<Value, VmError> where
    N: IntoTypeHash,
    A: GuardedArgs
[src]

Call the given function immediately asynchronously, returning the produced value.

This function permits for using references since it doesn't defer its execution.

Panics

If any of the arguments passed in are references, and that references is captured somewhere in the call as Mut<T> or Ref<T> this call will panic as we are trying to free the metadata relatedc to the reference.

Trait Implementations

impl Clone for Vm[src]

impl Debug for Vm[src]

Auto Trait Implementations

impl !RefUnwindSafe for Vm[src]

impl !Send for Vm[src]

impl !Sync for Vm[src]

impl Unpin for Vm[src]

impl !UnwindSafe for Vm[src]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.