Enums

An enum type, short for enumeration, is a type that represents a number of distinct named values, each of which can optionally be represented by a specific numerical value. An instance of an enum represents a single of the enum's values.

Flags are a special sub-type of enums where each value is represented by a separate bit in the underlying storage, allowing for a flag instance to represent a single value or a combination of two or more values, using bitwise or.

An enum type is declared with the enum or flag keyword, followed by one or more value names in parentheses:

type
  Color = public enum(
    Red,   // implied 0
    Green, // implied 1
    Blue   // implied 2
  );

  Number = public enum
  (
    One = 1,
    Two = 2,
    Three = 3
  ) of Word;


  State = public flags
  (
    IsVisible,  // implied 1
    IsSelected, // implied 2
    IsHovered   // implied 4
  );

Each enum value can be assigned to a specific numerical representation. If no numerical representation is provided, the compiler will automatically assign consecutive numbers, starting at 0 and counting up in increments of 1 for enum types, and starting at 1 and shifting the bit to the left for flags types.

If a numerical representation is provided for some values but not all, the compiler will use the fixed values where provided, and increment (enums) or look for the next free higher bit (flags from there for subsequent values without explicit number).

By default, enums are stored at 32-bit numbers compatible with a UInt32 type. Optionally, a different integer storage type can be provided at the end of the declaration, using the of keyword. This can be used to size the enum smaller (Byte or Word) or larger (Int64).

Type Visibility

The visibility of an enum type can be controlled by applying a Visibility Modifier on the declaration. The default visibility is assembly.

Other Modifiers

Other modifiers do not apply to enums.