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

Construct Types #217

Merged
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
16 changes: 9 additions & 7 deletions src/types/final_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,33 @@ impl<'a> DagLike for &'a Final {
}

impl Final {
/// (Non-public) constructor for the final data of the unit type
pub(crate) fn unit() -> Arc<Self> {
/// Create the unit type.
pub fn unit() -> Arc<Self> {
Arc::new(Final {
bound: CompleteBound::Unit,
bit_width: 0,
tmr: Tmr::unit(),
})
}

/// Return a precomputed copy of 2^(2^n), for given n.
/// Create the type `2^(2^n)` for the given `n`.
///
/// The type is precomputed and fast to access.
pub fn two_two_n(n: usize) -> Arc<Self> {
super::precomputed::nth_power_of_2(n).final_data().unwrap()
}

/// (Non-public) constructor for the final data of a sum type
pub(crate) fn sum(left: Arc<Self>, right: Arc<Self>) -> Arc<Self> {
/// Create the sum of the given `left` and `right` types.
pub fn sum(left: Arc<Self>, right: Arc<Self>) -> Arc<Self> {
Arc::new(Final {
tmr: Tmr::sum(left.tmr, right.tmr),
bit_width: 1 + cmp::max(left.bit_width, right.bit_width),
bound: CompleteBound::Sum(left, right),
})
}

/// (Non-public) constructor for the final data of a product type
pub(crate) fn product(left: Arc<Self>, right: Arc<Self>) -> Arc<Self> {
/// Create the product of the given `left` and `right` types.
pub fn product(left: Arc<Self>, right: Arc<Self>) -> Arc<Self> {
Arc::new(Final {
tmr: Tmr::product(left.tmr, right.tmr),
bit_width: left.bit_width + right.bit_width,
Expand Down
18 changes: 10 additions & 8 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,24 +371,26 @@ impl Type {
Type::from(Bound::free(name))
}

/// Return a unit type.
/// Create the unit type.
pub fn unit() -> Self {
Type::from(Bound::unit())
}

/// Return a precomputed copy of 2^(2^n), for given n.
/// Create the type `2^(2^n)` for the given `n`.
///
/// The type is precomputed and fast to access.
pub fn two_two_n(n: usize) -> Self {
precomputed::nth_power_of_2(n)
}

/// Return the sum of the given two types.
pub fn sum(a: Self, b: Self) -> Self {
Type::from(Bound::sum(a, b))
/// Create the sum of the given `left` and `right` types.
pub fn sum(left: Self, right: Self) -> Self {
Type::from(Bound::sum(left, right))
}

/// Return the product of the given two types.
pub fn product(a: Self, b: Self) -> Self {
Type::from(Bound::product(a, b))
/// Create the product of the given `left` and `right` types.
pub fn product(left: Self, right: Self) -> Self {
Type::from(Bound::product(left, right))
}

/// Clones the `Type`.
Expand Down
Loading