-
Notifications
You must be signed in to change notification settings - Fork 82
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
Provide values for enums/constants #365
Comments
Hi, this is a good question so thanks for filing an issue and sorry for the slow reply (last week was the in-person CG meeting)! So coincidentally, with the recently-merged #336, I think we have a Component Model primitive that matches what you're describing. In particular, when defining an interface, in WAT I can write:
#336 didn't add WIT-level syntax to capture this new functionality, but we should before too long, and so you could imagine that in WIT you can write something like:
Now, an obvious improvement that you might want is a more direct typed connection between
and a C code generator can generate |
I would also argue that integer mappings of enum values are not an interface concern but one of lowering to a specific language, and only for those languages that actually expose enums as ints in the first place. |
Yeah, I think that's why we should consider this entirely separate from |
I agree that if you set values in enums, it is not a enum longer and they should not be extended this way. |
Did the middle code snippet in my first comment make sense, or were you imagining something else? |
Yes, absolutely. Maybe even "u32 bar: 42", so we have control over types sizes. |
Oops, yes, you're right; the type would be necessary as part of the value definition in the WIT too. |
When using WIT to describe some existing interface, it is sometimes required
to have enums with specific values. But there is no way to express this in WIT
currently.
Think of bitflags,for example:
we have something simple like this (C)
Or your function returns NEGATIVE constants (ERR_X = -1, ERR_Y =-33, ERR_Z = -22)
Or maybe your interface has some magic constants like MY_BETTER_PI=3.44 that needs to be passed around
or may be returned from functions.
I understand that WIT is about TYPES, but plain types are just not enough to describe an interface.
Because currently WIT definition is the only point where your host application can provide this data
to unknown number of its clients in unknown to the host languages.
Otherwise, we are back to days when we had to parse C includes to be able to use FFI.
The text was updated successfully, but these errors were encountered: