datex_core/runtime/execution/execution_loop/
interrupts.rs

1use crate::global::protocol_structures::instructions::{
2    RawFullPointerAddress, RawInternalPointerAddress, RawLocalPointerAddress,
3};
4use crate::stdlib::cell::RefCell;
5use crate::stdlib::rc::Rc;
6use crate::stdlib::vec::Vec;
7use crate::values::core_values::map::MapKey;
8use crate::values::value_container::{OwnedValueKey, ValueContainer};
9
10#[derive(Debug)]
11pub enum ExecutionInterrupt {
12    // used for intermediate results in unbounded scopes
13    SetActiveValue(Option<ValueContainer>),
14    /// yields an external interrupt to be handled by the execution loop caller (for I/O operations, pointer resolution, remote execution, etc.)
15    External(ExternalExecutionInterrupt),
16}
17
18#[derive(Debug)]
19pub enum ExternalExecutionInterrupt {
20    Result(Option<ValueContainer>),
21    ResolvePointer(RawFullPointerAddress),
22    ResolveLocalPointer(RawLocalPointerAddress),
23    ResolveInternalPointer(RawInternalPointerAddress),
24    RemoteExecution(ValueContainer, Vec<u8>),
25    Apply(ValueContainer, Vec<ValueContainer>),
26}
27
28#[derive(Debug)]
29pub enum InterruptResult {
30    ResolvedValue(Option<ValueContainer>),
31}
32
33#[derive(Debug, Clone)]
34pub struct InterruptProvider {
35    result: Rc<RefCell<Option<InterruptResult>>>,
36}
37
38impl Default for InterruptProvider {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44impl InterruptProvider {
45    pub fn new() -> Self {
46        Self {
47            result: Rc::new(RefCell::new(None)),
48        }
49    }
50
51    pub fn provide_result(&self, result: InterruptResult) {
52        *self.result.borrow_mut() = Some(result);
53    }
54
55    pub fn take_result(&self) -> Option<InterruptResult> {
56        self.result.borrow_mut().take()
57    }
58}