use hugr_core::{HugrView, Node, ops::OpType};
use inkwell::values::BasicValueEnum;
use crate::utils::fat::FatNode;
use super::func::RowPromise;
pub struct EmitOpArgs<'c, 'hugr, OT, H> {
pub node: FatNode<'hugr, OT, H>,
pub inputs: Vec<BasicValueEnum<'c>>,
pub outputs: RowPromise<'c>,
}
impl<'hugr, OT, H> EmitOpArgs<'_, 'hugr, OT, H> {
#[must_use]
pub fn node(&self) -> FatNode<'hugr, OT, H> {
self.node
}
}
impl<'c, 'hugr, H: HugrView<Node = Node>> EmitOpArgs<'c, 'hugr, OpType, H> {
pub fn try_into_ot<OT>(self) -> Result<EmitOpArgs<'c, 'hugr, OT, H>, Self>
where
for<'a> &'a OpType: TryInto<&'a OT>,
{
let EmitOpArgs {
node,
inputs,
outputs,
} = self;
match node.try_into_ot() {
Some(new_node) => Ok(EmitOpArgs {
node: new_node,
inputs,
outputs,
}),
None => Err(EmitOpArgs {
node,
inputs,
outputs,
}),
}
}
pub fn into_ot<OTInto: PartialEq + 'c>(self, ot: &OTInto) -> EmitOpArgs<'c, 'hugr, OTInto, H>
where
for<'a> &'a OpType: TryInto<&'a OTInto>,
{
let EmitOpArgs {
node,
inputs,
outputs,
} = self;
EmitOpArgs {
node: node.into_ot(ot),
inputs,
outputs,
}
}
}