1use crate::state::{
2 THREAD_STATUS_ERR_ERR, THREAD_STATUS_ERR_MEM, THREAD_STATUS_ERR_RUN, THREAD_STATUS_ERR_SYNTAX,
3};
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6#[repr(u8)]
7pub enum VmError {
8 Runtime,
9 Syntax,
10 Memory,
11 ErrorHandler,
12}
13
14impl VmError {
15 pub(crate) const fn status(self) -> i32 {
16 match self {
17 Self::Runtime => THREAD_STATUS_ERR_RUN as i32,
18 Self::Syntax => THREAD_STATUS_ERR_SYNTAX as i32,
19 Self::Memory => THREAD_STATUS_ERR_MEM as i32,
20 Self::ErrorHandler => THREAD_STATUS_ERR_ERR as i32,
21 }
22 }
23}
24
25#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26#[repr(u8)]
27pub enum VmControl {
28 Yield,
29 Break,
30}
31
32#[derive(Clone, Copy, Debug, Eq, PartialEq)]
33pub enum VmExit {
34 Error(VmError),
35 Control(VmControl),
36}
37
38impl From<VmError> for VmExit {
39 fn from(error: VmError) -> Self {
40 Self::Error(error)
41 }
42}
43
44impl From<VmControl> for VmExit {
45 fn from(control: VmControl) -> Self {
46 Self::Control(control)
47 }
48}
49
50pub type VmResult<T = ()> = Result<T, VmExit>;
51
52pub type VmErrorResult<T = ()> = Result<T, VmError>;