Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 46 additions & 2 deletions crates/taurus-core/src/handler/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,56 @@ use tucana::shared::value::Kind;
use tucana::shared::{ListValue, NumberValue, Struct, Value};

use crate::value::{number_to_f64, number_to_i64_lossy};
use std::fmt;
use tucana::shared::SubFlowSetting;

#[derive(Clone)]
pub struct FunctionThunk {
pub identifier: String,
pub parameter_index: i64,
pub settings: Vec<SubFlowSetting>,
}

impl fmt::Debug for FunctionThunk {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FunctionThunk")
.field("identifier", &self.identifier)
.field("parameter_index", &self.parameter_index)
.field("settings_len", &self.settings.len())
.finish()
}
}

#[derive(Clone)]
pub enum Thunk {
Node(i64),
Function(FunctionThunk),
}

impl fmt::Debug for Thunk {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Thunk::Node(node_id) => write!(f, "{}", node_id),
Thunk::Function(function) => function.fmt(f),
}
}
}

impl Thunk {
pub fn trace_target(&self) -> String {
match self {
Thunk::Node(node_id) => format!("node={}", node_id),
Thunk::Function(function) => format!("function={}", function.identifier),
}
}
}

#[derive(Clone, Debug)]
pub enum Argument {
/// Eager value that can be consumed immediately by a handler.
Eval(Value),
/// Deferred node execution handle, evaluated by calling `run(node_id)`.
Thunk(i64),
/// Deferred execution handle, evaluated by calling `run(thunk)`.
Thunk(Thunk),
}

#[derive(Clone, Copy, Debug)]
Expand Down
12 changes: 7 additions & 5 deletions crates/taurus-core/src/handler/registry.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
//! Runtime handler registry and callable function signatures.

use crate::handler::argument::{Argument, ParameterNode};
use crate::handler::argument::{Argument, ParameterNode, Thunk};
use crate::runtime::execution::value_store::ValueStore;
use crate::runtime::functions::ALL_FUNCTION_SETS;
use crate::types::signal::Signal;
use std::collections::HashMap;

/// Handler function type.
/// - For eager params, the executor will already convert them to Argument::Eval(Value).
/// - For lazy params, the executor will pass Argument::Thunk(node_id).
/// - If a handler wants to execute a lazy arg, it calls run(node_id).
pub type HandlerFn = fn(
/// - For lazy params, the executor will pass Argument::Thunk(thunk).
/// - If a handler wants to execute a lazy arg, it calls run(thunk).
pub type ThunkRunner<'runner> = dyn FnMut(&Thunk, &mut ValueStore) -> Signal + 'runner;

pub type HandlerFn = for<'runner> fn(
args: &[Argument],
ctx: &mut ValueStore,
run: &mut dyn FnMut(i64, &mut ValueStore) -> Signal,
run: &mut ThunkRunner<'runner>,
) -> Signal;

#[derive(Clone, Copy)]
Expand Down
Loading
Loading