From: Mark Wielaard <mark@klomp.org>
To: gcc-rust@gcc.gnu.org
Subject: union support
Date: Fri, 23 Jul 2021 01:19:00 +0200 [thread overview]
Message-ID: <20210722231902.7401-1-mark@klomp.org> (raw)
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
next reply other threads:[~2021-07-22 23:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-22 23:19 Mark Wielaard [this message]
2021-07-22 23:19 ` [PATCH 1/2] Better union support in the parser Mark Wielaard
2021-07-23 11:19 ` Philip Herron
2021-07-22 23:19 ` [PATCH 2/2] WIP union hir-lowering and type support Mark Wielaard
2021-07-23 11:19 ` Philip Herron
2021-08-01 11:29 ` Mark Wielaard
2021-08-01 22:37 ` Mark Wielaard
2021-08-02 12:33 ` Thomas Schwinge
2021-08-04 21:04 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210722231902.7401-1-mark@klomp.org \
--to=mark@klomp.org \
--cc=gcc-rust@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).