leanfran compiles Lean 4 IR to Clojure (LeanClj/, LeanClj/Cli.lean) and embeds Lean
in Clojure (src/leanfran/core.clj). See the backend README for usage.
Paths in this guide are relative to langs/Clojure/.
LeanClj/EmitClj.lean: the emitter. Collects IR decls from roots, emits
Clojure forms, and derives the marshalling descriptors of public functions. A call of an extern clj:<ns>/<name> goes
through an internal function of its own (emitBridge), and the calls of a spec whose @[csimp] lemma names such an
extern are replaced by those of it (generate). replaces judges for obligations check whether a function can
replace its spec.LeanClj/Sx.lean: S-expression tree and layout.LeanClj/Cli.lean: the commands of leanfran --lang clojure. LeanClj/Embed.lean: the Backend of
Leanfran.Embed for sync, check and status.src/leanfran/runtime.clj: runtime. lean_* functions are named after the C
symbols of Lean externs; generated code checks at load time that every
symbol it uses exists (check-symbols!). clj-var and clj-function find the Clojure functions of the bridges.src/leanfran/core.clj: deflean, which reads the code that sync generated.src/leanfran/cli.clj: scan and translate, which the compiler runs. scan.clj reads the blocks and the functions
of the files without loading namespaces. load.clj loads the namespaces for translate, and models.clj makes the
Lean modules of the models: f_<function> for each set of mutually recursive functions, o_<function> for the
obligations of its marks, b_<block>, which the block imports, check_models for leanfran.typed/check-translation,
and LeanCljModel.<Ns>, which imports the functions and the obligations of a namespace.src/leanfran/typed.clj, types.clj, translate.clj: typed functions, their types and their translation.
marks.clj: the verification marks, as scan and defn read them. property.clj: the random test of check.resources/leanfran/lean/: the Lean library of the models, which the compiler embeds. Clj.lean has the models of
clojure.core, and Clj/Model.lean the syntax that the translation writes: clj_body checks what Lean made of the body
of a model, and clj_field, clj_struct, clj_with, clj_keyword, clj_case and clj_fn the types that only Lean
knows.src/leanfran/dsl.clj: S-expressions → Lean source for deflean.LeanCljTest/: Lean test programs. Vectors.lean holds the diff-test
cases; OracleMain.lean is the native oracle.test/: Clojure tests, a project of its own whose generated code is committed. make sync regenerates it with the lock.
test-out/ holds the projects of the tests (ignored by git).../../lean-toolchain matches nixpkgs-unstable's lean4.grep -rn 'extern "<symbol>"' under the toolchain's
src/lean) and implement it with the same argument order, dropping erased
arguments.scan reads the names of the functions and the types of a block from _lean/<block>.clj (provided), and the hash of
a function depends on them: the public functions of a block are the same whether Clojure functions replace its
functions or not.LeanCljTest/Vectors.lean; the diff-test must
match the C backend byte for byte.make build runs lake --dir ../.. build leanfran. The tests use that compiler with --lang clojure.
nix develop ../..#clojure --command make check
make build # build the shared compiler
make test # diff-test against the C backend, then the Clojure tests
make check # format check, lint, and all tests
make format
../../maint/Clojure/test-diff.sh runs LeanCljTest.Vectors.report compiled by Lean's C backend
and the same function generated as Clojure, and compares the output.
The Release and Publish workflows release every backend under one version, as CONTRIBUTING.md describes. The release writes the version with clojure -T:build set-version :version '"X.Y.Z"', and the Publish job deploys the jar to Clojars.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |