
###################################################
#                                                 #
#  Integral classes:                              #
#                                                 #
#     uint         int                            #
#     ushort       short                          #
#     ubyte        byte                           #
#                                                 #
#  plus their boxed versions:                     #
#                                                 #
#     uint_ref     int_ref                        #
#     ushort_ref   short_ref                      #
#     ubyte_ref    byte_ref                       #
#                                                 #
###################################################

###################################################
#                                                 #
#  int                                            #
#                                                 #
###################################################

norename class int

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: int): int := builtin "int_add"(self, other)
  infix 28 -(other: int): int := builtin "int_sub"(self, other)
  prefix -: int := builtin "int_neg"(self)
  infix 32 *(other: int): int := builtin "int_mul"(self, other)
  infix 32 div(other: int): int := builtin "int_div"(self, other)
  infix 32 mod(other: int): int := builtin "int_mod"(self, other)

  # comparisons
  cmp(other: int): int := self - other
  infix 24 =(other: int): bool := builtin "int_eq"(self, other)
  infix 24 <>(other: int): bool := builtin "int_ne"(self, other)
  infix 24 <(other: int): bool := builtin "int_lt"(self, other)
  infix 24 <=(other: int): bool := builtin "int_le"(self, other)
  infix 24 >(other: int): bool := builtin "int_gt"(self, other)
  infix 24 >=(other: int): bool := builtin "int_ge"(self, other)

  # coercions
  coerce to_real: real := builtin "int_to_real"(self)
  coerce to_int_ref: int_ref := int_ref(self)

  # other conversions
  to_uint: uint := builtin "int_to_uint"(self)
  to_ushort: ushort := builtin "int_to_ushort"(self)
  to_ubyte: ubyte := builtin "int_to_ubyte"(self)
  to_short: short := builtin "int_to_short"(self)
  to_byte: byte := builtin "int_to_byte"(self)

predefined

  max_int := builtin "int_max"
  min_int := builtin "int_min"

end


###################################################
#                                                 #
#  int_ref                                        #
#                                                 #
###################################################

norename class int_ref

  coerce val: int

end


###################################################
#                                                 #
#  short                                          #
#                                                 #
###################################################

norename class short

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: short): short := builtin "short_add"(self, other)
  infix 28 -(other: short): short := builtin "short_sub"(self, other)
  prefix -: short := builtin "short_neg"(self)
  infix 32 *(other: short): short := builtin "short_mul"(self, other)
  infix 32 div(other: short): short := builtin "short_div"(self, other)
  infix 32 mod(other: short): short := builtin "short_mod"(self, other)

  # comparisons
  cmp(other: short): int := self.to_int - other.to_int
  infix 24 =(other: short): bool := builtin "short_eq"(self, other)
  infix 24 <>(other: short): bool := builtin "short_ne"(self, other)
  infix 24 <(other: short): bool := builtin "short_lt"(self, other)
  infix 24 <=(other: short): bool := builtin "short_le"(self, other)
  infix 24 >(other: short): bool := builtin "short_gt"(self, other)
  infix 24 >=(other: short): bool := builtin "short_ge"(self, other)

  # coercions
  coerce to_short_ref: short_ref := short_ref(self)
  coerce to_int: int := builtin "short_to_int"(self)

  # other conversions
  to_uint: uint := builtin "short_to_uint"(self)
  to_ushort: ushort := builtin "short_to_ushort"(self)
  to_ubyte: ubyte := builtin "short_to_ubyte"(self)
  to_byte: byte := builtin "short_to_byte"(self)

predefined

  max_short := builtin "short_max"
  min_short := builtin "short_min"

end


###################################################
#                                                 #
#  short_ref                                      #
#                                                 #
###################################################

norename class short_ref

  coerce val: short

end


###################################################
#                                                 #
#  byte                                           #
#                                                 #
###################################################

norename class byte

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: byte): byte := builtin "byte_add"(self, other)
  infix 28 -(other: byte): byte := builtin "byte_sub"(self, other)
  prefix -: byte := builtin "byte_neg"(self)
  infix 32 *(other: byte): byte := builtin "byte_mul"(self, other)
  infix 32 div(other: byte): byte := builtin "byte_div"(self, other)
  infix 32 mod(other: byte): byte := builtin "byte_mod"(self, other)

  # comparisons
  cmp(other: byte): int := self.to_int - other.to_int
  infix 24 =(other: byte): bool := builtin "byte_eq"(self, other)
  infix 24 <>(other: byte): bool := builtin "byte_ne"(self, other)
  infix 24 <(other: byte): bool := builtin "byte_lt"(self, other)
  infix 24 <=(other: byte): bool := builtin "byte_le"(self, other)
  infix 24 >(other: byte): bool := builtin "byte_gt"(self, other)
  infix 24 >=(other: byte): bool := builtin "byte_ge"(self, other)

  # coercions
  coerce to_byte_ref: byte_ref := byte_ref(self)
  coerce to_short: short := builtin "byte_to_short"(self)

  # other conversions
  to_uint: uint := builtin "byte_to_uint"(self)
  to_ushort: ushort := builtin "byte_to_ushort"(self)
  to_ubyte: ubyte := builtin "byte_to_ubyte"(self)
  to_int: int := builtin "byte_to_int"(self)

predefined

  max_byte := builtin "byte_max"
  min_byte := builtin "byte_min"

end


###################################################
#                                                 #
#  byte_ref                                       #
#                                                 #
###################################################

