[][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<Context>, unit: Arc<Unit>) -> Self[src]

Construct a new runestick virtual machine.

pub const fn new_with_stack(
    context: Arc<Context>,
    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<Context>, 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][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<Context>[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 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 execute<A, N>(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 = Arc::new(Context::with_default_modules()?);
    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 call<A, N>(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 StrongMut<T> or StrongRef<T> this call will panic as we are trying to free the metadata relatedc to the reference.

pub async fn async_call<A, N>(
    __arg0: 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 StrongMut<T> or StrongRef<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

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> 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.