-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Refactor Type::Aggregate #12
Conversation
And thanks to Rust, it also adds lifetimes everywhere
69cc54c
to
fc009ab
Compare
Works like a charm! While trying this out I also wrote one more test, just to get a hang of it: #[test]
fn type_size_nested_aggregate() {
let inner = TypeDef {
name: "dog".into(),
align: None,
items: vec![(Type::Long, 2)],
};
let inner_aggregate = Type::Aggregate(&inner);
assert!(inner_aggregate.size() == 16);
let typedef = TypeDef {
name: "person".into(),
align: None,
items: vec![(Type::Long, 1), (Type::Word, 2), (Type::Byte, 1), (Type::Aggregate(&inner), 1)],
};
let aggregate = Type::Aggregate(&typedef);
assert!(aggregate.size() == 33);
} I don't think I can push to this branch, as it lives in your fork. Do you mind adding this, alongside the Changelog entry? |
Nevermind, I think I am able to push to your fork. I'll finish this up. Thanks! |
b074996
to
91ac0bc
Compare
we forgot about alignment |
How would that affect the size? Probably just has to be added to the sum of the size, right? |
Yes, every item in a typedef has to be extended so that it's dividable by the alignment (or by default, non-aligned size of largest item). |
Description
Aggregate types weren't implemented quite right and caused various problems like
Type.size()
being broken. NowType::Aggregate
takes a reference to aTypeDef
object, which it can use to calculate the size and assert correctness of the generated code because it would be a violation of Rust's rules to have an aggregate without a corresponding definition.ToDo