1use core::fmt;
23use crate::runtime::{Awaited, InstAddress, Output, VmCall};
45/// The reason why the virtual machine execution stopped.
6#[derive(Debug)]
7pub(crate) enum VmHalt {
8/// The virtual machine exited by running out of call frames, returning the given value.
9Exited(Option<InstAddress>),
10/// The virtual machine exited because it ran out of execution quota.
11Limited,
12/// The virtual machine yielded.
13Yielded(Option<InstAddress>, Output),
14/// The virtual machine awaited on the given future.
15Awaited(Awaited),
16/// Call into a new virtual machine.
17VmCall(VmCall),
18}
1920impl VmHalt {
21/// Convert into cheap info enum which only described the reason.
22pub(crate) fn into_info(self) -> VmHaltInfo {
23match self {
24Self::Exited(..) => VmHaltInfo::Exited,
25Self::Limited => VmHaltInfo::Limited,
26Self::Yielded(..) => VmHaltInfo::Yielded,
27Self::Awaited(..) => VmHaltInfo::Awaited,
28Self::VmCall(..) => VmHaltInfo::VmCall,
29 }
30 }
31}
3233/// The reason why the virtual machine execution stopped.
34#[derive(Debug, Clone, Copy, PartialEq)]
35pub(crate) enum VmHaltInfo {
36/// The virtual machine exited by running out of call frames.
37Exited,
38/// The virtual machine exited because it ran out of execution quota.
39Limited,
40/// The virtual machine yielded.
41Yielded,
42/// The virtual machine awaited on the given future.
43Awaited,
44/// Received instruction to push the inner virtual machine.
45VmCall,
46}
4748impl fmt::Display for VmHaltInfo {
49fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50match self {
51Self::Exited => write!(f, "exited"),
52Self::Limited => write!(f, "limited"),
53Self::Yielded => write!(f, "yielded"),
54Self::Awaited => write!(f, "awaited"),
55Self::VmCall => write!(f, "calling into other vm"),
56 }
57 }
58}