Hi,
I have been playing with union support which was mostly missing. union
is slightly odd because it is a weak keyword, so it can be used as a
"normal" identifier and is only special when defining a union
type. Which means you can have programs like:
union union { union: u32, funion: f32 }
pub fn main ()
{
let union = union { union: 1 };
let _u = unsafe { union.union };
let _f = unsafe { union.funion; };
}
Here are two patches to support the above (partially).
Also on https://code.wildebeest.org/git/user/mjw/gccrs/log/?h=union
The first fixes up the parser and should be good to go.
[PATCH 1/2] Better union support in the parser
The second provides lowering to HIR and type checking support. This
is mostly cargo culting existing code for structs and tuple struct. It
seems to work, but I cannot say I fully understand what I am doing.
[PATCH 2/2] WIP union hir-lowering and type support
Currently this will eventually crash when trying to generate code in
Gcc_backend::constructor_expression because we try to emit code for a
struct with multiple fields, but the union doesn't have real fields,
just multiple variants.
Hopefully this is somewhat useful. Feedback on how to proceed and/or
how to get a better design (it seems a good idea to treat a union as
much as possible as a struct/tuple variant, but maybe there is a
better way) is very welcome.
Thanks,
Mark
--
Gcc-rust mailing list
[email protected]
https://gcc.gnu.org/mailman/listinfo/gcc-rust