5 Manual page
MLton is run from the command line with a collection of options
followed by a file name and a list of files to compile, assemble, and
link with.
mlton [option ...] file.{c|cm|o|sml} [file.{c|o|s|S} ...]
The simplest case is to run mlton foo.sml, where foo.sml
contains a valid SML program, in which case MLton compiles the
program to produce an executable foo. Since MLton does not
support separate compilation, the program must be the entire
program you wish to compile. However, the program may refer to
signatures and structures defined in the SML basis library.
For developing large programs spanning many files, MLton supports a
limited subset of SML/NJ Compilation Manager (CM) files. For example,
mlton foo.cm will compile the complete SML program consisting of
the concatenation of all the SML files referred to (either directly
or indirectly) by foo.cm. See Section 10 for details.
5.1 Compile-time options
MLton's options allow you to control the name of the output file,
the verbosity of compile-time messages, and whether or not certain
optimizations are performed. They also allow you to specify which
intermediate files are saved and to stop the compilation process
early, at some intermediate pass, in which case compilation can be
resumed by passing the resulting files to MLton. MLton uses the
input file suffix to determine the type of input program. The
possibilities are .c, .cm, .o, and .sml.
With no arguments, MLton prints the version number and exits. For
a usage message, run MLton with an invalid switch, e.g. mlton
-. In the explanation below and in the usage message, for flags
that take a boolean argument {true|false}, the first value
listed is the default. For example, by default, overflow checking on
is performed on integer arithmetic.
-align {4|8}-
Aligns object sizes and doubles in memory by the specified alignment.
On X86, the default is 4 and on Sparc the default is
8.
- -cc-opt option
-
Pass the option to gcc when compiling C code.
- -detect-overflow {true|false}
-
Perform overflow checking on integer arithmetic.
- -exn-history {false|true}
-
Enable Exn.history. See Section 9.2.5 for details. There is a
performance cost to -exn-history true, both in memory usage of
exceptions and in run time, because of additional work that must be
performed at each exception construction, raise, and handle.
- -export-header file
-
Write to file C prototypes for all of the functions exported
from SML to C. This flag is useful for programs that use _export
expressions (see Section 6.2).
- -ieee-fp {false|true}
-
Cause the native code generator to be pedantic about following the
IEEE floating point standard. By default, it is not, because of the
performance cost. This has no effect with -native false.
- -inline n
-
Set the inlining threshold used in the optimizer. The threshold is an
approximate measure of code size of a procedure. The default is 320.
- -keep {g|o|sml}
-
Save intermediate files. If no -keep argument is given, then
only the output file is saved.
g |
generated .S and .c files passed to gcc and the assembler |
o |
object (.o) files |
sml |
SML file |
- -link-opt opt
-
Pass the option to gcc when linking. You can use this to
specify library search paths, e.g. -link-opt -Lpath, and
libraries to link with, e.g. -link-opt -lfoo, or even both at
the same time, e.g. -link-opt '-Lpath -lfoo'. If you wish to
pash an option to the linker, you must use gcc's -Wl,
syntax, e.g., -link-opt '-Wl,--export-dynamic'.
- -native {true|false}
-
Generate native code , as opposed to generating C and using gcc.
With -native true, MLton typically compiles more quickly and
generates better code.
- -output file
-
Specify the name of the final output file. The default name is the
input file name with its suffix removed and an appropriate, possibly
empty, suffix added.
- -profile {no|alloc|time}
-
Produce an executable that will gather allocation or time profiling
information. When such an executable is run, it will produce an mlmon.out file. See Section 7 for details.
- -profile-stack {false|true}
-
If true, the profiler will count the time spent (or bytes allocated)
while a function is on the stack.
- -runtime arg
-
Pass argument to the runtime system via @MLton. The argument
will be processed before other @MLton command line switches.
Multiple uses of -runtime are allowed, and will pass all the
arguments in order. If the same runtime switch occurs more than once,
then the last setting will take effect.
- -safe {true|false}
-
This switch determines the value of the SML variable MLton.safe,
which controls whether the basis library performs array, string, and
vector bounds checks, division for zero checks, and other checks.
Compiling -safe false changes the behavior of some programs,
does not conform to the basis library specification, and may cause
programs to seg fault.
- -sequence-unit {false|true}
-
If true, then in the sequence expression (e1; e2), it is a type
error if e1 is not of type unit. This can be helpful in
detecting curried applications that are mistakenly not fully applied.
To silence spurious errors, you can use ignore e1.
- -show-basis file
-
Pretty print to file the basis defined by the input program.
When used with no input file, MLton pretty prints the entire basis
library.
- -show-basis-used file
-
pretty print to file the portion of the basis library that the
input program uses.
- -show-def-use file
-
Output def-use information to file. Each identifier that is
defined appears on a line, follwed on subequent lines by the position
of each use.
- -stop {f|g|o|sml}
-
Secify pass to stop at.
f |
list of files on stdout (only makes sense when input is foo.cm) |
g |
generated .S and .c files |
o |
object file |
sml |
SML file (only makes sense when input is foo.cm) |
tc |
after type checking |
If you compile -stop g or -stop o, you can resume
compilation by running mlton on the generated .c and .S or .o files.
- -target {self|...}
-
Generate an executable that runs on the specified platform. The default
is self, which means to compile for the machine that MLton is
running on. To use any other target, you must first install a
cross-compiler. See Section 13.
- -verbose {0|1|2|3}
-
How verbose to be about what passes are running. The default is 0.
0 |
silent |
1 |
calls to compiler, assembler, and linker |
2 |
1 + intermediate compiler passes |
3 |
2 + some data structure sizes |
- -warn-match {true|false}
-
Report nonexhaustive and redundant matches.
- -warn-unused {false|true}
-
Report unused identifiers.
5.2 Runtime system options
To control the runtime system, executables produced by MLton take
several optional command line arguments before their usual arguments.
To use these options, the first argument to the executable must be
@MLton
. The optional arguments then follow, must be
terminated by --
, and are followed by any arguments to the
program. The optional arguments are not made available to the
SML program via CommandLine.arguments. For example, a valid
call to hello-world is:
hello-world @MLton gc-summary fixed-heap 10k -- a b c
In the above example, CommandLine.arguments () = ["a", "b",
"c"]. It is also allowed to have a sequence of @MLton
arguments, as in:
hello-world @MLton gc-summary -- @MLton fixed-heap 10k -- a b c
Here are the allowed options.
-
fixed-heap n[km]
-
Use a fixed size heap of n bytes.
A trailing k means that n is in units of 1024 bytes.
A trailing m means that n is in units of 1,048,576 bytes.
If neither appear, then n is in bytes.
A value of 0 means to use almost all the RAM present on the
machine.
- gc-messages
-
Print a message at the start and end of every garbage collection.
- gc-summary
-
Print a summary of garbage collection statistics upon program
termination.
- load-world world
-
Restart the computation with the file specified by world, which must
have been created by a call to MLton.World.save by the same
executable. See Section 9.2.27 for details.
- max-heap n[km]
-
Run the computation with an automatically resized heap that is never
larger than n. The meaning of [km] is the same as with the
fixed-heap option.
- no-load-world
-
Disable load-world. This can be used as an argument to the
compiler via -runtime no-load-world to create executables that
will not load a world. This may be useful to ensure that set-uid
executables do not load some strange world.
- ram-slop x
-
Multiply x by the amount of RAM on the machine to obtain what
the runtime views as the amount of RAM it can use. Typically x
is less than 1, and is used to account for space used by other
programs running on the same machine.
- stop
-
Causes the runtime to stop processing @MLton arguments once the
next -- is reached. This can be used as an argument to the
compiler via -runtime stop to create executables that don't
process any @MLton arguments.
These options can also control MLton, as in
mlton @MLton fixed-heap 100m -- foo.sml