use thiserror::Error; use crate::asm::data::literal::{DebugMsg, Label, RoutineName, Value}; use crate::asm::data::Register; use std::borrow::Cow; #[derive(Error, Debug)] pub enum Fault { #[error("Bad instruction at addr {addr:#10x}: {cause}")] BadInstruction { addr: u32, cause: InstrError, }, #[error("Runtime hit a barrier instruction: {msg}")] Barrier { msg: DebugMsg, }, #[error("User fault: {msg}")] FaultInstr { msg: DebugMsg, }, #[error("Program ended.")] Halt, #[error("Operation not allowed: {0}")] NotAllowed(Cow<'static, str>), #[error("Object does not exist: {0:#x}")] ObjectNotExist(Value), // #[error("Memory region {area:?} is locked by thread {owner:?}")] // MemoryLocked { // area: MemorySpan, // owner: ThreadToken // }, // // #[error("Memory claim {claim:?} owned by thread {owner:?} does not exist")] // ClaimNotExist { // claim: ClaimId, // owner: ThreadToken // }, #[error("Register does not exist: {reg:?}")] RegisterNotExist { reg: Register, }, #[error("Register is read-only: {reg:?}")] RegisterNotWritable { reg: Register, }, #[error("Called undefined routine: {routine}")] NoSuchRoutine { routine: RoutineName, }, #[error("Jump to undefined far label: {label}")] NoSuchLabel { label: Label, }, #[error("Crossed a barrier: {msg}")] JumpThroughBarrier { msg: DebugMsg, }, #[error("Call stack underflow")] CallStackUnderflow, #[error("Attempt to read undefined extension data store")] ExtDataNotDefined, } #[derive(Error, Debug)] pub enum InstrError { #[error("Instruction not recognized")] UnknownInstruction, #[error("Invalid bit span")] BadBitSpan, #[error("Operands data size differs")] UnevenOperandSize, }