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

Custom field type annotations #9

Open
Seelengrab opened this issue Jun 7, 2023 · 2 comments
Open

Custom field type annotations #9

Seelengrab opened this issue Jun 7, 2023 · 2 comments
Labels
feature New feature

Comments

@Seelengrab
Copy link
Owner

This would look like a regular field type annotation for exact sizes (i.e. a::UInt16), or like e.g. a:3::UInt16 for objects that want to store the lower 3 bits of an UInt16 and want to get that type back out when accessing the field.

Due to the nature of how these objects are stored internally, the types will need to be at least isbitstype, possibly even isprimitivetype, as it's unclear whether the padding potentially contained in an isbitstype is legal to observe (I suspect it isn't).

<: Signed types will need to be at least 2 bits in size, to store the sign bit.

@Seelengrab Seelengrab added the feature New feature label Jun 7, 2023
@Seelengrab
Copy link
Owner Author

One decision that needs to be made here is whether the additional bit for <: Signed should be implicit or explicit.

@Seelengrab
Copy link
Owner Author

Ok, there are three points I've come up with:

  • isprimitivetype is the simplest to implement, should be straightforward
  • immutable structs ought to be possible too, if I'm ok with lying to the compiler and having Expr(:new) outside of a constructor for an object
  • mutable structs (both outside of FieldFlags.jl and those defined by FieldFlags.jl) won't work, because the additional indirection for a.b.c = 3 won't be able to store the result of b.c = 3 back into a.

So only immutable things can be stored nested, which makes sense if you think about what these objects then tend to represent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant