Aug 13, 2022Kuina-chan


This is the language specification 6 of Kuin Programming Language, and is about enums.

1Kuin Enumerated Type

In Kuin, an enumerated type is defined as shown in Table 1-1.
Table 1-1: Enumerated Type Definition

enum Name
    Element Name 1
    Element Name 2
    Element Name 3 :: Element Value
    ...
end enum

Each element of an enumerated type has a value of type int, and when cast to another type, it becomes the value of that type. The value of the element can be specified explicitly, or it can be omitted.
The specification of the enumerated type is shown in Figure 1-1.
  • The value of the element must be Compile-time Constant.
  • The value of an element must not overlap with the value of any other element.
  • If the value of the element is not explicitly specified, it will be set in order from the top, starting from 0, 1, 2, 3, ..., and increasing by 1.
  • If the value of an element is explicitly specified, it will be set to the specified value; if it is not specified after that, it will be set starting from that value and increasing by 1.
Figure 1-1: Enumerated Type Specification
To refer to an element of an enumerated type in an expression, write "%element name" (Figure 1-2).
  1. enum Color
  2.   red
  3.   green
  4.   blue
  5. end enum
  6.  
  7. func main()
  8.   var color: @Color :: %red
  9. end func
Figure 1-2: Example Of Enumerated Type
1660379634enf