-
Notifications
You must be signed in to change notification settings - Fork 27
Description
In the text below, we consider the following Emboss definition:
enum OpCodeGroup:
# ...
FOO = 0x08
# ...
enum OpCodeCommand:
# ...
BAR = 0x0039
# ...
bits OpCode(group: UInt:6, command: UInt:10):
0 [+6] UInt ogf
6 [+10] UInt ocf
We would like to pass constant values to the group and command parameters of the OpCode type. We could store these values in virtual fields within the struct we are composing using the let keyword. However, these values are better placed inside the OpCodeGroup and OpCodeCommand enumerations, respectively. Doing so allows the values to be defined once across the entire codebase and made accessible within both Emboss and C++ code. The following situations arise here:
- If we use the
UInt:6andUInt:10types for parameters, the arguments must be hardcoded, and we no longer have a single definition of the constants across the codebase (they have to be defined elsewhere again) - If we use the enumeration types for both parameters and fields, Emboss generates an
EnumViewwhich doesn’t allow writes, makingogfandocfread only - If we use the enumeration types for the parameters and
UInttypes for the fields, adding a check like[requires: ogf == group && ocf == command]won’t compile because the types are different
For obvious reasons, we don’t want to use option 1 to hardcode constants. Enumerations shouldn’t be writable so option 2 makes sense as it is. In order to support this use case, Emboss should support cross-type integral equality as implied in option 2.
Potential Implementation
The .emb language syntax is updated to allow explicit int(Foo.Bar) conversions to allow for integral type coercion. We want to keep Emboss' strict type safety but want to be able to compare across only integral types.