Skip to main content

datex_core/runtime/execution/
macros.rs

1/// Yield an interrupt and get the next input
2pub(crate) macro interrupt($input:expr, $arg:expr) {{
3    yield Ok($arg);
4    $input.take_result()
5}}
6
7/// Yield an interrupt and get the next resolved value or None
8/// expecting the next input to be a ResolvedValue variant
9pub(crate) macro interrupt_with_maybe_value {
10    ($input:expr, $arg:expr) => {{
11        use crate::runtime::execution::macros::interrupt;
12
13        let res = interrupt!($input, $arg).unwrap();
14        match res {
15            crate::runtime::execution::execution_loop::interrupts::InterruptResult::ResolvedValue(value) => value,
16            _ => unreachable!(),
17        }
18    }}
19}
20
21/// Yield an interrupt and get the returned borrowed args and the result value
22pub(crate) macro interrupt_with_borrowed_args_and_maybe_result {
23    ($input:expr, $arg:expr) => {{
24        use crate::runtime::execution::macros::interrupt;
25
26        let res = interrupt!($input, $arg).unwrap();
27        match res {
28            crate::runtime::execution::execution_loop::interrupts::InterruptResult::ResolvedValueAndBorrowedArgs((value, args)) => (value, args),
29            _ => unreachable!(),
30        }
31    }}
32}
33
34/// Yield an interrupt and get the next resolved value
35/// expecting the next input to be a ResolvedValue variant with Some value
36pub(crate) macro interrupt_with_value($input:expr, $arg:expr) {{
37    use crate::runtime::execution::macros::interrupt_with_maybe_value;
38    let maybe_value = interrupt_with_maybe_value!($input, $arg);
39    if let Some(value) = maybe_value {
40        value
41    } else {
42        unreachable!();
43    }
44}}
45
46/// Yield an interrupt and get the next resolved values
47/// expecting the next input to be a ResolvedValues variant
48#[allow(unused_macros)]
49pub(crate) macro interrupt_with_values {
50    ($input:expr, $arg:expr) => {{
51        use crate::runtime::execution::macros::interrupt;
52        let res = interrupt!($input, $arg).unwrap();
53        match res {
54            crate::runtime::execution::execution_loop::interrupts::InterruptResult::ResolvedValues(values) => values,
55            _ => unreachable!(),
56        }
57    }}
58}