next up previous contents
Next: Comparison with CM Up: MLton User Guide Previous: Unsafe: UNSAFE   Contents


CM

For porting code from SML/NJ and for developing code for MLton under SML/NJ, MLton supports a very limited subset of Compilation Manager (CM) files. From MLton's point of view, a CM file foo.cm defines a list of SML source files. The call mlton foo.cm is equivalent to compiling an SML program consisting of the concatenation of these files. As always with MLton, the concatenation must be the whole program you wish to compile.

In its simplest form, a CM file contains the keywords Group is followed by an explicit list of sml files. For example, if foo.cm contains

Group is
bar.sig
bar.fun
main.sml
then a call mlton foo.cm is equivalent to concatenating the three files together and calling MLton on that SML file. The list of files defined by a CM file is the same as the order in which the filenames appear in the CM file. Thus, order in a CM file matters. In the above example, if main.sml refers to a structure defined in bar.fun, then main.sml must appear after bar.fun in the file list.

CM files can also refer to other CM files. A reference to bar.cm from within foo.cm means to include all of the SML files defined by bar.cm before any of the subsequent files in foo.cm. For example if foo.cm contains

Group is
bar.cm
main.sml
and bar.cm contains
Group is
bar.sig
bar.fun
then a call to mlton foo.cm is equivalent to compiling the concatenation of bar.sig, bar.fun, and main.sml.

CM also has a preprocessor mechanism that allows files to be conditionally included. This can be useful when developing code in SML/NJ and MLton. In SML/NJ, the preprocessor defines the symbol SMLNJ_VERSION. In MLton, no symbols are defined. So, to conditionally include foo.sml when compiling under SML/NJ, one can use the following pattern.

# if (defined(SMLNJ_VERSION))
foo.sml
# endif
To conditionally include foo.sml when comiling under MLton, one can negate the test.
# if (! defined(SMLNJ_VERSION))
foo.sml
# endif

The filenames listed in a CM file can be either absolute paths or relative paths, in which case they are interpreted relative to the directory containing the CM file. If a CM file refers either directly or indirectly to an SML source file in more than one way, only the first occurrence of the file is included. Finally, the only valid file suffixes in a CM file are .cm, .fun, .sig, and .sml.



Subsections
next up previous contents
Next: Comparison with CM Up: MLton User Guide Previous: Unsafe: UNSAFE   Contents