Skip to main content

datex_core/runtime/execution/
macros.rs

1/// Yield an interrupt and get the next input
2macro_rules! interrupt {
3    ($input:expr, $arg:expr) => {{
4        yield Ok($arg);
5        $input.take_result()
6    }};
7}
8pub(crate) use interrupt;
9
10/// Yield an interrupt and get the next resolved value or None
11/// expecting the next input to be a ResolvedValue variant
12macro_rules! interrupt_with_maybe_value {
13    ($input:expr, $arg:expr) => {{
14        use crate::runtime::execution::macros::interrupt;
15
16        let res = interrupt!($input, $arg).unwrap();
17        match res {
18            crate::runtime::execution::execution_loop::interrupts::InterruptResult::ResolvedValue(value) => value,
19            _ => unreachable!(),
20        }
21    }};
22}
23pub(crate) use interrupt_with_maybe_value;
24
25/// Yield an interrupt and get the next resolved value
26/// expecting the next input to be a ResolvedValue variant with Some value
27macro_rules! interrupt_with_value {
28    ($input:expr, $arg:expr) => {{
29        use crate::runtime::execution::macros::interrupt_with_maybe_value;
30        let maybe_value = interrupt_with_maybe_value!($input, $arg);
31        if let Some(value) = maybe_value {
32            value
33        } else {
34            unreachable!();
35        }
36    }};
37}
38pub(crate) use interrupt_with_value;
39
40/// Unwrap a Result expression, yielding an error if it is an Err variant
41/// This is similar to the `?` operator but works within generator functions
42/// TODO #642: use "?" operator instead of yield_unwrap once supported in gen blocks
43macro_rules! yield_unwrap {
44    ($e:expr) => {{
45        let res = $e;
46        if let Ok(res) = res {
47            res
48        } else if let Err(err) = res {
49            return yield Err(err.into());
50        } else {
51            unreachable!();
52        }
53    }};
54}
55pub(crate) use yield_unwrap;