Type System

    Cyrus features a strong and expressive type system. The compiler performs implicit type conversions when it is safe, and requires explicit casts when conversions could be unsafe or lossy.

    Safe Implicit Casting

    If a type can be safely converted to another type without losing information, Cyrus will perform the conversion automatically.

    var a: int32 = 42;
    var b: int64 = a; // implicit cast from int32 to int64
    
    • int32 (32-bit signed integer) can always fit into int64 (64-bit signed integer).
    • The compiler handles this implicitly, so no special syntax is required.

    Unsafe / Explicit Casting

    If a conversion could be unsafe, the compiler requires an explicit cast using the cast keyword.

    var u: uint32 = 10;
    var i: int64 = @cast(int64, u); // Explicit unsafe cast from uint32 to int64.
    

    Basic Types

    Cyrus provides a set of built-in types for numbers, characters, booleans, and special-purpose values. These are the fundamental building blocks of your programs.

    TypeCategoryBit WidthSignedness
    intSigned Integer (default)32Signed
    int8Signed Integer8Signed
    int16Signed Integer16Signed
    int32Signed Integer32Signed
    int64Signed Integer64Signed
    int128Signed Integer128Signed
    uintUnsigned Integer (default)32Unsigned
    uint8Unsigned Integer8Unsigned
    uint16Unsigned Integer16Unsigned
    uint32Unsigned Integer32Unsigned
    uint64Unsigned Integer64Unsigned
    uint128Unsigned Integer128Unsigned
    intptrPointer-sized IntegerPointer widthSigned
    uintptrPointer-sized IntegerPointer widthUnsigned
    usizeSize / Index TypePointer widthUnsigned
    isizeSize / Index TypePointer widthSigned

    Floating-Point Types

    TypeDescriptionPrecision
    float1616-bit floating-point number (half precision)~3 decimal digits
    float3232-bit floating-point number (single precision)~7 decimal digits
    float6464-bit floating-point number (double precision)~15–16 decimal digits
    float128128-bit floating-point number (quadruple precision)~34 decimal digits

    Character and Boolean Types

    TypeDescriptionNotes
    char

    A single character unit (one code unit; multi-byte Unicode not allowed in '...').

    Unsigned; Represents ASCII/byte chars only

    bool

    Boolean values, either true or false.

    1-bit storage (typically padded to 8 bits)

    Special Types

    TypeDescriptionNotes
    void

    Represents no value, commonly used for functions that do not return anything.

    Return type only

    Type Aliases

    You can create aliases for existing types. The compiler automatically expands these whenever the alias is used.

    type rune = uint32;
    type my_int = int16;
    
    pub fn main() {
      const x: rune = 10;
      const y: my_int = 20;
    }
    

    Note: Type aliases cannot be declared locally. Their scope and declaration rules will be covered in more detail later in these documents.