Types
Mach ships a small set of compiler-seeded primitive types plus a uniform grammar for building pointers, arrays, and function types out of them. There are no compiler-known aliases: names like bool, usize, and str are stdlib defs.
Primitive scalars
Eleven names make up the complete set of primitive types the compiler seeds. Everything else is built on top of them.
| Family | Members |
|---|---|
| Unsigned int | u8, u16, u32, u64 |
| Signed int | i8, i16, i32, i64 |
| Float | f32, f64 |
| Untyped pointer | ptr |
There is no compiler bool. It is a stdlib alias def bool: u8;, with true and false as stdlib vals (1 and 0).
SIMD vectors planned
The planned design extends the primitive numeric types into vectors by appending x<count>.
f32x4 # 4 lanes of f32
i32x8 # 8 lanes of i32
u8x16 # 16 lanes of u8
The grammar is <u|i|f><width>(x<count>)*. Higher dimensions such as f32x4x4 are legal grammatically; the compiler ships only the entries its target backends can accelerate.
The compiler does not seed vector types today. A name like f32x4 resolves as an ordinary unbound identifier, not a type. The grammar above describes the planned design only.
Pointers
*T is a pointer to a value of type T. Take an address with ? and read through it with @.
var x: i64;
var p: *i64 = ?x; # address-of yields a pointer
val v: i64 = @p; # dereference reads through it
Arrays
[N]T is an array of exactly N values of type T. Arrays nest as [N][M]T.
val a: [4]i64 = [4]i64{1, 2, 3, 4};
val g: [2][2]i64 = [2][2]i64{ [2]i64{1, 2}, [2]i64{3, 4} };
Function types
fun(T1, T2) R is a first-class function-pointer type, usable as a value's type just like any scalar.
def BinOp: fun(i64, i64) i64;
val op: BinOp = add;
val r: i64 = op(2, 3);
Named types and aliases
rec and uni declarations produce named types. A def introduces an alias for any type, including the constructed forms above.
def Bytes: [16]u8; # Bytes now names an array type
def bool: u8; # the stdlib's own bool alias
See also
- Values and variables -
defaliases,valconstants, and howboolis built - Records and unions - declaring named
recandunitypes - Expressions - which operations work on each type
- Intrinsics -
$size_ofand$align_ofover any type