PreviousUpNext

10.2.3  Integer Constants

Decimal integer constants consist an optional negative sign, a nonzero digit, and optionally more decimal digits, the first not being zero. In regular expression terms:

    -?[1-9][0-9]*

Examples:

     1
    12
   -12

Octal constants begin with a zero digit:

       0        # Zero. Technically octal not decimal, not that it matters.
     010        # Decimal eight.  
    0100        # Decimal sixty-four.

Hex constants begin with a 0x. Alphabetic digits may be upper or lower case:

     0xa        # Decimal ten.
     0xA        # Decimal ten.
    0x10        # Decimal sixteen.
   0x100        # Decimal two hundred fifty six.

Unsigned decimal constants are written with a 0u prefix:

     0u1        # Unsigned one.
    0u10        # Unsigned ten.
   0u100        # Unsigned one hundred.

Unsigned hexadecimal constants are written with a 0ux prefix:

    0ux1        # Unsigned one.
   0ux10        # Unsigned sixteen.
  0ux100        # Unsigned two hundred fifty six.

The compiler uses type inference to determine the type of an integer constant. This is done in src/lib/compiler/front/typer/types/resolve-overloaded-literals.pkg.

Signed integers may be assigned to any of the types:

    tagged_int::Int          # The default, and the most common.
    one_word_int::Int          # 32-bit integer.
    two_word_int::Int          # 64-bit integer.
    multiword_int::Int        # Indefinite precision.

If type inference does not yield a type for the constant it defaults to tagged_int::Int.

Unsigned integers may be assigned to any of the types:

    tagged_unt::Unt          # The default, and the most common.
    one_byte_unt::Unt           #  8-bit unsigned integer.
    one_word_unt::Unt          # 32-bit unsigned integer.
    two_word_unt::Unt          # 64-bit unsigned integer.

If type inference does not yield a type for the constant it defaults to tagged_unt::Unt.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext