Skip to main content

devela/lang/prog/script/machine/
outcome.rs

1// devela/src/lang/prog/script/machine/outcome.rs
2//
3//!
4//
5
6use crate::{ConstInit, ScriptCall, ScriptValue};
7#[cfg(doc)]
8use crate::{ScriptMachine, ScriptOp};
9
10#[doc = crate::_tags!(lang result)]
11/// The non-error outcome of running a [`ScriptMachine`].
12#[doc = crate::_doc_meta!{
13    location("lang/prog/script/machine"),
14    #[cfg(target_pointer_width = "32")]
15    test_size_of(ScriptOutcome<u32> = 16|128; niche Option),
16    #[cfg(target_pointer_width = "64")]
17    test_size_of(ScriptOutcome<u32> = 32|256; niche Option),
18}]
19/// An outcome explains why control returned to the caller.
20#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
21pub enum ScriptOutcome<R> {
22    /// Execution reached a host operation awaiting resolution.
23    HostCall(ScriptCall),
24
25    /// Execution explicitly suspended with [`ScriptOp::Yield`].
26    Yielded,
27
28    /// Execution finished with an optional returned value.
29    Returned(Option<ScriptValue<R>>),
30
31    /// Execution reached the caller-provided operation budget.
32    BudgetExhausted,
33}
34
35impl<R> ConstInit for ScriptOutcome<R> {
36    const INIT: Self = Self::Returned(None);
37}