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: IoImplementations§
Source§impl Context
impl Context
pub fn new(mem: Memory) -> Self
pub fn with_io(mem: Memory, io: Io) -> Self
pub fn override_flow_control(&mut self)
Sourcepub fn get_mut_register(&mut self, op: &Op) -> &mut usize
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.
Sourcepub fn get_register(&self, op: &Op) -> usize
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.
Sourcepub fn read(&self, op: &Op) -> RtResult<usize>
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)?);
}
});Sourcepub fn as_address(&self, op: &Op) -> RtResult<usize>
pub fn as_address(&self, op: &Op) -> RtResult<usize>
§Panics
If op is not an address. To avoid this, check op using Op::is_address.
Sourcepub fn modify(&mut self, op: &Op, f: impl Fn(&mut usize)) -> RtResult
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: operandf: 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§
Auto Trait Implementations§
impl !RefUnwindSafe for Context
impl !UnwindSafe for Context
impl Freeze for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
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