Darcy is a small, typed Lisp that compiles to Rust.
The compiler (dslc) reads .dsl files, typechecks them, lowers to Rust, and (optionally) runs the result.
Compile a single file to Rust:
cargo run -p dslc -- examples/ok.dsl > out.rsRun a file (compiles and executes):
cargo run -p dslc -- run examples/ok.dslAdd stdlib/module search paths (repeatable):
cargo run -p dslc -- -L crates/darcy-stdlib/darcy examples/ok.dsl
cargo run -p dslc -- -L crates/darcy-stdlib/darcy run examples/mnist.dsl --runtimeNote: the compiler may emit warnings when it auto-clones values to avoid move errors.
Install the language server binary:
cargo install --path crates/darcy-lspZed:
- Install dev extension from
extensions/zed(containsextension.toml). - This repo includes workspace config in
.zed/settings.jsonthat launchesdarcy-lspfor theDarcylanguage. - If
darcy-lspis not inPATH, replace the command with an absolute path. - See
extensions/zed/README.md.
VS Code:
- A local extension client lives at
extensions/vscode. - Setup:
cd extensions/vscode
npm install- Open
extensions/vscodein VS Code and pressF5to run an Extension Development Host. - The extension starts
darcy-lspover stdio for.dslfiles. - Settings:
darcy.languageServer.path(defaultdarcy-lsp)darcy.languageServer.args(default[])
TextMate grammars for Zed and VS Code are generated from extensions/defs.json:
make grammarsTo verify they are in sync:
make grammars-checkFiles:
- Source-of-truth metadata:
extensions/defs.json - Generator:
extensions/gen_grammars.py - Generated outputs:
extensions/vscode/syntaxes/darcy.tmLanguage.jsonextensions/zed/darcy.tmLanguage.json
Install repo-managed hooks:
make hooks-installCurrent pre-commit hook runs:
cargo fmt --all(auto-formats and stages tracked files)make grammars-checkmake test
Top-level forms:
- Records:
(defrecord name [field:type ...])(types optional:[field ...]) - Enums:
(defenum name (variant [field:type ...]) ...)(types optional inside variant field vectors) - Functions:
(defn name [params] expr) - Macros:
(defmacro name [params] expr) - Inline defs:
(defin name [params] expr)(expanded before typechecking) - Values:
(def name expr)
Expressions (selected):
- Literals: ints (default
i64), floats (f64), strings,true/false,nil(()), symbols (:key) - Symbol forms:
:x,:ns/x,::x,::alias/x ::xresolves to the current module namespace,::alias/xresolves viarequirealias- Control flow:
(if cond then [else]),(when cond expr ...),(cond (test expr) ... (else expr)) - Sequencing/binding:
(do ...),(let [x 1 y 2] ...),(let! x expr)(assignment, returns()) - Functions:
(fn [x] ...), calls:(f a b)(plus(call f a b)for dynamic calls) - Loops:
(loop expr),(while cond expr),(for i (range 0 10) expr) - Loop control:
(break [expr]),(continue) - Field access:
u.name - Method calls (Rust interop-ish):
(. obj method arg ...),(.method obj arg ...) - Case on enums:
(case x (variant (field v) expr) (_ expr)) - Threading macros:
(-> x (f 1) g),(->> xs (map f) (take 10)) - Reader conveniences:
;line comments,#| |#block comments, commas are whitespace,#_discards the next form - Type shorthand
name:typeis only valid in params/bindings/field declarations - Use
(type expr Type)for expression type ascription (x:typein expression position is rejected)
Interop (selected):
- Extern wrapper:
(extern (defrecord ...)),(extern (defenum ...)),(extern (defn name [params] RetType)) - Rust interop macros:
(require [darcy.rust :refer [defextern defextern-record]])
Prelude:
darcy.coreis automatically opened in every module (exceptdarcy.coreanddarcy.op).- This means
+,=,mod,<,<=,>,>=,&,|work as normal calls without an explicitrequire.
Operators:
- Operator spellings are aliases to
darcy.core/*names (+->add,=->eq, etc). darcy.core/*is a thin layer overdarcy.op/*.darcy.op/*are compiler-lowered primitives (they become real Rust ops in generated code).
Overloading:
- Functions can be overloaded by arity (same name, different parameter count).
Printing:
- Debug print:
(darcy.io/dbg x)(Rustprintln!("{:?}", ...)) - Formatting:
(darcy.fmt/format x),(darcy.fmt/pretty x) - Printing is variadic:
- Template-style:
(darcy.fmt/println "x={} y={}" x y)(lowered to Rustprintln!) - Value-style:
(darcy.fmt/println a b c)prints values separated by spaces
- Template-style:
String interpolation:
${name}inside a string literal lowers toformat!(...).- Example:
(darcy.fmt/println "hi ${name}")
Records/enums printing:
- All
defrecordanddefenumtypes automatically get a RustDisplayimpl (currently backed byDebug), so(darcy.fmt/println u)works for user-defined types.
(require [darcy.io :as io])
(defn main []
(io/dbg 42))You can also:
(require [darcy.io :refer [dbg]])(require [darcy.io :refer :all])
Module paths use . (example: darcy.io). Callable references use / (example: darcy.io/dbg).
Stdlib modules (selected):
- Always available (builtins):
darcy.core,darcy.op,darcy.io,darcy.fmt,darcy.option,darcy.result - Common library modules (from
crates/darcy-stdlib/darcy/):darcy.vec,darcy.string,darcy.math,darcy.tensor,darcy.nn,darcy.mnist,darcy.rand
Use the Cargo subcommand to scaffold a Rust project with Darcy integration:
cargo darcy init my-app
cd my-app
cargo runThis creates a normal Cargo crate with build.rs and a darcy/ folder. The build step compiles Darcy sources
into Rust and includes them automatically. Darcy's stdlib comes from the darcy-stdlib crate by default.
If you're developing from this repo, set DARCY_SDK to the repo root so cargo darcy init uses path
dependencies to darcy-build and darcy-stdlib:
export DARCY_SDK=/path/to/darcy-langFor an automated workflow, use the darcy-build crate in build.rs so Darcy sources are compiled during
cargo build.
[build-dependencies]
darcy-build = { path = "path/to/darcy-lang/crates/darcy-build" }
darcy-stdlib = { path = "path/to/darcy-lang/crates/darcy-stdlib" }// build.rs
fn main() {
darcy_build::Builder::new("darcy/main.dsl")
.lib_path("darcy")
.stdlib_path(darcy_stdlib::stdlib_dir())
.compile()
.expect("darcy compile failed");
}// src/main.rs
mod darcy_gen {
include!(concat!(env!("OUT_DIR"), "/darcy_gen.rs"));
}
fn main() {
let o = darcy_gen::Order { qty: 2, price: 3.5 };
let total = darcy_gen::total_prices(o);
println!("{total}");
}darcy-build looks for the stdlib at DARCY_STDLIB first, then falls back to this repo's
crates/darcy-stdlib/darcy/ directory (when used via the Darcy workspace or a path/git dependency).
There is a small benchmark stub at dslc/src/bin/bench.rs:
cargo run -p dslc --bin bench -- --iters 200000There is also a typecheck/inference benchmark:
cargo run -p dslc --bin bench_typecheck -- --iters 10000 --save bench/typecheck.json
cargo run -p dslc --release --bin bench_typecheck -- --iters 10000 --save bench/typecheck.release.json- No explicit ownership/borrowing surface syntax yet (there is inferred borrowing + auto-clone warnings)
- No user-defined traits/generics syntax (compiler infers generic bounds in some cases)
- Diagnostics are mostly single-span today
flowchart TD
A[Parse + expand] --> B[Typecheck]
B --> C[Lower to Rust IR]
C --> D[Emit Rust]
D --> E[Run or integrate into Cargo build]
Rustc remains the source of truth for hard errors and generated output validation.
The intent is: your compiler does the "clarity layer" (shape + local type inference + good errors), and Rust remains the final checker for deep lifetime / trait issues.
Naming: DSL identifiers are lowercase kebab-case. They are normalized to Rust identifiers during lowering
(types and variants become PascalCase; values become snake_case). Callable names are a bit more permissive
(they can include characters like ? and !), and all non-Rust characters are safely mangled during lowering.
Use (extern "RustName" (def...)) to override the Rust name for extern declarations.
See LANGUAGE.md for the living language guide.