norename class byte_ref

  coerce val: byte

end


###################################################
#                                                 #
#  uint                                           #
#                                                 #
###################################################

norename class uint

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: uint): uint := builtin "uint_add"(self, other)
  infix 28 -(other: uint): uint := builtin "uint_sub"(self, other)
  infix 32 *(other: uint): uint := builtin "uint_mul"(self, other)
  infix 32 div(other: uint): uint := builtin "uint_div"(self, other)
  infix 32 mod(other: uint): uint := builtin "uint_mod"(self, other)

  # comparisons
  cmp(other: uint): int := self.to_int - other.to_int
  infix 24 =(other: uint): bool := builtin "uint_eq"(self, other)
  infix 24 <>(other: uint): bool := builtin "uint_ne"(self, other)
  infix 24 <(other: uint): bool := builtin "uint_lt"(self, other)
  infix 24 <=(other: uint): bool := builtin "uint_le"(self, other)
  infix 24 >(other: uint): bool := builtin "uint_gt"(self, other)
  infix 24 >=(other: uint): bool := builtin "uint_ge"(self, other)

  # coercions
  coerce to_int: int := builtin "uint_to_int"(self)
  coerce to_real: real := builtin "uint_to_real"(self)
  coerce to_uint_ref: uint_ref := uint_ref(self)

  # other conversions
  to_ushort: ushort := builtin "uint_to_ushort"(self)
  to_ubyte: ubyte := builtin "uint_to_ubyte"(self)
  to_short: short := builtin "uint_to_short"(self)
  to_byte: byte := builtin "uint_to_byte"(self)

predefined

  max_uint := builtin "uint_max"

end


###################################################
#                                                 #
#  uint_ref                                       #
#                                                 #
###################################################

norename class uint_ref

  coerce val: uint

end


###################################################
#                                                 #
#  ushort                                         #
#                                                 #
###################################################

norename class ushort

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: ushort): ushort := builtin "ushort_add"(self, other)
  infix 28 -(other: ushort): ushort := builtin "ushort_sub"(self, other)
  infix 32 *(other: ushort): ushort := builtin "ushort_mul"(self, other)
  infix 32 div(other: ushort): ushort := builtin "ushort_div"(self, other)
  infix 32 mod(other: ushort): ushort := builtin "ushort_mod"(self, other)

  # comparisons
  cmp(other: ushort): int := self.to_int - other.to_int
  infix 24 =(other: ushort): bool := builtin "ushort_eq"(self, other)
  infix 24 <>(other: ushort): bool := builtin "ushort_ne"(self, other)
  infix 24 <(other: ushort): bool := builtin "ushort_lt"(self, other)
  infix 24 <=(other: ushort): bool := builtin "ushort_le"(self, other)
  infix 24 >(other: ushort): bool := builtin "ushort_gt"(self, other)
  infix 24 >=(other: ushort): bool := builtin "ushort_ge"(self, other)

  # coercions
  coerce to_short: short := builtin "ushort_to_short"(self)
  coerce to_ushort_ref: ushort_ref := ushort_ref(self)
  coerce to_uint: uint := builtin "ushort_to_uint"(self)

  # other conversions
  to_ubyte: ubyte := builtin "ushort_to_ubyte"(self)
  to_int: int := builtin "ushort_to_int"(self)
  to_byte: byte := builtin "ushort_to_byte"(self)

predefined

  max_ushort := builtin "ushort_max"

end


###################################################
#                                                 #
#  ushort_ref                                     #
#                                                 #
###################################################

norename class ushort_ref

  coerce val: ushort

end


###################################################
#                                                 #
#  ubyte                                          #
#                                                 #
###################################################

norename class ubyte

  builtin

noncreation

  # arithmetic operations
  infix 28 +(other: ubyte): ubyte := builtin "ubyte_add"(self, other)
  infix 28 -(other: ubyte): ubyte := builtin "ubyte_sub"(self, other)
  infix 32 *(other: ubyte): ubyte := builtin "ubyte_mul"(self, other)
  infix 32 div(other: ubyte): ubyte := builtin "ubyte_div"(self, other)
  infix 32 mod(other: ubyte): ubyte := builtin "ubyte_mod"(self, other)

  # comparisons
  cmp(other: ubyte): int := self.to_int - other.to_int
  infix 24 =(other: ubyte): bool := builtin "ubyte_eq"(self, other)
  infix 24 <>(other: ubyte): bool := builtin "ubyte_ne"(self, other)
  infix 24 <(other: ubyte): bool := builtin "ubyte_lt"(self, other)
  infix 24 <=(other: ubyte): bool := builtin "ubyte_le"(self, other)
  infix 24 >(other: ubyte): bool := builtin "ubyte_gt"(self, other)
  infix 24 >=(other: ubyte): bool := builtin "ubyte_ge"(self, other)

  # coercions
  coerce to_ubyte_ref: ubyte_ref := ubyte_ref(self)
  coerce to_ushort: ushort := builtin "ubyte_to_ushort"(self)
  coerce to_byte: byte := builtin "ubyte_to_byte"(self)

  # other conversions
  to_uint: uint := builtin "ubyte_to_uint"(self)
  to_int: int := builtin "ubyte_to_int"(self)
  to_short: short := builtin "ubyte_to_short"(self)

predefined

  max_ubyte := builtin "ubyte_max"

end


###################################################
#                                                 #
#  ubyte_ref                                      #
#                                                 #
###################################################

norename class ubyte_ref

  coerce val: ubyte

end
