datex_core/runtime/
mod.rs1use crate::{
2 network::com_hub::ComHub,
3 runtime::execution::ExecutionError,
4 values::{
5 core_values::endpoint::Endpoint, value_container::ValueContainer,
6 },
7};
8
9use crate::prelude::*;
10use core::{cell::RefCell, fmt::Debug, result::Result};
11use execution::context::{
12 ExecutionContext, RemoteExecutionContext, ScriptExecutionError,
13};
14
15mod config;
16pub mod dif_interface;
17pub mod execution;
18mod incoming_sections;
19mod internal;
20pub mod memory;
21mod runner;
22
23#[cfg(test)]
24pub mod test_utils;
25
26pub use config::*;
27pub use internal::*;
28pub use runner::*;
29
30use self::memory::Memory;
31
32const VERSION: &str = env!("CARGO_PKG_VERSION");
33
34#[derive(Clone)]
35pub struct Runtime {
36 pub version: String,
37 pub internal: Rc<RuntimeInternal>,
38}
39
40impl Debug for Runtime {
41 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42 f.debug_struct("Runtime")
43 .field("version", &self.version)
44 .finish()
45 }
46}
47
48impl Runtime {
51 pub fn com_hub(&self) -> Rc<ComHub> {
52 self.internal.com_hub.clone()
53 }
54 pub fn endpoint(&self) -> Endpoint {
55 self.internal.endpoint.clone()
56 }
57
58 pub fn internal(&self) -> Rc<RuntimeInternal> {
59 Rc::clone(&self.internal)
60 }
61
62 pub fn memory(&self) -> &RefCell<Memory> {
63 &self.internal.memory
64 }
65
66 #[cfg(feature = "compiler")]
67 pub async fn execute(
68 &self,
69 script: &str,
70 inserted_values: &[ValueContainer],
71 execution_context: Option<&mut ExecutionContext>,
72 ) -> Result<Option<ValueContainer>, ScriptExecutionError> {
73 RuntimeInternal::execute(
74 self.internal(),
75 script,
76 inserted_values,
77 execution_context,
78 )
79 .await
80 }
81
82 #[cfg(feature = "compiler")]
83 pub fn execute_sync(
84 &self,
85 script: &str,
86 inserted_values: &[ValueContainer],
87 execution_context: Option<&mut ExecutionContext>,
88 ) -> Result<Option<ValueContainer>, ScriptExecutionError> {
89 RuntimeInternal::execute_sync(
90 self.internal(),
91 script,
92 inserted_values,
93 execution_context,
94 )
95 }
96
97 pub async fn execute_dxb<'a>(
98 &'a self,
99 dxb: Vec<u8>,
100 execution_context: Option<&'a mut ExecutionContext>,
101 end_execution: bool,
102 ) -> Result<Option<ValueContainer>, ExecutionError> {
103 RuntimeInternal::execute_dxb(
104 self.internal(),
105 dxb,
106 execution_context,
107 end_execution,
108 )
109 .await
110 }
111
112 pub fn execute_dxb_sync(
113 &self,
114 dxb: &[u8],
115 execution_context: Option<&mut ExecutionContext>,
116 end_execution: bool,
117 ) -> Result<Option<ValueContainer>, ExecutionError> {
118 RuntimeInternal::execute_dxb_sync(
119 self.internal(),
120 dxb,
121 execution_context,
122 end_execution,
123 )
124 }
125
126 async fn execute_remote(
127 &self,
128 remote_execution_context: &mut RemoteExecutionContext,
129 dxb: Vec<u8>,
130 ) -> Result<Option<ValueContainer>, ExecutionError> {
131 RuntimeInternal::execute_remote(
132 self.internal(),
133 remote_execution_context,
134 dxb,
135 )
136 .await
137 }
138}