rune/runtime/vm_halt.rs
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 53 54 55 56 57 58
use core::fmt;
use crate::runtime::{Awaited, InstAddress, Output, VmCall};
/// The reason why the virtual machine execution stopped.
#[derive(Debug)]
pub(crate) enum VmHalt {
/// The virtual machine exited by running out of call frames, returning the given value.
Exited(Option<InstAddress>),
/// The virtual machine exited because it ran out of execution quota.
Limited,
/// The virtual machine yielded.
Yielded(Option<InstAddress>, Output),
/// The virtual machine awaited on the given future.
Awaited(Awaited),
/// Call into a new virtual machine.
VmCall(VmCall),
}
impl VmHalt {
/// Convert into cheap info enum which only described the reason.
pub(crate) fn into_info(self) -> VmHaltInfo {
match self {
Self::Exited(..) => VmHaltInfo::Exited,
Self::Limited => VmHaltInfo::Limited,
Self::Yielded(..) => VmHaltInfo::Yielded,
Self::Awaited(..) => VmHaltInfo::Awaited,
Self::VmCall(..) => VmHaltInfo::VmCall,
}
}
}
/// The reason why the virtual machine execution stopped.
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum VmHaltInfo {
/// The virtual machine exited by running out of call frames.
Exited,
/// The virtual machine exited because it ran out of execution quota.
Limited,
/// The virtual machine yielded.
Yielded,
/// The virtual machine awaited on the given future.
Awaited,
/// Received instruction to push the inner virtual machine.
VmCall,
}
impl fmt::Display for VmHaltInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Exited => write!(f, "exited"),
Self::Limited => write!(f, "limited"),
Self::Yielded => write!(f, "yielded"),
Self::Awaited => write!(f, "awaited"),
Self::VmCall => write!(f, "calling into other vm"),
}
}
}