Next Previous Contents

1. Getting started

1.1 Requirements

MLton runs on X86 machines under Linux. It produces C code as output and requires gcc to produce the final executable. It may work with other C compilers, but it hasn't been tested. Installation requires 30M disk space and 64M RAM.

1.2 Installation

Unpack MLton. Then, cd to the src directory and run make. This compiles MLton's runtime system and the compiler itself. This takes about 8 minutes on a 400MhZ P6. MLton is now ready to go!

The bin directory contains the short shell script, mlton, that runs the compiler. This script may be moved anywhere, however, MLton makes use of files in the include/ and lib/ directories defined in the script.

1.3 Use

Normally, the mlton command takes a single file name as an argument, where the file suffix is .sml and the file contains a valid Standard ML program. MLton produces an executable named by stripping off the .sml suffix. The .sml suffix is necessary because MLton uses the file suffix to determine the type of input program (other possibilities are .c, .s, and .o). The input program must consist of a sequence of toplevel declarations -- unlike a read-eval-print loop, expressions are not allowed as programs. MLton has no notion of separate compilation. The program must be the entire program you wish to compile. The program may have free references to variables defined in the basis library (section basis library), but otherwise must be closed.

1.4 Hello, World!

From the root directory, run the command

bin/mlton examples/hello-world.sml

This takes several seconds and will create an executable, examples/hello-world. You can now run this executable to verify that it works. There are several other small examples in the examples/ directory. In particular, there are examples that demonstrate MLton's heap checkpointing, callcc, and object size facilities (section MLton extensions), as well as profiling and FFI.

1.5 Recompile MLton test

For a more strenuous test of MLton, you can recompile the compiler and verify that the generated C code is the same as the C code in the distribution. To do this, cd src; make test. This requires a machine with at least 256M RAM and takes about 6 minutes on a 400MhZ P6. If this test succeeds, feel free to do cd src; make clean.


Next Previous Contents