Brain is a compiled programming language designed to be type-safe, high-performance, and built for parallel programming. It combines low-level control with strong compile-time guarantees — no garbage collector, no runtime overhead, no surprises.
⚠️ Brain is experimental. The language design, syntax, and compiler are still evolving.
- 🔒 Type Safety – Strong static typing and ownership checking at compile time
- ⚡ High Performance – Compiled to native code via LLVM with full O3 optimization
- 🧵 Parallel Programming – Safe concurrency with Mutex primitives built into the type system
- 🛠️ Low-level Control – Manual memory semantics without a garbage collector
The compiler fully implements the following features end-to-end — lexing, parsing, semantic analysis, ownership checking, LLVM IR generation, and linking to a native executable:
- Primitive types:
int,bool,char,string - Arithmetic, comparison, and logical operators
if/else if/else,while,forloops- Functions with typed parameters and return values, including recursion
- String concatenation,
.len(),.char_at(),int_to_string() - Fixed-size arrays and dynamic
Vec - Structs with named fields and member access
- Enums with optional associated values and
matchexpressions - Ownership and borrow checking — move semantics,
&borrows,&mutmutable borrows - File I/O —
read_file,write_file Mutex<T>with.lock()andunsafeescape hatch- Module system —
exportandimportacross files and folders - LLVM O3 optimization pipeline via
build.ps1
Brain uses a compile-time ownership system — no garbage collector, no reference counting.
fn consume_string(s: string) {
print(s);
}
fn borrow_string(s: &string) {
print(s);
}
fn ownership_example() {
let s = "hello world";
borrow_string(&s);
borrow_string(&s);
consume_string(s);
}
&sborrows — the caller keeps ownership, can borrow multiple times- Passing
sdirectly moves ownership —scannot be used again after that point - Violations are caught at compile time, not at runtime
export struct Point {
x: int,
y: int,
}
export fn make_point(x: int, y: int) -> Point {
return Point { x: x, y: y };
}
import { Point, make_point } from "structs/structs.brn";
fn main() {
let p = make_point(3, 4);
print(p.x);
}
export works on fn, struct, enum, and let. Imports are resolved relative to the importing file.
examples/
├── main.brn
├── game/
│ └── main.brn ← Crypts of Brain (dungeon crawler)
├── types/types.brn
├── operators/operators.brn
├── control_flow/control_flow.brn
├── functions/functions.brn
├── strings/strings.brn
├── arrays/arrays.brn
├── vectors/vectors.brn
├── structs/structs.brn
├── enums/enums.brn
├── ownership/ownership.brn
├── files/files.brn
└── mutex/mutex.brn
A text-based dungeon crawler written entirely in Brain — a real game that demonstrates structs, functions, ownership, file I/O, and string handling working together in a single file.
examples\game\main.brn
- 3 floors, 18 rooms total
- Turn-based combat with 6 enemy types (Goblin → Dragon boss)
- RPG progression: XP, levelling up, attack/defense/HP upgrades
- Items: Health Potions, Attack Scrolls, Defense Amulets, Gold
- Autosaves to
brain_save.txtafter every room
- Rust (for building the Brain compiler)
- LLVM / Clang (for optimization and linking)
.\build.ps1build.ps1 handles everything: compiles the Brain compiler with cargo, lets you pick a source file, runs it through the Brain compiler to produce LLVM IR, then runs the LLVM O3 optimization pipeline and links a native .exe.
Options presented by build.ps1:
| # | Source | Description |
|---|---|---|
| 1 | examples\main.brn |
Feature showcase |
| 2 | examples\game\main.brn |
Crypts of Brain (dungeon crawler) |
| 3 | compiler\main.brn |
Self-hosting compiler (building on progress) |
cargo build --release
target\release\brain.exe examples\main.brn
clang -O3 examples\main.ll -o main.exe -lkernel32 -luser32To build the game specifically:
cargo build --release
target\release\brain.exe examples\game\main.brn
clang -O3 examples\game\main.ll -o game.exe -lkernel32 -luser32struct Person {
name: string,
age: int,
}
enum Direction {
North,
South,
East,
West,
}
fn match_direction(d: Direction) -> int {
match d {
Direction::North => 0,
Direction::South => 1,
Direction::East => 2,
Direction::West => 3,
}
}
fn fib(n: int) -> int {
if n < 2 {
return n;
}
return fib(n - 1) + fib(n - 2);
}
fn main() {
let p = Person { name: "Alice", age: 30 };
print(p.age);
let d = Direction::North;
print(match_direction(d));
print(fib(10));
}
- Game engines
- Operating systems and low-level tooling
- Performance-critical applications
- Language and compiler design research
The compiler pipeline is complete and produces working native executables. Current focus is preparing for self-hosting — rewriting the Brain compiler in Brain itself.
This project is open-source. See the LICENSE file for more details.