pub struct Stack { /* private fields */ }
Expand description
The stack of the virtual machine, where all values are stored.
Implementations§
Source§impl Stack
impl Stack
Sourcepub fn at(&self, addr: InstAddress) -> &Value
pub fn at(&self, addr: InstAddress) -> &Value
Access the value at the given frame offset.
§Examples
use rune::vm_try;
use rune::Module;
use rune::runtime::{Output, Stack, VmResult, InstAddress};
fn add_one(stack: &mut Stack, addr: InstAddress, args: usize, out: Output) -> VmResult<()> {
let value = vm_try!(stack.at(addr).as_integer::<i64>());
out.store(stack, value + 1);
VmResult::Ok(())
}
Sourcepub fn at_mut(&mut self, addr: InstAddress) -> Result<&mut Value, StackError>
pub fn at_mut(&mut self, addr: InstAddress) -> Result<&mut Value, StackError>
Get a value mutable at the given index from the stack bottom.
§Examples
use rune::vm_try;
use rune::Module;
use rune::runtime::{Output, Stack, VmResult, InstAddress};
fn add_one(stack: &mut Stack, addr: InstAddress, args: usize, out: Output) -> VmResult<()> {
let mut value = vm_try!(stack.at_mut(addr));
let number = vm_try!(value.as_integer::<i64>());
*value = vm_try!(rune::to_value(number + 1));
out.store(stack, ());
VmResult::Ok(())
}
Sourcepub fn slice_at(
&self,
addr: InstAddress,
len: usize,
) -> Result<&[Value], SliceError>
pub fn slice_at( &self, addr: InstAddress, len: usize, ) -> Result<&[Value], SliceError>
Get the slice at the given address with the given length.
§Examples
use rune::vm_try;
use rune::Module;
use rune::runtime::{Output, Stack, ToValue, VmResult, InstAddress};
fn sum(stack: &mut Stack, addr: InstAddress, args: usize, out: Output) -> VmResult<()> {
let mut number = 0;
for value in vm_try!(stack.slice_at(addr, args)) {
number += vm_try!(value.as_integer::<i64>());
}
out.store(stack, number);
VmResult::Ok(())
}
Sourcepub fn slice_at_mut(
&mut self,
addr: InstAddress,
len: usize,
) -> Result<&mut [Value], SliceError>
pub fn slice_at_mut( &mut self, addr: InstAddress, len: usize, ) -> Result<&mut [Value], SliceError>
Get the mutable slice at the given address with the given length.
§Examples
use rune::vm_try;
use rune::Module;
use rune::runtime::{Output, Stack, VmResult, InstAddress};
fn sum(stack: &mut Stack, addr: InstAddress, args: usize, out: Output) -> VmResult<()> {
for value in vm_try!(stack.slice_at_mut(addr, args)) {
let number = vm_try!(value.as_integer::<i64>());
*value = vm_try!(rune::to_value(number + 1));
}
out.store(stack, ());
VmResult::Ok(())
}
Trait Implementations§
Source§impl Memory for Stack
impl Memory for Stack
Source§fn slice_at(
&self,
addr: InstAddress,
len: usize,
) -> Result<&[Value], SliceError>
fn slice_at( &self, addr: InstAddress, len: usize, ) -> Result<&[Value], SliceError>
Get the slice at the given address with the given length. Read more
Source§fn slice_at_mut(
&mut self,
addr: InstAddress,
len: usize,
) -> Result<&mut [Value], SliceError>
fn slice_at_mut( &mut self, addr: InstAddress, len: usize, ) -> Result<&mut [Value], SliceError>
Access the given slice mutably. Read more
Source§fn at_mut(&mut self, addr: InstAddress) -> Result<&mut Value, StackError>
fn at_mut(&mut self, addr: InstAddress) -> Result<&mut Value, StackError>
Get a value mutable at the given index from the stack bottom. Read more
Source§fn array_at<const N: usize>(
&self,
addr: InstAddress,
) -> Result<[&Value; N], SliceError>where
Self: Sized,
fn array_at<const N: usize>(
&self,
addr: InstAddress,
) -> Result<[&Value; N], SliceError>where
Self: Sized,
Get the slice at the given address with the given static length.
Source§impl TryFromIteratorIn<Value, Global> for Stack
impl TryFromIteratorIn<Value, Global> for Stack
Source§fn try_from_iter_in<T: IntoIterator<Item = Value>>(
iter: T,
alloc: Global,
) -> Result<Self>
fn try_from_iter_in<T: IntoIterator<Item = Value>>( iter: T, alloc: Global, ) -> Result<Self>
Creates a value from an iterator within an allocator.
Auto Trait Implementations§
impl Freeze for Stack
impl !RefUnwindSafe for Stack
impl !Send for Stack
impl !Sync for Stack
impl Unpin for Stack
impl !UnwindSafe for Stack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, U> TryFromIterator<T> for Uwhere
U: TryFromIteratorIn<T, Global>,
impl<T, U> TryFromIterator<T> for Uwhere
U: TryFromIteratorIn<T, Global>,
Source§fn try_from_iter<I>(iter: I) -> Result<U, Error>where
I: IntoIterator<Item = T>,
fn try_from_iter<I>(iter: I) -> Result<U, Error>where
I: IntoIterator<Item = T>,
Creates a value from an iterator within an allocator.