Plan 9 programs rewritten in OCaml: the build system, the shell, a C compiler, an assembler and a linker, an editor, git, the windowing system, and more.
Website: aryx.github.io/xix, with a code map of the whole repository to explore in the browser (below).
XIX is XIX: the first fully recursive acronym for a project. It is a port of the C source code of the major Plan 9 programs to OCaml, and a companion to Principia Softwarica, a series of literate programming books explaining Plan 9's source code: each OCaml port has its own book.
It is not finished: some programs are mature (omk and orc build
XIX itself; orio can take the place of rio on Plan 9), others are
still being written.
The code map shows the
whole repository as a map, in the browser: each folder a region, each
file a block the size of its code, each block the code itself once you
zoom in. x shows each program's skeleton, / searches, a click on a
name shows its definition, g the dependencies between the parts, h
every key.
A link can open it anywhere: omk, orc, omk running a recipe; the table below links each program so. It is tinybox's code map, from ocaml-elm-playground, after my codemap.
Lines are of OCaml; the ratio is how many lines of C the original has for one of the port.
| program | what it is | ported from | lines | C/OCaml | code | book |
|---|---|---|---|---|---|---|
| omk | the build system | mk |
2,750 | 1.58 | builder/ (map) |
|
| orc | the shell | rc |
2,150 | 3.04 | shell/ (map) |
|
| occ | the C compiler | 5c |
6,250 | 2.99 | compiler/ (map) |
|
| oas | the assembler | 5a |
1,750 | 2.04 | assembler/ (map) |
|
| olk | the linker | 5l |
2,650 | 2.84 | linker/ (map) |
|
| olex, oyacc | the lexer and parser generators | lex, yacc |
3,500 | generators/ (map) |
||
| oed | the editor | ed |
1,500 | 1.06 | editor/ (map) |
|
| ogit | version control | git | 5,600 | vcs/ (map) |
||
| orio | the windowing system | rio |
3,300 | 2.67 | windows/ (map) |
The toolchain targets ARM, x86-64, ARM64, MIPS and RISC-V. There is
also a port of the Plan 9 kernel (kernel/), which builds
only on Plan 9.
The same project, in repositories of their own: ocaml-light, a simplified OCaml compiler that runs OCaml programs on Plan 9; efuns, an Emacs clone; mmm, a web browser; and the Tiger and C-- compilers (fork-tiger, fork-c--).
One way to understand a program well enough to explain it in a book is to port it to another language. While porting, it is tempting to skip what looks accessory; finding out what is essential already teaches something, and the port that does not work at first, because the "accessory" turned out to matter, shows the subtleties of the original.
The ports are also useful by themselves. Unlike Plan 9's C code, most of them run on Linux, macOS and Windows; the OCaml is about half the size of the C, and has no segmentation fault or buffer overflow. It became easier to try a new feature in OCaml first and port it back to C later.
Here is orio running on Plan 9 in place of the original rio, its
windows showing omk, orc, oas and olk at work, all OCaml
programs run by ocaml-light's ocamlrun:
The website tells more, and the IWP9 paper describes the project.
XIX has two build systems side by side: dune, for development, and
mk (its own omk), which must always work without dune.
With dune (OCaml and opam; see install.txt for the
packages):
make # omk, orc, the toolchain, oed, ...
make testWith mk, from nothing:
./bootstrap-mk.sh # builds bin/omk and bin/orc
source env.sh # puts ./bin in the PATH
mk depend
mkAbout 95% of the code in this repository was written by humans (me, Pad, and the authors of the OCaml standard library, Xavier Leroy et al.). The rest was written by Claude Code, especially for the linker.
LGPL 2.1 (see license.txt).

