Skip to content

Instantly share code, notes, and snippets.

@tmcgilchrist
Last active July 28, 2023 12:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcgilchrist/1bb5b67e60a2224f0ba8d58546b1d1cd to your computer and use it in GitHub Desktop.
Save tmcgilchrist/1bb5b67e60a2224f0ba8d58546b1d1cd to your computer and use it in GitHub Desktop.
```
OCaml compilation pipeline
┌────────────────┐
│ │
│ Source code │
│ │ parsing and preprocessing
└───────┬────────┘ preprocessor extensions (ppx)
┌───────▼────────┐
│ │
│ Parsetree │
│ (untyped AST) │
└───────┬────────┘
│ type inference and checking
┌───────▼────────┐
│ │
│ Typedtree │
│ │
└───────┬────────┘
│ pattern-matching compilation
┌───────▼────────┐ elimination of modules and classes (patches to pass more information down to Lambda)
│ │
│ OCaml Lambda ├──────────────────────────────────────────────────────┐
│ │ │
└───────┬────────┘ closure conversion, │ melange/original Bucklescript
│ inlining, uncurrying, ┌───────────┼─────────────────────────────────────────────────────────────┐
┌──────────────────────┐ ┌────────────────┴────────────────┐ data representation strategy │ │ │
│ │ │ │ │ ┌───────▼────────┐ │
│ ┌────────────────┐ │ ┌──────▼─────────┐ ┌───────▼────────┐ │ │ │ 6 Lambda Passes (lam_* files) │
│ │ │ │ │ │ │ │ │ │ Buckle Lambda │ Optimisation/inlining/dead code elimination │
│ │ js_of_ocaml │◄─┼────┤ Bytecode │ │ CMM │ │ │ │ │
│ │ │ │ │ │ │ │ │ └───────┬────────┘ │
│ └───────┬────────┘ │ └──────┬─────────┘ └───────┬────────┘ │ │ self tail call elimination │
│ │ │ │ ocamlrun │ │ │ Constant folding + propagation │
│ │ │ │ │ │ │ │
│ ┌───────▼────────┐ │ ┌──────▼─────────┐ ┌───────▼────────┐ │ ┌───────▼────────┐ │
│ │ Javascript code│ │ │ │ │ │ │ │ │ │
│ │ │ │ │ Interpreted │ │ Compiled │ │ │ Javascript IR │ 6 JS Passes (js_* files) │
│ │ │ │ │ │ │ │ │ │ │ Optimisation/inlining/dead code elimination │
│ └────────────────┘ │ └────────────────┘ └────────────────┘ │ └───────┬────────┘ │
│ │ │ │ │
└──────────────────────┘ │ │ Smart printer include scope analysis │
│ │ │
│ ┌───────▼────────┐ │
│ │ │ │
│ │ Javascript Code│ │
│ │ │ │
│ └────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment