Skip to main content

ExecutionContext

Struct ExecutionContext 

Source
pub struct ExecutionContext { /* private fields */ }
Expand description

Execution context for evaluating expressions

Implementations§

Source§

impl ExecutionContext

Source

pub fn set_id(&mut self, id: &str)

Set the current ID

Source

pub fn id(&self) -> Result<&str>

Get the ID being analyzed

Source

pub fn get_current_id(&self) -> Result<String>

Get the current ID (owned string)

Source

pub fn timeframe(&self) -> Result<&Timeframe>

Get the timeframe

Source

pub fn get_current_timeframe(&self) -> Result<Timeframe>

Get the current timeframe

Source

pub fn set_current_timeframe(&mut self, timeframe: Timeframe) -> Result<()>

Set the current timeframe

Source

pub fn update_data(&mut self, data: &DataFrame)

Update ID and timeframe from a DataFrame

Source

pub fn get_date_range(&self) -> Option<(DateTime<Utc>, DateTime<Utc>)>

Get the loaded date range (if any) as native DateTime values

Source

pub fn set_date_range(&mut self, start: DateTime<Utc>, end: DateTime<Utc>)

Set the date range for data loading with native DateTime values

Source

pub fn set_date_range_parsed(&mut self, start: &str, end: &str) -> Result<()>

Set the date range by parsing ISO8601 strings

Accepts common date formats:

  • ISO8601: “2024-01-01T00:00:00Z”
  • Date only: “2024-01-01” (assumes start of day UTC)
Source

pub fn set_reference_datetime(&mut self, datetime: DateTime<Utc>)

Set the reference datetime for row indexing

Source

pub fn get_reference_datetime(&self) -> Option<DateTime<Utc>>

Get the reference datetime

Source

pub fn sync_to_reference_datetime(&mut self) -> Result<()>

Update current row to match reference datetime

Source

pub fn set_data_access_mode(&mut self, mode: DataAccessMode, strict: bool)

Set the data access mode for future data validation

Source

pub fn lookahead_guard(&self) -> Option<&LookAheadGuard>

Get the look-ahead guard

Source§

impl ExecutionContext

Source

pub fn set_current_row(&mut self, index: usize) -> Result<()>

Set the current data row index

Source

pub fn current_row_index(&self) -> usize

Get the current data row index

Source

pub fn get_current_row_index(&self) -> usize

Get the current data row index (alias for compatibility)

Source

pub fn row_count(&self) -> usize

Get total row count

Source

pub fn get_row_timestamp(&self, index: usize) -> Result<i64>

Get timestamp for a row index

Source

pub fn get_row(&mut self, relative_index: i32) -> Result<RowValue>

Get a data row by relative index

Source

pub fn get_row_range(&mut self, start: i32, end: i32) -> Result<Vec<RowValue>>

Get data rows in a range

Source

pub fn get_row_with_timeframe( &mut self, index: i32, timeframe: &Timeframe, ) -> Result<RowValue>

Get a data row with explicit timeframe

Source

pub fn get_row_range_with_timeframe( &mut self, start: i32, end: i32, timeframe: &Timeframe, ) -> Result<Vec<RowValue>>

Get data rows in a range with explicit timeframe

Source

pub fn get_row_relative_to_reference( &mut self, relative_index: i32, ) -> Result<RowValue>

Get a data row relative to the reference datetime

Source

pub fn get_row_range_relative_to_reference( &mut self, start: i32, end: i32, ) -> Result<Vec<RowValue>>

Get data rows in a range relative to the reference datetime

Source

pub fn get_all_rows(&mut self) -> Result<Vec<RowValue>>

Get all rows for the current identifier and timeframe

Source§

impl ExecutionContext

Source

pub async fn prefetch_data(&mut self, queries: Vec<DataQuery>) -> Result<()>

Prefetch data before execution (Phase 6)

This async method loads all required data concurrently and populates the cache. Must be called before execution starts.

§Arguments
  • queries - List of DataQuery objects specifying what data to load
§Example
let queries = vec![
    DataQuery::new("AAPL", Timeframe::d1()).limit(1000),
];
ctx.prefetch_data(queries).await?;
Source

pub fn start_live_feed(&mut self) -> Result<()>

Start live data feed (Phase 6)

Subscribes to live bar updates for the current symbol/timeframe. New bars will be appended to the live buffer as they arrive.

Source

pub fn stop_live_feed(&mut self) -> Result<()>

Stop live data feed (Phase 6)

Source

pub fn has_data_cache(&self) -> bool

Check if using async data cache (Phase 6)

Source

pub fn data_cache(&self) -> Option<&DataCache>

Get reference to data cache (Phase 8)

Source

pub fn async_provider(&self) -> Option<SharedAsyncProvider>

Get async data provider (Phase 7)

Returns the AsyncDataProvider from the data cache if available. This is used for constructing TableRef and other lazy data references.

Source

pub fn register_provider(&self, name: &str, provider: SharedAsyncProvider)

Register a data provider (Phase 8)

Registers a named provider in the registry.

Source

pub fn get_provider(&self, name: &str) -> Result<SharedAsyncProvider>

Get provider by name (Phase 8)

Source

pub fn get_default_provider(&self) -> Result<SharedAsyncProvider>

Get default provider (Phase 8)

Source

pub fn set_default_provider(&self, name: &str) -> Result<()>

Set default provider (Phase 8)

Source

pub fn register_type_mapping(&self, type_name: &str, mapping: TypeMapping)

Register a type mapping (Phase 8)

Registers a type mapping that defines the expected DataFrame structure.

Source

pub fn get_type_mapping(&self, type_name: &str) -> Result<TypeMapping>

Get type mapping (Phase 8)

Retrieves the type mapping for validation.

Source

pub fn has_type_mapping(&self, type_name: &str) -> bool

Check if type mapping exists (Phase 8)

Source

pub fn load_extension( &self, path: &Path, config: &Value, ) -> Result<LoadedExtension>

Load a data source extension from a shared library

§Arguments
  • path - Path to the extension shared library (.so, .dll, .dylib)
  • config - Configuration value for the extension
Source

pub fn unload_extension(&self, name: &str) -> bool

Unload an extension by name

Source

pub fn list_extensions(&self) -> Vec<String>

List all loaded extension names

Source

pub fn get_extension_query_schema( &self, name: &str, ) -> Option<ParsedQuerySchema>

Get query schema for an extension (for LSP autocomplete)

Source

pub fn get_extension_output_schema( &self, name: &str, ) -> Option<ParsedOutputSchema>

Get output schema for an extension (for LSP autocomplete)

Source

pub fn get_extension(&self, name: &str) -> Option<Arc<ExtensionDataSource>>

Get an extension data source by name

Source

pub fn get_extension_module_schema( &self, module_name: &str, ) -> Option<ParsedModuleSchema>

Get extension module schema by module namespace.

Source

pub fn get_language_runtime( &self, language_id: &str, ) -> Option<Arc<PluginLanguageRuntime>>

Get a language runtime by its language identifier (e.g., “python”).

Source

pub fn language_runtimes(&self) -> HashMap<String, Arc<PluginLanguageRuntime>>

Return all loaded language runtimes, keyed by language identifier.

Source

pub fn module_exports_from_extensions(&self) -> Vec<ModuleExports>

Build VM extension modules from loaded extension module capabilities.

Source

pub fn invoke_extension_module_nb( &self, module_name: &str, function: &str, args: &[ValueWord], ) -> Result<ValueWord>

Invoke one loaded module export via module namespace.

Source

pub fn invoke_extension_module_wire( &self, module_name: &str, function: &str, args: &[WireValue], ) -> Result<WireValue>

Invoke one loaded module export via module namespace.

Source

pub fn data_load_mode(&self) -> DataLoadMode

Get current data load mode (Phase 8)

Source

pub fn set_data_load_mode(&mut self, mode: DataLoadMode)

Set data load mode (Phase 8)

Source

pub fn is_repl_mode(&self) -> bool

Check if in REPL mode (sync loading allowed)

Source

pub fn set_data_provider(&mut self, provider: Arc<dyn Any + Send + Sync>)

Set the DuckDB provider

Source

pub fn data_provider(&self) -> Result<Arc<dyn Any + Send + Sync>>

Get DataProvider (legacy compatibility - returns type-erased Arc)

Source§

impl ExecutionContext

Source

pub fn register_annotation(&mut self, def: AnnotationDef)

Register an annotation definition

Annotation definitions are stored and used to dispatch lifecycle hooks when functions with those annotations are registered.

Source

pub fn annotation_context(&self) -> &AnnotationContext

Get the annotation context (for lifecycle hooks)

Source

pub fn annotation_context_mut(&mut self) -> &mut AnnotationContext

Get mutable annotation context (for lifecycle hooks)

Source

pub fn register_function(&mut self, function: FunctionDef)

Register a user-defined function

This dispatches on_define lifecycle hooks for all annotations on the function.

Source

pub fn lookup_pattern(&self, name: &str) -> Result<&Closure>

Look up a pattern by name from the pattern registry

Returns an error with a helpful message if the pattern is not found.

Source

pub fn type_method_registry(&self) -> &Arc<TypeMethodRegistry>

Get the type method registry

Source

pub fn type_schema_registry(&self) -> &Arc<TypeSchemaRegistry>

Get the type schema registry for JIT type specialization

Source

pub fn merge_type_schemas(&mut self, other: TypeSchemaRegistry)

Merge additional type schemas into the context’s registry. Used after compilation to make inline object schemas available for wire serialization.

Source

pub fn register_enum(&mut self, enum_def: EnumDef)

Register an enum definition

This enables sum type support by tracking which enums exist and their variants. Called during semantic analysis when processing enum declarations.

Source

pub fn lookup_enum(&self, name: &str) -> Option<&EnumDef>

Look up an enum definition by name

Source

pub fn has_enum(&self, name: &str) -> bool

Check if an enum exists

Source

pub fn enum_registry(&self) -> &EnumRegistry

Get the enum registry (for advanced queries)

Source

pub fn register_struct_type(&mut self, struct_def: StructTypeDef)

Register a struct type definition for REPL persistence

This stores the full StructTypeDef so that type definitions survive across REPL sessions. When a new REPL command is compiled, previously registered struct types are injected into the program so the compiler can see them.

Source

pub fn struct_type_defs(&self) -> &HashMap<String, StructTypeDef>

Get all registered struct type definitions

Returns an iterator over all struct type definitions registered in previous REPL sessions. Used to inject them into the program before compilation.

Source§

impl ExecutionContext

Source

pub fn push_scope(&mut self)

Push a new variable scope (for function calls)

Source

pub fn pop_scope(&mut self)

Pop a variable scope (after function return)

Source

pub fn reset_for_new_execution(&mut self)

Reset for new execution (Interpreter mode)

Clears script-level variables while preserving:

  • Data cache (loaded instruments)
  • Registered functions (from stdlib)
  • Data providers
  • Module exports

This allows re-execution of code with the same variable names without “Variable already declared” errors.

Source

pub fn fork_for_parallel(&self) -> Self

Create a fresh context for parallel execution that shares Arc-wrapped resources but has independent mutable state (variables, position manager, caches)

Source§

impl ExecutionContext

Source

pub fn set_variable(&mut self, name: &str, value: ValueWord) -> Result<()>

Set a variable value (for simple assignment without declaration)

Source

pub fn set_variable_nb(&mut self, name: &str, value: ValueWord) -> Result<()>

Set a variable value from ValueWord (avoids ValueWord conversion)

Source

pub fn get_variable(&self, name: &str) -> Result<Option<ValueWord>>

Get a variable value as ValueWord

Source

pub fn get_variable_nb(&self, name: &str) -> Result<Option<ValueWord>>

Get a variable value as ValueWord (avoids ValueWord materialization)

Source

pub fn declare_variable( &mut self, name: &str, kind: VarKind, value: Option<ValueWord>, ) -> Result<()>

Declare a new variable (with let, var, const)

Source

pub fn declare_variable_with_format( &mut self, name: &str, kind: VarKind, value: Option<ValueWord>, format_hint: Option<String>, format_overrides: Option<HashMap<String, ValueWord>>, ) -> Result<()>

Declare a new variable with format hint and parameter overrides

This is the full version that supports type aliases with meta parameter overrides, e.g., type Percent4 = Percent { decimals: 4 } would store:

  • format_hint: Some(“Percent”)
  • format_overrides: Some({ “decimals”: 4 })
Source

pub fn get_variable_format_hint(&self, name: &str) -> Option<String>

Get the format hint for a variable (if any)

Source

pub fn get_variable_format_overrides( &self, name: &str, ) -> Option<HashMap<String, ValueWord>>

Get the format overrides for a variable (if any)

Returns parameter overrides from type alias, e.g., { “decimals”: 4 } for a variable declared as let x: Percent4 where type Percent4 = Percent { decimals: 4 }

Source

pub fn get_variable_format_info( &self, name: &str, ) -> (Option<String>, Option<HashMap<String, ValueWord>>)

Get both format hint and overrides for a variable

Source

pub fn declare_pattern( &mut self, pattern: &DestructurePattern, kind: VarKind, value: ValueWord, ) -> Result<()>

Declare variables matching a pattern

Source

pub fn set_pattern( &mut self, pattern: &DestructurePattern, value: ValueWord, ) -> Result<()>

Set variables matching a pattern (for assignments)

Source

pub fn get_all_variable_names(&self) -> Vec<String>

Get all variable names currently in scope

Source

pub fn get_variable_kind(&self, name: &str) -> Option<VarKind>

Get the kind of a variable (let, var, const)

Source

pub fn root_scope_binding_names(&self) -> Vec<String>

Get all root-scope binding names (from the outermost scope).

This is useful for REPL persistence where we need to inform the bytecode compiler about bindings from previous sessions.

Source§

impl ExecutionContext

Source

pub fn new_with_registry( data: &DataFrame, type_method_registry: Arc<TypeMethodRegistry>, ) -> Self

Create a new execution context with shared type method registry

Source

pub fn new(data: &DataFrame) -> Self

Create a new execution context

Source

pub fn new_empty_with_registry( type_method_registry: Arc<TypeMethodRegistry>, ) -> Self

Create a new execution context without market data with shared registry

Source

pub fn new_empty() -> Self

Create a new execution context without market data

Source

pub fn with_data_provider_and_registry( data_provider: Arc<dyn Any + Send + Sync>, type_method_registry: Arc<TypeMethodRegistry>, ) -> Self

Create a new execution context with DuckDB provider and shared registry

Source

pub fn with_data_provider(data_provider: Arc<dyn Any + Send + Sync>) -> Self

Create a new execution context with DuckDB provider

Source

pub fn with_async_provider( provider: SharedAsyncProvider, runtime: Handle, ) -> Self

Create with async data provider (Phase 6)

This constructor sets up ExecutionContext with a DataCache for async data loading. Call prefetch_data() before executing to populate the cache.

Source

pub fn set_output_adapter(&mut self, adapter: Box<dyn OutputAdapter>)

Set the output adapter for print() handling

Source

pub fn output_adapter_mut(&mut self) -> &mut Box<dyn OutputAdapter>

Get mutable reference to output adapter

Source

pub fn metadata_registry(&self) -> &Arc<MetadataRegistry>

Get the metadata registry

Source

pub fn register_type_alias( &mut self, alias_name: &str, base_type: &str, overrides: Option<HashMap<String, ValueWord>>, )

Register a type alias for runtime meta resolution

Used when loading stdlib to make type aliases available for formatting. Example: type Percent4 = Percent { decimals: 4 }

Source

pub fn lookup_type_alias(&self, name: &str) -> Option<&TypeAliasRuntimeEntry>

Look up a type alias

Returns the base type name and any parameter overrides.

Source

pub fn resolve_type_for_format( &self, type_name: &str, ) -> (String, Option<HashMap<String, ValueWord>>)

Resolve a type name, following aliases if needed

If the type is an alias, returns (base_type, Some(overrides)) If not an alias, returns (type_name, None)

Source

pub fn snapshot(&self, store: &SnapshotStore) -> Result<ContextSnapshot>

Create a serializable snapshot of the dynamic execution state.

Source

pub fn restore_from_snapshot( &mut self, snapshot: ContextSnapshot, store: &SnapshotStore, ) -> Result<()>

Restore execution state from a snapshot.

Source

pub fn set_event_queue(&mut self, queue: SharedEventQueue)

Set indicator cache Set the event queue for async operations

Source

pub fn event_queue(&self) -> Option<&SharedEventQueue>

Get the event queue

Source

pub fn event_queue_mut(&mut self) -> Option<&mut SharedEventQueue>

Get mutable reference to event queue

Source

pub fn set_suspension_state(&mut self, state: SuspensionState)

Set suspension state (called when yielding/suspending)

Source

pub fn suspension_state(&self) -> Option<&SuspensionState>

Get suspension state

Source

pub fn clear_suspension_state(&mut self) -> Option<SuspensionState>

Clear suspension state (called when resuming)

Source

pub fn is_suspended(&self) -> bool

Check if execution is suspended

Source

pub fn set_alert_pipeline(&mut self, pipeline: Arc<AlertRouter>)

Set the alert pipeline for routing alerts to sinks

Source

pub fn alert_pipeline(&self) -> Option<&Arc<AlertRouter>>

Get the alert pipeline

Source

pub fn emit_alert(&self, alert: Alert)

Emit an alert through the pipeline

Source

pub fn set_progress_registry(&mut self, registry: Arc<ProgressRegistry>)

Set the progress registry for monitoring load operations

Source

pub fn progress_registry(&self) -> Option<&Arc<ProgressRegistry>>

Get the progress registry

Source

pub fn set_kernel_compiler(&mut self, compiler: Arc<dyn KernelCompiler>)

Set the JIT kernel compiler for high-performance simulation.

This enables JIT compilation of simulation kernels when the state is a TypedObject. The compiler should be an instance of shape_jit::JITCompiler wrapped in Arc.

Source

pub fn kernel_compiler(&self) -> Option<&Arc<dyn KernelCompiler>>

Get the JIT kernel compiler, if set.

Trait Implementations§

Source§

impl Clone for ExecutionContext

Source§

fn clone(&self) -> ExecutionContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExecutionContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more