diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-09-08 17:31:44 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-09-08 17:31:44 +0200 |
| commit | 37c9824cd7674aa9b8b9f094cf3a93e6da2c1f99 (patch) | |
| tree | 4b1d8663ad8c95f737a28fc72783614c600b705d | |
| parent | f556a7bbebab54b4a4bd9d9ecf0b79c085f0b543 (diff) | |
| download | tools.nes-37c9824cd7674aa9b8b9f094cf3a93e6da2c1f99.tar.gz tools.nes-37c9824cd7674aa9b8b9f094cf3a93e6da2c1f99.zip | |
vnf: refuse to proceed if the machine is inactive
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | lib/vnf/src/lib.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 729bd58..0b15d6a 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -659,8 +659,20 @@ impl Machine { Ok(()) } - /// Step the execution of the machine by one instruction. + /// Step the execution of the machine by one instruction. It will return an + /// error if the execution fails for whatever reason, but also if this + /// machine is no longer active. Hence, if the machine has been deactivated + /// for some reason (e.g. an unexpected 'brk' with 'Machine.halt_on_brk' set + /// to true), then it's up to the caller to create a new [`Machine`] + /// instance. pub fn next_iteration(&mut self) -> Result<(), String> { + // This is a public function, and so it can be called even if it doesn't + // make sense to do so. Let's make a sanity check and return an error + // whenever the machine is set to be inactive. + if !self.active { + return Err("the machine is no longer active, cannot iterate over it".to_string()); + } + // Perform a new iteration of the PPU and the CPU. self.next_ppu()?; self.execute()?; |
