Skip to content

rey-language/rey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

199 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rey Programming Language

Rey is a statically-typed, compiled programming language with clean syntax, built for clarity and hackability. The compiler is written in Rey itself β€” it bootstraps from a Rust reference interpreter and emits LLVM IR compiled to native binaries via clang.

func greet(name: String): String {
    return "Hello, " + name + "!";
}

func main(): Void {
    println(greet("Rey"));
}

Status

Component State
Lexer βœ… Complete
Parser βœ… Complete
Type checker 🚧 Stub (inference only)
LLVM backend βœ… Complete
C runtime library βœ… Complete
Self-hosting βœ… Phase H β€” native compiler passes all e2e tests

The native compiler (rey-compiler/main.rey) compiles to a standalone binary using clang. No Rust is required at runtime.


Quick Start

Prerequisites

  • macOS arm64 (other platforms: build from source)
  • clang on PATH

Pre-built binary (macOS arm64)

# Use the pre-built binary from releases/
chmod +x releases/0.2.0/rey-macos-arm64

# Compile a program
./releases/0.2.0/rey-macos-arm64 rey-compiler/main.rey build examples/basic/hello.rey

# Run a program
./releases/0.2.0/rey-macos-arm64 rey-compiler/main.rey run examples/basic/hello.rey

Build from source

# 1. Build the Rust bootstrap interpreter
cd compiler/v1 && cargo build --release && cd ../..

# 2. Compile the Rey compiler using the bootstrap
./compiler/v1/target/release/rey-v0 rey-compiler/main.rey build rey-compiler/main.rey

# 3. Sign the output (macOS)
codesign -s - rey-compiler/main.bin

# 4. Run a Rey program with the native compiler
./rey-compiler/main.bin rey-compiler/main.rey run examples/basic/hello.rey

Language Features

Variables and constants

var x = 42;
var name: String = "Rey";
const PI: float = 3.14159;

Functions and lambdas

func add(a: int, b: int): int {
    return a + b;
}

var double = (x: int) => x * 2;

Control flow

if x > 0 { println("positive"); } else { println("non-positive"); }

while i < 10 { i = i + 1; }

loop { if done { break; } }

for item in [1, 2, 3] { println(item.toString()); }

Structs

struct Point {
    pub x: int,
    pub y: int,
}

var p = Point { x: 3, y: 4 };

Enums and match

enum Color { Red, Green, Blue }

match color {
    Color.Red   => println("red"),
    Color.Green => println("green"),
    _           => println("other"),
}

Collections

var v = Vec.new();
v.push("a");
v.push("b");
println(v.join(", "));   // a, b

var m = HashMap.new();
m.set("count", 42);
println(m.get("count").toString());

Result and Option

var r = readFile("data.txt");
if r.isOk() {
    println(r.unwrap());
} else {
    println("error: " + r.unwrapOr("unknown"));
}

Imports

import lexer;
import parser;

var tokens = lexer.tokenize(source, "file.rey");
var ast    = parser.parse(tokens, "file.rey");

Repository Layout

rey-lang/
β”œβ”€β”€ compiler/v1/          # Rust bootstrap interpreter (not needed at runtime)
β”‚   └── src/              # Lexer, parser, tree-walk interpreter
β”œβ”€β”€ rey-compiler/         # Self-hosted LLVM compiler (written in Rey)
β”‚   β”œβ”€β”€ main.rey          # Compiler entry point and pipeline
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ lexer/        # Tokenizer
β”‚   β”‚   β”œβ”€β”€ parser/       # Recursive-descent parser + AST definitions
β”‚   β”‚   β”œβ”€β”€ typecheck/    # Type checker (stub)
β”‚   β”‚   └── codegen/      # LLVM IR emitter
β”‚   β”œβ”€β”€ runtime/          # C runtime library (librey_rt)
β”‚   β”‚   β”œβ”€β”€ rey_rt.h      # Public ABI header
β”‚   β”‚   β”œβ”€β”€ string.c      # String operations
β”‚   β”‚   β”œβ”€β”€ vec.c         # Dynamic arrays
β”‚   β”‚   β”œβ”€β”€ hashmap.c     # Hash maps
β”‚   β”‚   β”œβ”€β”€ result.c      # Result/Option/instanceof
β”‚   β”‚   β”œβ”€β”€ io.c          # File I/O and process
β”‚   β”‚   └── mem.c         # Allocator
β”‚   └── tests/e2e/        # End-to-end test suite
β”œβ”€β”€ releases/             # Pre-built binaries (by version)
β”œβ”€β”€ examples/             # Example Rey programs
β”œβ”€β”€ spec/                 # Language specification
└── tests/                # Interpreter-level test fixtures

Testing

# Build runtime first (only needed once)
make -C rey-compiler/runtime

# Run all e2e tests with the native compiler
bash rey-compiler/tests/e2e/run.sh

Expected output: OK


Docs


License

MIT β€” see LICENSE.

About

rey is an experimental programming language

Topics

Resources

License

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages