This repository was archived by the owner on Jun 16, 2021. It is now read-only.
Add enum typeinfos #73
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Merge branch 'add-enum-typeinfos'
This introduces type information for enum types.
The ion program can now know that a type is an enum, and what is its base
type and size as well as the values of available constants in the enum
(see enum_items and num_enum_items)
This allows user programs to print the friendly enumeration constant
associated with a value, or validate that a value is a legal one.
The name of the constant is the external C name, i.e. as mangled into
the C symbols, similarly to how type names are also introspected. This
guarantees unicity, however means that a ion program looking to generate
new ion programs would have to reverse the manging somehow. The same issue
is true for existing type names however.
Note that this creates a distinction between enum constants and plain
constants: enum constants are known to the program and can be shared
outside. This matches my experience of using enumerations in applications.
Initially I wanted to supply sorted arrays for an enumeration type by
ame and value, to make lookups more efficient. However to do this at
compile time would necessitate the ion compiler to evaluate the enum
expression. Right now the value of the expression is only known to the ion program
(after the C compiler has done its job)
So fast lookups (sub-O(n)) for large enumerations will have to be done by hand in
the ion program using raw type infos for now.