strontium/machine/instruction/executors/
interrupt.rs

1use crate::machine::{Executor, Strontium, StrontiumError};
2use crate::Instruction;
3use super::super::InterruptKind;
4
5/// Attend to an event that needs immediate attention.
6#[derive(Debug, Clone, PartialEq)]
7pub struct InterruptExecutor;
8
9impl Executor for InterruptExecutor {
10    fn execute(&self, machine: &mut Strontium, instruction: Instruction) -> Result<bool, StrontiumError> {
11        if let Instruction::INTERRUPT { interrupt } = instruction {
12            match interrupt.kind {
13                InterruptKind::Print => {
14                    let value = machine.registers.get(&interrupt.address);
15                    if let Some(value) = value {
16                        println!("{}", value);
17                    } else {
18                        println!("Invalid register address: {}", interrupt.address);
19                    }
20                },
21
22                _ => {},
23            }
24        }
25
26        Ok(true)
27    }
28}