Rivar is a minimal, contract-first, class-based, garbage-collected programming language inspired by Eiffel.
It is being built from scratch in OCaml (with the help of LLMs), designed to bring native Design by Contract (DbC) to the modern developer's toolbox.
So far this has been tested only on Ubuntu 24.04.
- OCaml (recommended via opam)
dune
menhir
opam install dune menhir
dune build
sudo apt-get install libgc-dev
- Generate C code from Rivar source:
./_build/default/src/main.exe examples/greeter.rivar
- Compile generated C code with Boehm GC:
gcc -std=c99 -o test examples/test-greeter.c out.c -lgc
class GREETER
feature
name: STRING
set_name(new_name: STRING)
require new_name != ""
do
this->name = new_name
ensure
this->name != old this->name
end
greet()
require this->name != ""
do
print(this->name)
ensure
result == true
end
end
rivar/
├── src/
│ ├── ast.ml # Core [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) definitions
│ ├── ir.ml # IR types ([Intermediate Representation](https://en.wikipedia.org/wiki/Intermediate_representation))
│ ├── ir.mli # IR interface
│ ├── irgen.ml # AST -> IR lowering
│ ├── lexer.mll # OCamllex lexer
│ ├── parser.mly # Menhir parser
│ ├── codegen.ml # IR -> C code generation
│ ├── typecheck.ml # Type checker (WIP)
│ └── main.ml # CLI compiler entry point (`rivarc`)
├── examples/
│ ├── account.rivar # Sample Rivar class
│ ├── greeter.rivar # Sample Rivar class with strings
│ ├── test-account.c # Test harness for `account.rivar`
│ └── test-greeter.c # Test harness for `greeter.rivar`
├── out.c # Generated C output (from `rivarc`)
├── out.h # Generated C header
├── dune-project # Dune project file
├── .gitignore # Ignores compiled artifacts and test binaries
└── README.md # You're looking at it
Rivar isn't about speed or syntax gimmicks. It's about truth in code.
Contracts aren't optional: they are the code.
MIT