small changes

This commit is contained in:
voidNUL 2024-02-25 09:35:06 -06:00
parent dd9a0c6f4e
commit dd0f64c859
3 changed files with 16 additions and 3 deletions

View file

@ -100,7 +100,7 @@ pub fn assemble(input: &str) -> Result<Vec<Word>, TaggedAsmError> {
if let Some(l) = last {
Err(TaggedAsmError {
kind: AsmError::ExpectedNum,
word: l.to_string(),
word: "[END OF FILE]".to_string(),
})
} else {
Ok(output)

View file

@ -18,6 +18,7 @@ pub struct Machine {
ip: Word,
ebp: Word,
phase: Phase,
clock: usize,
pub log: String,
pub cstack: Vec<Word>,
pub pstack: Vec<Word>,
@ -32,6 +33,7 @@ impl Machine {
ip: 0,
ebp: 0,
phase: Phase::Warmup,
clock: 0,
log: "".to_string(),
cstack: vec![],
pstack: vec![],
@ -106,6 +108,10 @@ impl Machine {
}
pub fn step(&mut self) -> CResult {
self.clock += 1;
if self.clock > 256 {
return Err(Error::ExecLimit)
}
let word = self
.instructions
.get(self.ip as usize)
@ -363,7 +369,7 @@ impl Machine {
self.phase = Phase::Recital;
self.ip = match self.fstack.last() {
Some(i) => *i,
None => return Err(Error::StackUnderflow),
None => return Err(Error::NoFunc),
}
},
OpKind::Push => {

View file

@ -18,6 +18,8 @@ pub enum Error {
BadCall,
NoExec,
IllegalOp,
NoFunc,
ExecLimit,
EndReached,
}
@ -30,13 +32,18 @@ impl Display for Error {
Self::WriteOob => write!(f, "Memory write out of bounds"),
Self::ReadOob => write!(f, "Memory read out of bounds"),
Self::IllegalOp => write!(f, "Illegal instruction reached"),
Self::BadCall => {
write!(f, "Attempted to call function which does not exist")
},
Self::NoExec => write!(
f,
"No exec instruction found. Are you trying to execute a library?"
"No exe instruction found. Are you trying to execute a library?"
),
Self::NoFunc => {
write!(f, "Cannot begin Recital, no functions have been defined")
},
Self::ExecLimit => write!(f, "Execution limit reached, compile and run natively to do really big stuff!"),
Self::EndReached => write!(f, "Successfully terminated"),
}
}