Programming language for literate programming law specification
Go to file
Louis Gesbert ee569657e1 C backend: WIP handling mixed const/non-const inits
we want our pointers to "const" (in the C sense, i.e. read-only) values in
general; but structures need to be initialised field by field. We handle the
absence of `const` in this case (the pointer target will be made `const` upon
function return).

When we compile with `-O`, though, intermediate variables are removed, and we
have branchings with one side getting an already allocated (`const`) structure,
while the other one will need to init through allocation of individual fields.

In the current state of this patch, we define the structure as non-const and
malloc it when this happens, like in the basic definition case. It works, but in
the branch of the already allocated structure, the malloc is discarded (wasted),
and there is a legitimate warning because we strip the `const` flag from the
source pointer.

I see only two solutions:
- remove all consts (beh, they are very good for understanding what's going on,
  and I'm sure that without them we'll fall into more traps later)
- in the branch(es) needing malloc, allocate and initialise to a temporary
  non-const structure, then affect it to the return pointer ("sealing" it as
  const after initialisation). This basically what happens without `-O` because
  we have more intermediate variables... But we want to target that specifically
  at cases that need malloc.

A variant of the 2nd option could be to define initialiser functions for all
structs, but we loose in readability since the arguments would be unlabelled.
The cleaner way to do it would probably be at the scalc level, depending on the
`--no-struct-literals` flag.
2024-09-13 18:38:50 +02:00
.github/workflows Update and fix CI 2024-08-28 15:32:58 +02:00
.nix fix nix environment 2023-11-16 16:52:23 +01:00
build_system Improve error reporting and remove language 2024-08-06 18:12:29 +02:00
compiler C backend: WIP handling mixed const/non-const inits 2024-09-13 18:38:50 +02:00
doc Cheat-sheet: remove need for exotic latex package 2024-06-27 17:01:55 +02:00
runtimes C backend: all tests pass but modules 2024-09-13 15:37:31 +02:00
syntax_highlighting fix missing keywords in emacs mode 2024-07-30 14:39:00 +02:00
tests Scalc printer: be explicit about inits 2024-09-11 16:27:26 +02:00
.git-blame-ignore-revs Fix a few remaining renaming glitches 2024-09-04 10:50:25 +02:00
.gitattributes Remove generated files from git 2023-07-10 15:48:11 +02:00
.gitignore Makefile: remove references to the examples 2024-01-16 11:54:28 +01:00
.ocamlformat Update ocamlformat 2023-09-01 16:19:58 +02:00
build_release.sh Better version handling 2024-01-24 11:41:34 +01:00
catala.opam Properly link and use dates_calc into the C runtime, and use header files 2024-09-11 13:51:38 +02:00
catala.opam.locked Properly link and use dates_calc into the C runtime, and use header files 2024-09-11 13:51:38 +02:00
CITATION.cff Fix a few remaining renaming glitches 2024-09-04 10:50:25 +02:00
CONTRIBUTING.md Add PR policies in contributing 2024-06-19 12:02:51 +02:00
Dockerfile Update and fix CI 2024-08-28 15:32:58 +02:00
dune tests: check the generated C code 2024-05-30 16:19:55 +02:00
dune-project Install Python and R runtimes 2024-01-16 11:54:28 +01:00
flake.lock update flakes file 2023-07-31 16:24:41 +02:00
flake.nix Update ocamlformat 2023-09-01 16:19:58 +02:00
INSTALL.md Update the generation process of the website assets 2024-02-21 11:28:56 +01:00
LICENSE.txt Code reorg 2019-09-04 10:32:33 +02:00
Makefile scalc translation: simplify local bindings implem 2024-09-13 12:19:45 +02:00
README.md Fix broken links in README 2024-04-12 17:17:42 +02:00

Catala logo

Catala

Explore the docs »
View TutorialReport BugContributeJoin Zulip Chat

CI Opam Licence Tag LoC Language Issues Contributors Activity

Catala is a domain-specific language for deriving faithful-by-construction algorithms from legislative texts. To learn quickly about the language and its features, you can jump right to the official Catala tutorial. You can join the Catala community on Zulip!


