-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: stdlib/develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
/// Natural integer as defined by VHDL. | ||
pub type Natural = NonNegative; |
There was a problem hiding this comment.
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?
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 | ||
))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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?
Co-authored-by: Matthijs Brobbel <[email protected]>
Co-authored-by: Matthijs Brobbel <[email protected]>
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.