Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstValue::F64 and OpaqueOp::new #206

Merged
merged 3 commits into from
Jun 29, 2023
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
6 changes: 6 additions & 0 deletions src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum ConstValue {
value: HugrIntValueStore,
width: HugrIntWidthStore,
},
/// Double precision float
F64(f64),
/// A constant specifying a variant of a Sum type.
Sum {
tag: usize,
Expand Down Expand Up @@ -90,6 +92,8 @@ impl PartialEq for ConstValue {
) => tag == t1 && variants == type1 && val == v1,

(Self::Tuple(v1), Self::Tuple(v2)) => v1.eq(v2),
(Self::F64(f1), Self::F64(f2)) => f1 == f2,

_ => false,
}
}
Expand Down Expand Up @@ -122,12 +126,14 @@ impl ConstValue {
.collect();
ClassicType::Container(Container::Tuple(Box::new(row.into())))
}
Self::F64(_) => ClassicType::F64,
}
}
/// Unique name of the constant.
pub fn name(&self) -> SmolStr {
match self {
Self::Int { value, width } => format!("const:int<{width}>:{value}"),
Self::F64(f) => format!("const:float:{f}"),
Self::Opaque(_, v) => format!("const:{}", v.name()),
Self::Sum { tag, val, .. } => {
format!("const:sum:{{tag:{tag}, val:{}}}", val.name())
Expand Down
9 changes: 9 additions & 0 deletions src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub struct OpaqueOp {
}

impl OpaqueOp {
/// Initialize a new named OpaqueOp
pub fn new(id: impl Into<SmolStr>, custom: impl CustomOp) -> Self {
Self {
id: id.into(),

custom: Box::new(custom),
}
}

/// The name of the operation, cached for fast equality checks.
pub fn name(&self) -> SmolStr {
self.id.clone()
Expand Down