datex_core/runtime/execution/context/
local.rs1#[cfg(feature = "compiler")]
2use crate::compiler::scope::CompilationScope;
3use crate::runtime::{
4 RuntimeInternal,
5 execution::{
6 ExecutionOptions, context::ExecutionContext,
7 execution_loop::state::ExecutionLoopState,
8 },
9};
10
11use crate::prelude::*;
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub enum ExecutionMode {
14 #[default]
16 Static,
17 Unbounded { has_next: bool },
20}
21
22impl ExecutionMode {
23 pub fn unbounded() -> Self {
24 ExecutionMode::Unbounded { has_next: true }
25 }
26
27 pub fn is_unbounded(&self) -> bool {
28 matches!(self, ExecutionMode::Unbounded { .. })
29 }
30}
31
32#[derive(Debug)]
33pub struct LocalExecutionContext {
34 #[cfg(feature = "compiler")]
35 pub compile_scope: CompilationScope,
36 pub loop_state: Option<ExecutionLoopState>,
37 pub runtime: Rc<RuntimeInternal>,
38 pub execution_options: ExecutionOptions,
39 pub verbose: bool,
40 pub execution_mode: ExecutionMode,
41}
42
43impl LocalExecutionContext {
44 pub fn new(
45 execution_mode: ExecutionMode,
46 runtime: Rc<RuntimeInternal>,
47 ) -> Self {
48 LocalExecutionContext {
49 #[cfg(feature = "compiler")]
50 compile_scope: CompilationScope::new(execution_mode),
51 loop_state: None,
52 runtime,
53 execution_options: ExecutionOptions::default(),
54 verbose: false,
55 execution_mode,
56 }
57 }
58
59 pub fn debug(
61 execution_mode: ExecutionMode,
62 runtime: Rc<RuntimeInternal>,
63 ) -> Self {
64 LocalExecutionContext {
65 #[cfg(feature = "compiler")]
66 compile_scope: CompilationScope::new(execution_mode),
67 execution_options: ExecutionOptions { verbose: true },
68 loop_state: None,
69 runtime,
70 verbose: true,
71 execution_mode,
72 }
73 }
74
75 pub fn set_runtime_internal(
76 &mut self,
77 runtime_internal: Rc<RuntimeInternal>,
78 ) {
79 self.runtime = runtime_internal;
80 }
81}
82
83impl ExecutionContext {
84 pub fn local(
85 execution_mode: ExecutionMode,
86 runtime: Rc<RuntimeInternal>,
87 ) -> Self {
88 ExecutionContext::Local(LocalExecutionContext::new(
89 execution_mode,
90 runtime,
91 ))
92 }
93
94 pub fn local_static(runtime: Rc<RuntimeInternal>) -> Self {
96 ExecutionContext::Local(LocalExecutionContext::new(
97 ExecutionMode::Static,
98 runtime,
99 ))
100 }
101
102 pub fn local_unbounded(runtime: Rc<RuntimeInternal>) -> Self {
104 ExecutionContext::Local(LocalExecutionContext::new(
105 ExecutionMode::Unbounded { has_next: true },
106 runtime,
107 ))
108 }
109
110 pub fn local_debug(
113 execution_mode: ExecutionMode,
114 runtime: Rc<RuntimeInternal>,
115 ) -> Self {
116 ExecutionContext::Local(LocalExecutionContext::debug(
117 execution_mode,
118 runtime,
119 ))
120 }
121}