osiris-process 0.3.1

A processor implementation.
Documentation
//! Exposes some structs to help track state in a processor.

use osiris_data::data::atomic::Word;
use osiris_data::data::composite::WordStack;
use osiris_data::data::identification::Address;

use crate::register::floating_point::Vector;
use crate::register::integral::Bank;

/// The state of an operation.
#[derive(Copy, Clone, Debug, Default)]
pub struct OperationState {
    /// Shall be used to store the result of an arithmetic operation.
    pub result: Word,
    /// Shall be used to implement a for-next logic.
    pub counter: Word,
    /// Shall be used to implement A <=> B comparison logic,
    pub compare: i64,
    /// Shall be used to signal an operation resulting with 0 or an empty set,
    pub flag_zero: bool,
    /// Shall be used to signal an operation resulting with a numeric overflow,
    pub flag_overflow: bool,
}

impl OperationState {
    /// Reset the whole operation state
    pub fn reset(&mut self) {
        self.reset_arithmetic();
        self.counter = Word::default();
        self.compare = 0;
    }
    /// Reset the arithmetic operation state.
    /// 
    /// Fields set :
    /// * result
    /// * flag_zero
    /// * flag_overflow
    pub fn reset_arithmetic(&mut self) {
        self.result = Word::default();
        self.flag_zero = false;
        self.flag_overflow = false;
    }
}

/// A proposed implementation of a processor state.
#[derive(Clone, Debug, Default)]
pub struct CpuState {
    /// The current operation pointer,
    pub current: Address,
    /// Last operation result,
    pub operation: OperationState,
    /// The stack (for procedure-calling and operations),
    pub stack: WordStack,
    /// The integral register bank,
    pub bank: Bank,
    /// The floating-point register bank,
    pub vector: Vector,
    /// On if a trace shall be printed out,
    pub flag_debug: bool,
    /// On if the processor must skip the next instruction,
    pub flag_skip: bool,
    /// On if the processor must halt,
    pub flag_halt: bool,
}

impl CpuState {
    /// Creates a default state.
    pub fn new() -> Self {
        Self {
            current: Address::default(),
            operation: OperationState::default(),
            stack: WordStack::default(),
            bank: Bank::default(),
            vector: Vector::default(),
            flag_debug: false,
            flag_skip: false,
            flag_halt: false,
        }
    }
}

/// The result of a processor tick.
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum TickState {
    /// Operation normally executed,
    Executed,
    /// The last operation was a jump in memory,
    Jumped,
    /// The last operation was skip accordingly to the [CpuState],
    Skipped,
    /// The last operation resulted in an error.
    Error,
}