Memory

Struct Memory 

Source
pub struct Memory<'a> { /* private fields */ }
Expand description

A memory on a virtual machine.

Implementations§

Source§

impl<'a> Memory<'a>

Source

pub fn new(heap: &'a mut [Value]) -> Result<Self, Error>

Creates a memory.

Source

pub const fn code(&self) -> Cons

Returns a code.

Source

pub const fn set_code(&mut self, value: Cons)

Sets a code.

Source

pub const fn register(&self) -> Cons

Returns a register.

Source

pub const fn set_register(&mut self, value: Cons)

Sets a register.

Source

pub const fn stack(&self) -> Cons

Returns a stack.

Source

pub const fn set_stack(&mut self, value: Cons)

Sets a stack.

Source

pub fn boolean(&self, value: bool) -> Result<Cons, Error>

Returns a boolean value.

Source

pub fn null(&self) -> Result<Cons, Error>

Returns a null value.

Source

pub fn push(&mut self, value: Value) -> Result<(), Error>

Pushes a value to a stack.

Source

pub fn pop(&mut self) -> Result<Value, Error>

Pops a value from a stack.

Source

pub fn pop_many<const M: usize>(&mut self) -> Result<[Value; M], Error>

Pops values from a stack.

Source

pub fn pop_numbers<const M: usize>(&mut self) -> Result<[Number; M], Error>

Pops numbers from a stack.

Source

pub fn top(&self) -> Result<Value, Error>

Peeks a value at the top of a stack.

Source

pub fn set_top(&mut self, value: Value) -> Result<(), Error>

Sets a value at the top of a stack.

Source

pub fn cons(&mut self, car: Value, cdr: Cons) -> Result<Cons, Error>

Allocates a cons with a default tag of Type::Pair.

Source

pub fn allocate(&mut self, car: Value, cdr: Value) -> Result<Cons, Error>

Allocates a cons.

Source

pub const fn size(&self) -> usize

Returns a heap size.

Source

pub const fn allocation_index(&self) -> usize

Returns the current allocation index relative an allocation start index.

Source

pub const fn allocation_start(&self) -> usize

Returns an allocation start index.

Source

pub const fn allocation_end(&self) -> usize

Returns an allocation end index.

Source

pub fn car(&self, cons: Cons) -> Result<Value, Error>

Returns a value of a car field in a cons.

Source

pub fn cdr(&self, cons: Cons) -> Result<Value, Error>

Returns a value of a cdr field in a cons.

Source

pub fn car_value(&self, cons: Value) -> Result<Value, Error>

Returns a value of a car field in a value assumed as a cons.

Source

pub fn cdr_value(&self, cons: Value) -> Result<Value, Error>

Returns a value of a cdr field in a value assumed as a cons.

Source

pub fn set_car(&mut self, cons: Cons, value: Value) -> Result<(), Error>

Sets a value to a car field in a cons.

Source

pub fn set_cdr(&mut self, cons: Cons, value: Value) -> Result<(), Error>

Sets a value to a cdr field in a cons.

Source

pub fn set_raw_cdr(&mut self, cons: Cons, value: Value) -> Result<(), Error>

Sets a raw value to a cdr field in a cons overwriting its tag.

Source

pub fn set_car_value(&mut self, cons: Value, value: Value) -> Result<(), Error>

Sets a value to a car field in a value assumed as a cons.

Source

pub fn set_cdr_value(&mut self, cons: Value, value: Value) -> Result<(), Error>

Sets a value to a cdr field in a value assumed as a cons.

Source

pub fn tail(&self, list: Cons, index: usize) -> Result<Cons, Error>

Returns a tail of a list.

Source

pub fn build_string(&mut self, string: &str) -> Result<Cons, Error>

Builds a string.

Source

pub fn build_raw_string(&mut self, string: &str) -> Result<Cons, Error>

Builds a raw string.

Source

pub fn operate_top( &mut self, operate: impl Fn(&Self, Value) -> Result<Value, Error>, ) -> Result<(), Error>

Executes an operation against a value at the top of a stack.

Source

pub fn list_length(&self, list: Cons) -> Result<usize, Error>

Calculates a length of a list.

Source

pub fn operate_unary( &mut self, operate: impl Fn(Number) -> Number, ) -> Result<(), Error>

Executes an unary number operation.

Source

pub fn operate_binary( &mut self, operate: fn(Number, Number) -> Number, ) -> Result<(), Error>

Executes a binary number operation.

Source

pub fn collect_garbages(&mut self, cons: Option<&mut Cons>) -> Result<(), Error>

Collects garbage memory blocks.

Trait Implementations§

Source§

impl Display for Memory<'_>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Write for Memory<'_>

Source§

fn write_str(&mut self, string: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Memory<'a>

§

impl<'a> RefUnwindSafe for Memory<'a>

§

impl<'a> Send for Memory<'a>

§

impl<'a> Sync for Memory<'a>

§

impl<'a> Unpin for Memory<'a>

§

impl<'a> !UnwindSafe for Memory<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.