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

Add support for generics on component portmapping & add Natural and Positive types #27

Open
wants to merge 5 commits into
base: stdlib/develop
Choose a base branch
from

Conversation

jobtijhuis
Copy link

The support for generics takes the parameters from a component and adds them to the portmapping as generics.

The Natural and Positive types are only meant to be used for generics because calculating the width of these types has not been implemented.

Copy link

@mbrobbel mbrobbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some generic comments and questions. I think the best way forward is to merge this with approval from @matthijsr and @johanpel, because they know a lot more about the details and goals of both this PR and the code it targets.

Comment on lines +113 to +114
/// Natural integer as defined by VHDL.
pub type Natural = NonNegative;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move this type def to the vhdl generator module. What do you think?

Comment on lines +169 to +180
if let ObjectType::Natural = typ {
Ok(())
}
// Positive can be assigned to natural but not the other way around
else if let ObjectType::Positive = typ {
Ok(())
} else {
Err(Error::InvalidTarget(format!(
"Cannot assign {} to Natural",
typ
)))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let ObjectType::Natural = typ {
Ok(())
}
// Positive can be assigned to natural but not the other way around
else if let ObjectType::Positive = typ {
Ok(())
} else {
Err(Error::InvalidTarget(format!(
"Cannot assign {} to Natural",
typ
)))
}
matches!(typ, ObjectType::Natural | ObjectType::Positive)
.then(|| ())
.ok_or_else(|| Error::InvalidTarget(format!("Cannot assign {} to Positive", typ)));

if let ObjectType::Positive = typ {
Ok(())
} else {
// Natural can not be assigned to positive because positive does not include 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add this comment to the error message. What do you think?

src/stdlib/common/architecture/object/mod.rs Outdated Show resolved Hide resolved
src/stdlib/common/architecture/statement/mod.rs Outdated Show resolved Hide resolved
jobtijhuis and others added 2 commits November 30, 2021 17:29
Co-authored-by: Matthijs Brobbel <m1brobbel@gmail.com>
Co-authored-by: Matthijs Brobbel <m1brobbel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants