Documentation
Complete guides and reference documentation for the Rey programming language.
Overview
Rey is a compiled, statically-typed programming language designed for simplicity and performance. It compiles to native machine code via LLVM, with no garbage collector and no runtime overhead.
Version 0.2.0 marked a major milestone: the compiler is now self-hosting — written entirely in Rey itself. This means every feature in the language is tested by the act of compiling the compiler.
Key properties of Rey:
- Compiled to native binaries via LLVM
- Statically typed with full inference
- No garbage collector
- Self-hosting compiler (as of v0.2.0)
- Clean, readable syntax
- MIT licensed, open source
Installation
Rey currently ships pre-built binaries for macOS arm64. Linux and Windows builds are in progress.
macOS (recommended)
Download the binary from the Download page or use the installer:
Build from Source
Rey's compiler is written in Rust (the bootstrap compiler) and Rey (the self-hosted compiler). To build from source you'll need Rust toolchain and LLVM installed.
See the Contributing guide for the full development setup.
First Program
Create a file hello.rey:
func main(): Void {
println("Hello, World!");
}Compile and run:
Variables
Variables are declared with var. Types are inferred by default, and can be optionally annotated:
var x = 42; "color:#637099">// inferred: Int
var name = "Alice"; "color:#637099">// inferred: String
var pi: Float = 3.14; "color:#637099">// annotated, enforcedOnce declared, a variable's type cannot change. Reassigning with a different type is a compile error. See the full variables reference.
Types
Rey's built-in types:
| Type | Description | Example |
|---|---|---|
Int | Integer (64-bit) | 42, -7, 0 |
Float | Floating point (64-bit) | 3.14, -0.5 |
Bool | Boolean | true, false |
String | UTF-8 string | "hello" |
Void | No return value | — |
Vec<T> | Resizable array | [1, 2, 3] |
HashMap<K,V> | Hash map | HashMap.new() |
Result<T> | Success or error | readFile(...) |
Option<T> | Some or None | Option.some(x) |
Functions
All functions require parameter and return type annotations:
func add(a: Int, b: Int): Int {
return a + b;
}
"color:#637099">// lambdas
var double = (x: Int) => x * 2;Control Flow
"color:#637099">// if / else
if x > 0 {
println("positive");
} else {
println("non-positive");
}
"color:#637099">// match
match value {
0 => println("zero"),
1 => println("one"),
_ => println("other"),
}Structs
struct User {
pub name: String,
pub age: Int,
}
var u = User { name: "Alice", age: 30 };
println(u.name); "color:#637099">// AliceEnums
enum Status { Ok, Err, Pending }
var s = Status.Ok;
match s {
Status.Ok => println("good"),
Status.Err => println("fail"),
Status.Pending => println("wait"),
}For the complete language specification, see the Language Reference.