A backend for compiling
The backend requires OCaml 4.13 or later to run. The development also depends on Coq 8.19, and developer builds of CertiCoq.
The backend can be installed using Opam with:
git clone https://github.com/AU-COBRA/lambda-box-extraction.git
cd lambda-box-extraction
opam switch create . 4.14.2 --repositories default,coq-released=https://coq.inria.fr/opam/released
eval $(opam env)
opam install .
lbox TARGETLANGUAGE FILE [-o FILE]
E.g. compiling prog.ast
file to WebAssembly.
lbox wasm prog.ast -o prog.wasm
Valid values for TARGETLANGUAGE
are:
wasm
c
ocaml
rust
elm
For detailed usage on all commands and flags see here or use lbox --help
.
The tool currently supports extracting
Verified extraction to WebAssembly is implemented in CertiCoq-Wasm.
It extends on the CertiCoq with an additional translation from
Extracted Wasm code can be run using any WebAssembly engine supporting the tail call extension of WebAssembly.
Examples of how to run Wasm in browsers, Node.js, Wasmtime.
The program main function will be exported as main_function
in extracted Wasm module.
Clight is a subset of C used by the verified CompCert compiler. Clight includes pointer arithmetic, struct and union types, loops, and structured switch statements.
A verified compiler to Clight is implemented in CertiCoq.
Clight can be compiled using CompCert or any ordinary C compiler (GCC, clang, ...). The generated C code must be linked with the garbage collector and glue code as described here.
https://github.com/yforster/coq-verified-extraction implements verified extraction to OCaml or more specifically Malfunction which is an internal language used in the OCaml compiler.
For more details see the paper Verified Extraction from Coq to OCaml.
Malfunction can compiled using the malfunction tool.
The Rust extraction uses the certified typed erasure of MetaCoq to extracted programs to
Extracted Rust code depends on bumpalo v3 or later.
The Elm extraction uses the certified typed erasure of MetaCoq to extracted programs to
The extracted Elm code does not depend on any external libraries and can be compiled with the Elm compiler.
The lbox tool compiles
Agda2lambox is a backend for Agda translating Agda programs into
To use the Agda2lambox frontend you should first annotate the definition you wish to translate with {-# COMPILE AGDA2LAMBOX DEF_NAME #-}
.
For example
test = ...
{-# COMPILE AGDA2LAMBOX test #-}
The program can then be translated to
agda2lambox FILE
or to
agda2lambox --typed --no-block FILE
MetaCoq is a project formalizing Coq in Coq and providing tools for manipulating Coq terms and developing certified plugins (i.e. translations, compilers or tactics) in Coq. It can be used to translate Coq programs into
For extracting Coq programs it is recommended to use the respective extraction backends in Coq rather than using the standalone lbox tool.
-
-o FILE
output file for extracted program -
--bypass-wf
bypass wellformedness check on input programs, note that the correctness guarantees of proofs don't apply when bypassing these checks -
--quiet
,--verbose
,--debug
controls the level of feedback from the program -
--typed=MAIN_FUNCTION
attempts to parse the input program as a$\lambda_\square^T$ program rather than$\lambda_\square$ , only available for untyped extraction targets -
--opt
enable extra optimizations
lbox TARGETLANGUAGE FILE [-o FILE]
Valid values for TARGETLANGUAGE
are:
wasm
c
ocaml
rust
elm
The wasm
and c
targets also supports the --cps
flag that uses verified cps translation during compilation instead of the unverified direct translation.
These commands main purpose are for debugging
This command evaluates --anf
flag can be used to use an alternative evaluator which first translates the program to
lbox eval FILE [-anf]
Also supports the --cps, --opt, --typed
flags.
lbox validate FILE
Validates that the program in FILE
can be parsed and is wellformed.
Also supports the --typed
flag.
Compiles
lbox anf FILE
Also supports the --cps, --opt, --typed
flags.