Table of Contents

Concepts

Catala is a programming language adapted for socio-fiscal legislative literate programming. By annotating each line of the legislative text with its meaning in terms of code, one can derive an implementation of complex socio-fiscal mechanisms that enjoys a high level of assurance regarding the code-law faithfulness.

Concretely, you have to first gather all the laws, executive orders, previous cases, etc. that contain information about the socio-fiscal mechanism that you want to implement. Then, you can proceed to annotate the text article by article, in your favorite text editor :

Screenshot

Once your code is complete and tested, you can use the Catala compiler to produce a lawyer-readable PDF version of your implementation. The Catala language has been specially designed in collaboration with law professionals to ensure that the code can be reviewed and certified correct by the domain experts, which are in this case lawyers and not programmers.

Screenshot

The Catala language is special because its logical structure mimics the logical structure of the law. Indeed, the core concept of "definition-under-conditions" that builds on default logic has been formalized by Professor Sarah Lawsky in her article A Logic for Statutes. The Catala language is the only programming language to our knowledge that embeds default logic as a first-class feature, which is why it is the only language perfectly adapted to literate legislative programming.

Getting started

To get started, the best place is the tutorial of the language. A French version is also available but might be out of sync with the latest language features.

Note: bleeding-edge version

If you are interested in the latest development version, pre-built artifacts including binaries and API documentation can be found at https://catalalang.github.io/catala

Building and installation

Catala is available as an opam package! If opam is installed on your machine, simply execute:

opam install catala

To get the cutting-edge, latest version of Catala, you can also do

opam pin add catala --dev-repo

However, if you wish to get the latest developments of the compiler, you probably want to compile it from the sources of this repository or use nix. For that, see the dedicated readme.

Usage

Catala

Use catala --help if you have installed it to get more information about the command line options available. The man page is also available online. To get the development version of the help, run make help_catala after make build. The catala binary corresponds to the Catala compiler.

The top-level Makefile contains a lot of useful targets to run. To display them, use

    make help

Plugin backends

While the compiler has some builtin backends for Catala (Python, Ocaml, etc.), it is also possible to add a custom backend to the Catala compiler without having to modify its source code. This plugin solution relies on dynamic linking: see the dedicated README.

Clerk

Use clerk --help if you have installed it to get more information about the command line options available. To get the development version of the help, run make help_clerk after make build. The clerk binary corresponds to the Catala build system, responsible for testing among other things.

To get more information about Clerk, see the dedicated readme

Catleg

Catleg is a command line utility providing useful integration with LégiFrance, the official repository of French legal documentation. See the decidated repository for more information.

Documentation

Syntax cheat sheet

A complete and handy reference of the Catala syntax can be found in the cheat sheet (for French and English versions of the syntax).

Formal semantics

To audit the formal proof of the partial certification of the Catala compiler, see the dedicated readme.

Compiler documentation

The documentation is accessible online, both for the latest release and bleeding-edge version.

It is otherwise generated from the compiler source code using dune and odoc. Run

make doc

to generate the documentation, then open the doc/odoc.html file in any browser.

Examples

To explore the different programs written in Catala, see the dedicated readme.

API

To know how to use the code generated by the Catala compiler in your favorite programming language, head to the readme of the French law library. The corresponding pre-built examples are also available.

Contributing

To know how you can contribute to the project, see the dedicated readme.

Test suite

To know how to run or improve the Catala reference test suite, see the dedicated readme.

License

The compiler and all the code contained in this repository is released under the Apache license (version 2) unless another license is explicited for a sub-directory.

Limitations and disclaimer

Catala is a research project from Inria, the French National Research Institute for Computer Science. The compiler is yet unstable and lacks some of its features.

Pierre Catala

The language is named after Pierre Catala, a professor of law who pionneered the French legaltech by creating a computer database of law cases, Juris-Data. The research group that he led in the late 1960s, the Centre détudes et de traitement de linformation juridique (CETIJ), has also influenced the creation by state conselor Lucien Mehl of the Centre de recherches et développement en informatique juridique (CENIJ), which eventually transformed into the entity managing the LegiFrance website, acting as the public service of legislative documentation.