#[cfg(feature = "compiler")]
use crate::compiler::scope::CompilationScope;
use crate::runtime::{
Runtime,
execution::{
ExecutionOptions, context::ExecutionContext,
execution_loop::state::ExecutionLoopState,
},
};
use crate::runtime::execution::execution_input::ExecutionCallerMetadata;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ExecutionMode {
#[default]
Static,
Unbounded { has_next: bool },
}
impl ExecutionMode {
pub fn unbounded() -> Self {
ExecutionMode::Unbounded { has_next: true }
}
pub fn is_unbounded(&self) -> bool {
matches!(self, ExecutionMode::Unbounded { .. })
}
}
#[derive(Debug)]
pub struct LocalExecutionContext {
#[cfg(feature = "compiler")]
pub compile_scope: CompilationScope,
pub loop_state: Option<ExecutionLoopState>,
pub runtime: Runtime,
pub execution_options: ExecutionOptions,
pub verbose: bool,
pub execution_mode: ExecutionMode,
pub caller_metadata: ExecutionCallerMetadata,
}
impl LocalExecutionContext {
pub fn new(
execution_mode: ExecutionMode,
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
LocalExecutionContext {
#[cfg(feature = "compiler")]
compile_scope: CompilationScope::new(execution_mode),
loop_state: None,
runtime,
execution_options: ExecutionOptions::default(),
verbose: false,
execution_mode,
caller_metadata,
}
}
pub fn debug(
execution_mode: ExecutionMode,
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
LocalExecutionContext {
#[cfg(feature = "compiler")]
compile_scope: CompilationScope::new(execution_mode),
execution_options: ExecutionOptions { verbose: true },
loop_state: None,
runtime,
verbose: true,
execution_mode,
caller_metadata,
}
}
pub fn set_runtime_internal(&mut self, runtime_internal: Runtime) {
self.runtime = runtime_internal;
}
}
impl ExecutionContext {
pub fn local(
execution_mode: ExecutionMode,
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
ExecutionContext::Local(LocalExecutionContext::new(
execution_mode,
runtime,
caller_metadata,
))
}
pub fn local_static(
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
ExecutionContext::Local(LocalExecutionContext::new(
ExecutionMode::Static,
runtime,
caller_metadata,
))
}
pub fn local_unbounded(
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
ExecutionContext::Local(LocalExecutionContext::new(
ExecutionMode::Unbounded { has_next: true },
runtime,
caller_metadata,
))
}
pub fn local_debug(
execution_mode: ExecutionMode,
runtime: Runtime,
caller_metadata: ExecutionCallerMetadata,
) -> Self {
ExecutionContext::Local(LocalExecutionContext::debug(
execution_mode,
runtime,
caller_metadata,
))
}
}