1#[derive(Debug, Clone, Eq)]
2pub enum SimulatorErrorCode {
3 DetectedTrueLoop,
4 DetectedTrueLoopCode(i64),
5 DetectedTrueLoopAt {
6 signals: Vec<String>,
7 },
8 Runtime {
9 message: String,
10 signals: Vec<String>,
11 },
12 InternalError,
13 NotAnEvent(String),
14}
15
16impl PartialEq for SimulatorErrorCode {
17 fn eq(&self, other: &Self) -> bool {
18 match (self, other) {
19 (Self::DetectedTrueLoop, Self::DetectedTrueLoop)
20 | (Self::DetectedTrueLoop, Self::DetectedTrueLoopCode(_))
21 | (Self::DetectedTrueLoop, Self::DetectedTrueLoopAt { .. })
22 | (Self::DetectedTrueLoopCode(_), Self::DetectedTrueLoop)
23 | (Self::DetectedTrueLoopCode(_), Self::DetectedTrueLoopCode(_))
24 | (Self::DetectedTrueLoopCode(_), Self::DetectedTrueLoopAt { .. })
25 | (Self::DetectedTrueLoopAt { .. }, Self::DetectedTrueLoopCode(_))
26 | (Self::DetectedTrueLoopAt { .. }, Self::DetectedTrueLoop)
27 | (Self::DetectedTrueLoopAt { .. }, Self::DetectedTrueLoopAt { .. }) => true,
28 (Self::InternalError, Self::InternalError) => true,
29 (
30 Self::Runtime {
31 message: a,
32 signals: sa,
33 },
34 Self::Runtime {
35 message: b,
36 signals: sb,
37 },
38 ) => a == b && sa == sb,
39 (Self::NotAnEvent(a), Self::NotAnEvent(b)) => a == b,
40 _ => false,
41 }
42 }
43}
44
45impl std::fmt::Display for SimulatorErrorCode {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 match self {
48 Self::DetectedTrueLoop | Self::DetectedTrueLoopCode(_) => {
49 write!(f, "Detected True Loop")
50 }
51 Self::DetectedTrueLoopAt { signals } if signals.is_empty() => {
52 write!(f, "Detected True Loop")
53 }
54 Self::DetectedTrueLoopAt { signals } => {
55 write!(f, "Detected True Loop: {}", signals.join(", "))
56 }
57 Self::Runtime { message, signals } if signals.is_empty() => write!(f, "{message}"),
58 Self::Runtime { message, signals } => {
59 write!(f, "{}: {}", message, signals.join(", "))
60 }
61 Self::InternalError => write!(f, "Internal Error"),
62 Self::NotAnEvent(name) => write!(
63 f,
64 "Signal '{}' is not an event (only clock and async reset signals can be scheduled). Use `modify()` for synchronous signals.",
65 name
66 ),
67 }
68 }
69}
70
71impl std::error::Error for SimulatorErrorCode {}