From dd0f64c8591d0e71be32d137665770776fc69439 Mon Sep 17 00:00:00 2001 From: voidNUL <50534996+Xterminate1818@users.noreply.github.com> Date: Sun, 25 Feb 2024 09:35:06 -0600 Subject: [PATCH] small changes --- src/asm.rs | 2 +- src/lib.rs | 8 +++++++- src/util.rs | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/asm.rs b/src/asm.rs index de71c48..c5c6c4e 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -100,7 +100,7 @@ pub fn assemble(input: &str) -> Result, TaggedAsmError> { if let Some(l) = last { Err(TaggedAsmError { kind: AsmError::ExpectedNum, - word: l.to_string(), + word: "[END OF FILE]".to_string(), }) } else { Ok(output) diff --git a/src/lib.rs b/src/lib.rs index 344dd7e..f52eb5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ pub struct Machine { ip: Word, ebp: Word, phase: Phase, + clock: usize, pub log: String, pub cstack: Vec, pub pstack: Vec, @@ -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 => { diff --git a/src/util.rs b/src/util.rs index 016267d..dfa3fdb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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"), } }