corrode
corrode copied to clipboard
Preliminary support for unions added.
This is really far from complete, but it starts addressing #22 by filling in everything straightforward. Here are the issues AFAICT
-
We cannot yet derive
Copy
andClone
for unions, but support for that is pending (incredibly fast given how recent an addition unions are!). -
We'll need to add
#![feature(untagged_unions)]
to the top of files (I don't think we currently have anything to do this - if we don't it'd be worth it to make it good). -
The can of worms that was struct initialization needs to be reopened. I'll take a look at the C99 spec. I'm hoping that when there are multiple (named) initializers in the initializer list for a union in C99, we simply ignore all except the last one (even if the previous ones are bigger), and at least clang seems to agree... I'm also hoping that the rust unions are also initialized with an extra empty space zeroed out. If all that works out as expected, I'll still need to find a nice way of expressing union based initializers - something like
data Initializer = StructInitializer (Maybe Rust.Expr) (IntMap.IntMap Initializer) = UnionInitializer Int Initializer
Is there anything else I'm missing here? I think there is something to do with incomplete types that you did for structs that also applies to unions. I'm thinking of this...
We cannot yet derive Copy and Clone for unions
FYI, Copy
can already be derived, it was a part of initial union implementation.
This build fails because one of the big changes that comes with this last commit (that adds what I think is complete support for union initialization) is that Initializer
no longer is a Monoid
but a Semigroup
instead. That means we'll need to add either semigroups
or base >= 4.9
to the cabal file, and currently I've done neither.
Personally I am in favour of the latter (if we are generating rust that only compiles on rust nightly, it seems fairly reasonably to say we run on GHC 8.0), but I'll leave the choice up to you.
@harpocrates Conflicting files