Struct cambridge_asm::exec::Context

source ·
pub struct Context {
    pub cmp: bool,
    pub mar: usize,
    pub acc: usize,
    pub ix: usize,
    pub flow_override_reg: bool,
    pub mem: Memory,
    pub ret: usize,
    pub gprs: [usize; 30],
    pub end: bool,
    pub io: Io,
}
Expand description

Tracks state of the registers and memory during execution

Fields§

§cmp: bool§mar: usize§acc: usize§ix: usize§flow_override_reg: bool§mem: Memory§ret: usize§gprs: [usize; 30]§end: bool§io: Io

Implementations§

source§

impl Context

source

pub fn new(mem: Memory) -> Self

source

pub fn with_io(mem: Memory, io: Io) -> Self

source

pub fn override_flow_control(&mut self)

source

pub fn get_mut_register(&mut self, op: &Op) -> &mut usize

Panics

If op is not a usize register. To avoid this, check op using Op::is_register.

source

pub fn get_register(&self, op: &Op) -> usize

Panics

If op is not a usize register. To avoid this, check op using Op::is_register.

source

pub fn read(&self, op: &Op) -> RtResult<usize>

Read the given operand from the context

Arguments
  • op:

returns: RtResult

Panics

If op is not usizeable. To avoid this, check op using Op::is_usizeable

Example
inst!(print (ctx, op) {
    if op.is_usizeable() {
        println!("{}", ctx.read(op)?);
    }
});
source

pub fn modify(&mut self, op: &Op, f: impl Fn(&mut usize)) -> RtResult

Modify the given operand in the context if it is writeable

Arguments
  • op: operand
  • f: closure to modify the value

returns: RtResult

Panics

If op is not writeable. To avoid this, check op using Op::is_read_write.

Example
inst!(double_inc (ctx, op) {
    if op.is_read_write() {
        ctx.modify(op, |val| *val += 2)?;
    }
});

Trait Implementations§

source§

impl Debug for Context

source§

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

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

impl Default for Context

source§

fn default() -> Context

Returns the “default value” for a type. Read more
source§

impl Display for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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.