1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::machine::instruction::MachineInstruction;
use crate::machine::output_receiver::OutputReceiver;
use crate::machine::register::MachineRegister;
use crate::machine::Machine;
use std::marker::PhantomData;
pub enum HookResult {
Proceed,
Skip,
Goto(i32),
Abort,
}
pub trait PreExecuteHook<I: MachineInstruction> {
fn run<R: MachineRegister, O: OutputReceiver<R>>(
&mut self,
machine: &mut Machine<I, R, O>,
instruction: &I,
idx: usize,
) -> HookResult;
}
pub struct NoopHook<I: MachineInstruction> {
_marker: PhantomData<I>,
}
impl<I: MachineInstruction> Default for NoopHook<I> {
fn default() -> Self {
NoopHook {
_marker: Default::default(),
}
}
}
impl<I: MachineInstruction> PreExecuteHook<I> for NoopHook<I> {
fn run<R: MachineRegister, O: OutputReceiver<R>>(
&mut self,
_machine: &mut Machine<I, R, O>,
_instruction: &I,
_idx: usize,
) -> HookResult {
HookResult::Proceed
}
}