Skip to main content

datex_core/runtime/
mod.rs

1//! This module contains the implementation of the runtime, which is the backbone of the DATEX system.
2use crate::{
3    core_compiler::core_compilation_context::DXBWithSharedValues,
4    runtime::execution::ExecutionError,
5    values::value_container::ValueContainer,
6};
7
8use crate::prelude::*;
9use core::{fmt::Debug, ops::Deref, result::Result};
10use execution::context::{
11    ExecutionContext, RemoteExecutionContext, ScriptExecutionError,
12};
13mod config;
14pub mod execution;
15mod incoming_sections;
16mod internal;
17pub mod pointer_availability_lookup;
18mod runner;
19
20pub mod cache;
21pub mod pointer_address_provider;
22mod request_move;
23#[cfg(test)]
24pub mod test_utils;
25
26pub use config::*;
27pub use internal::*;
28pub use runner::*;
29
30#[derive(Clone, Debug)]
31pub struct Runtime {
32    internal: Rc<RuntimeInternal>,
33}
34
35impl Deref for Runtime {
36    type Target = RuntimeInternal;
37
38    fn deref(&self) -> &Self::Target {
39        &self.internal
40    }
41}
42
43/// publicly exposed wrapper impl for the Runtime
44/// around RuntimeInternal
45impl Runtime {
46    pub(crate) fn new(runtime_internal: RuntimeInternal) -> Runtime {
47        Runtime {
48            internal: Rc::new(runtime_internal),
49        }
50    }
51
52    pub fn stub() -> Runtime {
53        Runtime::new(RuntimeInternal::stub())
54    }
55
56    fn internal(&self) -> Rc<RuntimeInternal> {
57        Rc::clone(&self.internal)
58    }
59
60    #[cfg(feature = "compiler")]
61    pub async fn execute(
62        &self,
63        script: &str,
64        inserted_values: &[ValueContainer],
65        execution_context: Option<&mut ExecutionContext>,
66    ) -> Result<Option<ValueContainer>, ScriptExecutionError> {
67        RuntimeInternal::execute(
68            self.internal(),
69            script,
70            inserted_values,
71            execution_context,
72        )
73        .await
74    }
75
76    #[cfg(feature = "compiler")]
77    pub fn execute_sync(
78        &self,
79        script: &str,
80        inserted_values: &[ValueContainer],
81        execution_context: Option<&mut ExecutionContext>,
82    ) -> Result<Option<ValueContainer>, ScriptExecutionError> {
83        RuntimeInternal::execute_sync(
84            self.internal(),
85            script,
86            inserted_values,
87            execution_context,
88        )
89    }
90
91    pub async fn execute_dxb<'a>(
92        &'a self,
93        input: DXBWithSharedValues,
94        execution_context: Option<&'a mut ExecutionContext>,
95        end_execution: bool,
96    ) -> Result<Option<ValueContainer>, ExecutionError> {
97        RuntimeInternal::execute_dxb(
98            self.internal(),
99            input,
100            execution_context,
101            end_execution,
102        )
103        .await
104    }
105
106    pub fn execute_dxb_sync(
107        &self,
108        input: DXBWithSharedValues,
109        execution_context: Option<&mut ExecutionContext>,
110        end_execution: bool,
111    ) -> Result<Option<ValueContainer>, ExecutionError> {
112        RuntimeInternal::execute_dxb_sync(
113            self.internal(),
114            input,
115            execution_context,
116            end_execution,
117        )
118    }
119
120    async fn execute_remote(
121        &self,
122        remote_execution_context: &mut RemoteExecutionContext,
123        input: DXBWithSharedValues,
124    ) -> Result<Option<ValueContainer>, ExecutionError> {
125        RuntimeInternal::execute_remote(
126            self.internal(),
127            remote_execution_context,
128            input,
129        )
130        .await
131    }
132}