Skip to content
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

Bitflag literals? #14

Open
kiedtl opened this issue Sep 11, 2024 · 0 comments
Open

Bitflag literals? #14

kiedtl opened this issue Sep 11, 2024 · 0 comments
Labels
lang-new New language feature proposal

Comments

@kiedtl
Copy link
Owner

kiedtl commented Sep 11, 2024

Would be nice to be able to specify a bitflag literal, where the bitflag is derived from an enum.

This would be useful, for example, when specifying opcode modes for inline assembly. Currently the (asm) builtin takes a string, e.g. (asm "gr" .Op/Oadd), which would be more consistent as an enum. Defining an enum to carry all possible variations of the flags (grk, gkr, srk, k, kr, etc) would be tedious, though, which is where flags would help.

This could be done with a (flags) builtin: (flags <type> <enum literals>...). No compile-time checking would be done on the enum to ensure it makes sense to use it in that context, that would be the user's responsibility.

Example:

(asm (flags OpFl g r k) .Op/Opop)
(asm (flags OpFl s r) .Op/Osub)
(asm .OpFl/g .Op/Oadd) // Single flag would just be the enum literal itself

To be more concise, perhaps (| ...) could be used instead:

(asm (| OpFl g r k) .Op/Opop)
(asm (| OpFl s r) .Op/Osub)

Or if we really wanted to be concise, just drop the idea of adding a builtin and add a dedicated syntax instead:

(asm .OpFl/g|r|k .Op/Opop)
(asm .OpFl/s|r .Op/Osub)

Though I don't really like the idea of adding yet more symbol soup to the language -- it already has quite enough in my opinion.

@kiedtl kiedtl added the lang-new New language feature proposal label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-new New language feature proposal
Projects
None yet
Development

No branches or pull requests

1 participant