BasicExecutionNode

Struct BasicExecutionNode 

Source
pub struct BasicExecutionNode { /* private fields */ }
Expand description

Executes TIS-100 assembly code. Once a Program has been set on the node, the node may be executed using alternating calls of step and sync.

§Example

use tis_100::core::Port::*;
use tis_100::io::IoBus;
use tis_100::node::{Node, BasicExecutionNode};
use tis_100::parse::parse_program;

let src = "MOV UP ACC\nADD 1\nMOV ACC DOWN\n";
let prog = parse_program(src).unwrap();
let mut bus = IoBus::new();
let mut node = BasicExecutionNode::with_program(prog);

bus.connect_half(0, 1, DOWN)
    .connect_half(1, 2, DOWN)
    .view(0).write(DOWN, 1);
bus.commit();

for _ in 0..3 {
    {
        let mut view = bus.view(1);
        node.step(&mut view);
        node.sync(&mut view);
    }

    bus.commit();
}

assert_eq!(bus.view(2).read(UP), Some(2));

Implementations§

Source§

impl BasicExecutionNode

Source

pub fn new() -> BasicExecutionNode

Construct a new, empty BasicExecutionNode.

Source

pub fn with_program(program: Program) -> BasicExecutionNode

Construct a new BasicExecutionNode and initialize it with the given program.

Source

pub fn set_program(&mut self, program: Program)

Set the program on a BasicExecutionNode.

Source

pub fn get_mode(&self) -> &Mode

Trait Implementations§

Source§

impl Debug for BasicExecutionNode

Source§

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

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

impl Node for BasicExecutionNode

Source§

fn step(&mut self, io: &mut IoBusView<'_>)

Execute the next instruction, if possible.

Source§

fn sync(&mut self, io: &mut IoBusView<'_>)

Synchronize this node with the IoBus. If the node was blocked on a write, and that value was read during the previous cycle, then this will clear the block and allow the node to proceed with execution.

Source§

fn is_stalled(&self) -> bool

An execution node is stalled if it is waiting on an IO action or if it is not executing.

Auto Trait Implementations§

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.