Bars (барс) — Снежният леопард. Бърз, независим, опасен.The snow leopard (Panthera uncia)
A systems programming language with Clojure syntax, Rust-like ownership (lighter), and compilation to native code via QBE, Cranelift, and LLVM.
;; examples/hello.brs
(defn main []
(println "Hello, World!"))$ bars run examples/hello.brs
Hello, World!- Clojure syntax — parentheses naturally express scope and structure. Only
()and[]brackets. - Lightweight ownership — NLL borrow checking, drop checking, no lifetime annotations.
- Type inference — Hindley-Milner type system with
bars check --types. - Three backends — QBE for fast AOT, Cranelift for JIT/REPL and fast AOT, LLVM for
--release. - Lambda functions — anonymous
(fn [x] body)with full pipeline support. - Zero-cost FFI — direct C ABI access through the runtime.
- GC when you want it — stack + ownership + Boehm GC for complex data.
.brs— source file extension.
- Rust 1.70+ (for building the compiler)
qbe(AOT backend, installed at~/.local/bin/qbeor on PATH)libgc-dev(Boehm GC for the runtime)cc/gcc(for linking)
git clone https://codeberg.org/bars-lang/bars-lang.git
cd bars-lang
cargo build --release# Read and print AST
bars read examples/hello.brs
# Compile to QBE IR
bars build examples/hello.brs
# Compile and run (default QBE backend)
bars run examples/math.brs
# Compile and run with Cranelift backend
bars run --backend cranelift examples/math.brs
# REPL (Cranelift JIT)
bars repl(defn greet [name]
(println name))
(defn add [a b]
(+ a b))(defn main []
(let [x 42
y (+ x 1)]
(println y)))(defn main []
(let [x 2]
(cond
(= x 1) "one"
(= x 2) "two"
:else "other")))(defn factorial [n]
(loop [i n acc 1]
(if (= i 0)
acc
(recur (- i 1) (* acc i)))))(defn main []
(let [v (vector 1 2 3)]
(push v 4)
(println (count v)) ;; 4
(println (get v 2)))) ;; 3Vectors can be nested:
(def v [1 [2 3] 4])
(println (get (get v 1) 0)) ;; 2Maps are created with functions (no {} literal syntax):
(defn main []
(let [m (map)]
(map-set m 1 100)
(println (map-get m 1)))) ;; 100Maps can hold vectors as values:
(def m (map))
(map-set m 1 [10 20])
(println (get (map-get m 1) 0)) ;; 10(defn main []
(let [s (set)]
(set-add s 1)
(set-add s 2)
(println (set-count s)) ;; 2
(println (set-contains? s 2)))) ;; 1 (true)(defn use-buf [^buf data]
;; immutable borrow
(println (count data)))
(defn mutate-buf [^mut buf data]
;; mutable borrow
(push data 42))
;; Implicit borrow: ^ is optional when passing owned values
(let [v (vector 1 2 3)]
(use-buf v) ;; automatic borrow
(use-buf v)) ;; OK — borrow released after each call(load "lib/core.brs")
(load "lib/math.brs")
(defn main []
(println (factorial 5))
(println (range 1 10)));; Inline anonymous functions
(fn [x] (+ x 1))
;; Lambda with borrow annotation
(fn [^buf data]
(println (count data)))
;; Lambda as function body
(defn make-adder [n]
(fn [x] (+ x n)))$ bars check --types examples/hello.brs
✅ Type inference passed.
main : i64(deftype Option [Some i64] [None])
(deftype Result [Ok i64] [Err i64])
(defn handle [res]
(match res
(Ok v) (+ v 1)
(Err e) (* e -1)))Конструкторите се разпознават по главна буква. match проверява за exhaustiveness.
;; Деклариране на C функция
(extern "putchar" [c i64] -> i64)
(defn main []
(putchar 65)) ;; отпечатва 'A'Работи с QBE, Cranelift и LLVM — генерира правилни extern declarations.
| Command | Description |
|---|---|
bars read <file> |
Parse and print AST |
bars build <file> |
Compile to QBE IR via HIR (stdout) |
bars build --backend cranelift <file> |
Compile via Cranelift to object file |
bars build --backend llvm <file> |
Compile via LLVM to object file |
bars build --release <file> |
Release build with optimizations |
bars run <file> |
Compile, link, and execute (default QBE) |
bars run --backend cranelift <file> |
Compile, link, and execute (Cranelift) |
bars run --backend llvm <file> |
Compile, link, and execute (LLVM) |
bars repl |
Interactive Cranelift JIT session |
bars check <file> |
Run ownership analysis |
bars check --types <file> |
Run type inference |
bars build --features llvm-backend |
Enable LLVM backend (requires LLVM 14+) |
.
├── src/ # Compiler source (Rust)
│ ├── reader/ # Lexer + Parser
│ ├── ast/ # AST types
│ ├── macro/ # Macro expansion
│ ├── ownership/ # Ownership checker
│ ├── types/ # Hindley-Milner type inference
│ ├── hir/ # High-level IR (flattened)
│ └── backends/ # QBE + Cranelift + LLVM backends
├── runtime/ # C runtime + Boehm GC
├── lib/ # Standard library (.brs)
├── examples/ # Example programs
├── tests/ # Integration tests
└── docs/ # Documentation
| Backend | Mode | Status |
|---|---|---|
| QBE HIR | Fast AOT debug/release | ✅ Working |
| Cranelift | JIT / REPL / AOT | ✅ Working |
| LLVM | Optimized release (--release) | ✅ Working |
See lib/ and docs/04-stdlib.md.
lib/core.brs— numeric helpers, vector helpers, range,or,andlib/math.brs—square,cube,gcd,lcm,factorial,fib,sum,productlib/vector.brs—last,rest,take,drop,reverse,contains?,index-oflib/string.brs—str-empty?,str-countlib/map.brs—map-empty?,map-has?lib/adt.brs—Option,Resultтипове с helper функцииlib/test.brs—assertмакрос за тестове
| Функция | Описание |
|---|---|
sqrt n |
Корен квадратен |
pow base exp |
Степенуване |
abs n |
Абсолютна стойност |
str-count s |
Дължина на низ |
str-concat a b |
Конкатенация на низове |
slurp path |
Прочита файл като низ |
spit path content |
Записва низ във файл |
.brs → Reader → AST → Macro Expansion → Ownership Check → HIR → Backend → Native Code
├── QBE IR → qbe → cc
├── Cranelift → cc
└── LLVM IR → llc → cc
See ROADMAP.md for the full plan.
| Feature | Status |
|---|---|
| Reader (Lexer + Parser) | ✅ |
| AST → HIR → QBE IR | ✅ |
| Functions & recursion | ✅ |
| Ownership checker | ✅ |
| Runtime + Boehm GC | ✅ |
| REPL + Cranelift JIT | ✅ |
Built-in macros (when, unless, cond, ->, ->>) |
✅ |
loop / recur |
✅ |
load system |
✅ |
| Stdlib | ✅ |
| LLVM backend | ✅ |
User-defined macros (defmacro) |
✅ |
Type inference (check --types) |
✅ |
Lambda functions (fn [x] body) |
✅ |
| Nested collections | ✅ |
| Sets | ✅ |
| Cranelift AOT | ✅ |
| Generics (implicit polymorphism) | ✅ |
ADT (deftype, exhaustiveness check) |
✅ |
FFI (extern C functions) |
✅ |
MIT or Apache-2.0
