изменен стиль кода, изменено расположение инструкций

This commit is contained in:
2024-02-13 12:33:31 +02:00
parent 061238db49
commit 48b53dc991
54 changed files with 524 additions and 484 deletions
+12 -7
View File
@@ -6,14 +6,14 @@ use crate::errors::StackError;
pub struct Instruction {
pub name: String,
pub arg: String,
pub data: u16
pub data: u16,
}
pub struct Stack {
pub program: Vec<Instruction>,
pub program_counter: u16,
pub labels: [Option<i16>; 256],
pub memory: StackVec
pub memory: StackVec,
}
impl Stack {
@@ -22,14 +22,14 @@ impl Stack {
program: Vec::new(),
program_counter: 0,
labels: [None; 256],
memory: StackVec::new(stack_size)
memory: StackVec::new(stack_size),
};
}
}
pub struct StackVec {
data: Vec<u16>,
max_size: usize
max_size: usize,
}
impl StackVec {
@@ -53,11 +53,16 @@ impl StackVec {
}
pub fn pop(&mut self) -> u16 {
self.data.pop().expect(&format!("{}", StackError::StackUnderflow))
self.data
.pop()
.expect(&format!("{}", StackError::StackUnderflow))
}
pub fn last(&mut self) -> u16 {
*self.data.last().expect(&format!("{}", StackError::StackUnderflow))
*self
.data
.last()
.expect(&format!("{}", StackError::StackUnderflow))
}
}
@@ -67,4 +72,4 @@ impl Deref for StackVec {
fn deref(&self) -> &Self::Target {
&self.data
}
}
}