use indexmap::IndexSet;
use toasty_core::stmt;
use crate::engine::{
eval, exec,
mir::{self, LogicalPlan},
};
#[derive(Debug)]
pub(crate) struct Guard {
pub(crate) input: mir::NodeId,
pub(crate) guard_inputs: IndexSet<mir::NodeId>,
pub(crate) guard: eval::Func,
pub(crate) ty: stmt::Type,
}
impl Guard {
pub(crate) fn to_exec(
&self,
logical_plan: &LogicalPlan,
node: &mir::Node,
var_table: &mut exec::VarDecls,
) -> exec::Guard {
let input = logical_plan[self.input].var.get().unwrap();
let guard_inputs = self
.guard_inputs
.iter()
.map(|id| logical_plan[id].var.get().unwrap())
.collect();
let var = var_table.register_var(node.ty().clone());
node.var.set(Some(var));
exec::Guard {
input,
guard_inputs,
output: exec::Output {
var,
num_uses: node.num_uses.get(),
},
guard: self.guard.clone(),
}
}
}
impl From<Guard> for mir::Node {
fn from(value: Guard) -> Self {
mir::Operation::Guard(value).into()
}
}