1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! 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 {
    pub fn reset(&mut self) {
        self.result = Word::default();
        self.counter = Word::default();
    }
}

/// 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 {
    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,
}