Skip to content
/ miniml Public

Compiler for a subset of the ML (really OCaml) language. LLVM is used as a backend.

Notifications You must be signed in to change notification settings

cmaes/miniml

Repository files navigation

MiniML Goals

This project is an experiment in compiling a subset of the ML language (or more properly OCaml). The project follows the structure of the mincaml compiler. However, instead of directly emiting assembler, we use the OCaml LLVM bindings to emit LLVM IR. These bindings don't need to have the code in SSA form, meaning that our intermediate language used inside the compiler does not need to be in kNormal form.

How to install MiniML

Install OCAML

On Ubuntu or Debian, if you don't have OCaml and OPAM yet, you can do

sudo add-apt-repository ppa:avsm/ppa
sudo apt-get update
sudo apt-get install curl build-essential m4 ocaml opam

or use your system's package manager and install its version of OCaml and OPAM.

Setup OPAM

Install OPAM

opam init
eval `opam config env`

Install Menhir

opam install menhir

Install LLVM OCaml Bindings

On Ubuntu or Debian:

sudo apt-get install llvm-3.7 llvm-3.7-dev llvm-3.7-runtime
opam install llvm

MiniML organization

Closure conversion

The most complicated part of the compiler is the typed closure conversion.

Outline

The compiler is structured as follows:

  • lexer.mll - The lexer (use ocamllex to generate lexer.ml)
  • paser.mly - The parser (use menhir to generate parser.ml)
  • type.ml - Defines the types supported in miniml
  • id.ml - Functions for working with identifiers
  • syntax.ml - Defines the AST for miniml
  • env.ml - Defines the environment data structure
  • s.ml - Defines a set data structure
  • typing.ml - Performs type inference
  • inter.ml - Defines an intermediate language, and converts from AST
  • closure.ml - Performs closure conversion
  • prettyprint.ml - Pretty printing routines
  • compile.ml - Emit's LLVM IR
  • miniml.ml - The main program driver

Examples of MiniML programs

There is a small collection of sample programs written in miniml:

You can compile these programs by doing make progname.exe. For example, to compile fib.mml into an exectuable do:

make fib.exe

You can then run fib.exe via

./fib.exe

About

Compiler for a subset of the ML (really OCaml) language. LLVM is used as a backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published