Skip to main content

datex_core/runtime/execution/execution_loop/
interrupts.rs

1use core::cell::RefCell;
2
3use crate::values::value_container::ValueContainer;
4
5use crate::{
6    core_compiler::core_compilation_context::DXBWithSharedValues,
7    libs::core::core_lib_id::CoreLibId,
8    prelude::*,
9    shared_values::{
10        ReferenceMutability, RemotePointerAddress, SelfOwnedPointerAddress,
11        SharedContainerMutability,
12    },
13    values::core_values::endpoint::Endpoint,
14};
15
16#[derive(Debug)]
17pub enum ExecutionInterrupt {
18    // used for intermediate results in unbounded scopes
19    SetActiveValue(Option<ValueContainer>),
20    /// yields an external interrupt to be handled by the execution loop caller (for I/O operations, pointer resolution, remote execution, etc.)
21    External(ExternalExecutionInterrupt),
22}
23
24#[derive(Debug)]
25pub enum ExternalExecutionInterrupt {
26    Result(Option<ValueContainer>),
27    GetReferenceToRemotePointer(RemotePointerAddress, ReferenceMutability),
28    GetReferenceToLocalPointer(SelfOwnedPointerAddress),
29    GetCoreLibValue(CoreLibId),
30    RemoteExecution {
31        input: DXBWithSharedValues,
32        receivers: Vec<Endpoint>,
33    },
34    Apply(ValueContainer, Vec<ValueContainer>),
35    /// Request to move a list of pointers from the current caller endpoint to the local endpoint
36    RequestMove(Vec<(SharedContainerMutability, SelfOwnedPointerAddress)>),
37    /// Move a list of pointers from the local endpoint to the caller
38    Move(Vec<(SelfOwnedPointerAddress, SelfOwnedPointerAddress)>),
39}
40
41#[derive(Debug)]
42pub enum InterruptResult {
43    ResolvedValue(Option<ValueContainer>),
44    ResolvedValues(Vec<ValueContainer>),
45}
46
47#[derive(Debug, Clone)]
48pub struct InterruptProvider {
49    result: Rc<RefCell<Option<InterruptResult>>>,
50}
51
52impl Default for InterruptProvider {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58impl InterruptProvider {
59    pub fn new() -> Self {
60        Self {
61            result: Rc::new(RefCell::new(None)),
62        }
63    }
64
65    pub fn provide_result(&self, result: InterruptResult) {
66        *self.result.borrow_mut() = Some(result);
67    }
68
69    pub fn take_result(&self) -> Option<InterruptResult> {
70        self.result.borrow_mut().take()
71    }
72}