Skip to content

Language specification

goubermouche edited this page Feb 1, 2024 · 4 revisions

Warning: The following page contains an unfinished and incomplete language specification for the Sigma programming language.

Data types

The sigma language separates individual types into the following key sections:

Integral data types

Sigma defines several integral data types, each of them can be declared by either a decimal, hexadecimal, or a binary literal:

// decimal
i32 a = 123;          // 123
i32 b = -123;         // -123
i32 c = 123_000_123;  // 123000123
i32 d = -123_000_123; // -123000123

// hexadecimal
i32 e = 0x12;         // 18
i32 f = 0xffff;       // 65535

// binary
i32 g = 0b011111;     // 31
i32 h = 0b1;          // 1

Signed integers:

Represent a signed integer of the specified bit-width. Once an overflow/underflow of a signed literal is detected, the value is rotated around. The following types are declared:

Typename Min Max
i8 -128 127
i16 -32768 32767
i32 -2147483648 2147483647
i64 -9223372036854775808 9223372036854775807

Unsigned integers:

Represent a signed integer of the specified bit-width. Once an overflow of an unsigned literal is detected, the value is modulated by the max value of the relevant type. The following types are declared:

Typename Min Max
u8 0 255
u16 0 65535
u32 0 4294967295
u64 0 18446744073709551615

Booleans:

The Sigma language also provides a boolean type - bool, which is represented by an 8-bit unsigned value. Values which are equal to 0 are always interpreted as a falsy value, and non-zero values as truthy. Additionally, a boolean value can be represented by either a boolean literal (true or false), or by a numerical literal. Boolean literals are additionally implicitly convertible to numbers - true to 1, and false to 0.

Pointer types:

A pointer type can be defined by using a primary type and one or more asterisks, like so:

i32*  a;
i32** b;
i32** c;

Each asterisk represents a pointer, level, in a similar way C's pointers do. Pointer types are always the largest address type (8 bytes on x64). A pointer type may also be accessed via an array operator, like so:

i32*  a;
i32** b;

a[0] = 10;
b[0] = a;
b[0, 0] = 20;

// a[0] = 10

A pointer may not be accessed via an array operator with more levels than the pointer is declared with. Something like this, for example, will cause an error to be emitted:

i32*  a;
a[0, 0]; // error

Clone this wiki locally