Add pipeline generator registration

Introduce a new field to `Environment` to store a list of pipeline
generator functions.
Add a `run_pipeline` method to `Environment` that iterates through and
executes all registered generators until they are exhausted.
Implement `ObservableStream` trait for `RootStream` and `PipeStream`.
Add a `StreamNode` wrapper for `ObservableStream` to be used as a script
object.
Register `create-random-ohlc` as a native function that creates a
`RootStream`, sets up a OHLC record layout, and registers a stateful
generator closure in the environment's pipeline generators.
This commit is contained in:
Michael Schimmel
2026-03-01 22:18:52 +01:00
parent 50f33b2c30
commit 2579e2b1fd
3 changed files with 181 additions and 1 deletions
+16
View File
@@ -33,6 +33,7 @@ pub struct Environment {
pub debug_mode: bool,
pub optimization: bool,
pub macro_registry: Rc<RefCell<MacroRegistry>>,
pub pipeline_generators: Rc<RefCell<Vec<Box<dyn FnMut() -> bool>>>>,
}
struct EnvFunctionRegistry {
@@ -106,6 +107,7 @@ impl Environment {
debug_mode: false,
optimization: true,
macro_registry: Rc::new(RefCell::new(MacroRegistry::new())),
pipeline_generators: Rc::new(RefCell::new(Vec::new())),
};
env.register_stdlib();
env
@@ -115,6 +117,20 @@ impl Environment {
self.debug_mode = enabled;
}
/// Pumps data through all registered pipeline generators until they are exhausted.
pub fn run_pipeline(&self) {
let mut generators = self.pipeline_generators.borrow_mut();
let mut any_active = true;
while any_active {
any_active = false;
for generator in generators.iter_mut() {
if generator() {
any_active = true;
}
}
}
}
fn get_expander(&self) -> MacroExpander<RuntimeMacroEvaluator> {
let evaluator = RuntimeMacroEvaluator {
global_names: self.global_names.clone(),