Skip to main content

datex_core/runtime/execution/execution_loop/
interrupts.rs

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