Moscow ML includes a batch compiler mosmlc in addition to the interactive system mosml. It compiles and links programs non-interactively, and can turn them into standalone executable files. The batch compiler can be invoked from a Makefile, which simplifies the (re)compilation of large programs considerably; see Section 6.
The mosmlc command has a command-line interface similar to that of most C compilers. It accepts several types of arguments: source files for unit bodies, source files for unit signatures, and compiled unit bodies.
The output of the linking phase is a file containing compiled code that can be executed by the runtime system camlrunm. If mosmlout is the name of the file produced by the linking phase, the command
executes the compiled code contained in mosml.out. The arguments can be accessed from the Moscow ML program via function Mosml.argv; see file mosml/lib/Mosml.sig.
The output file mosmlout.exe consists of a tiny executable file prepended to a linked bytecode file. The executable invokes the camlrunm runtime system to interpret the bytecode. As a consequence, this is not a standalone executable: it still requires camlrunm.exe to reside in one of the directories in the path.
#!/usr/local/bin/camlrunm
. In the
former case, camlrunm must be in one of the directories in the
path; in the latter case it must be in /usr/local/bin. To
create a true stand-alone executable you may simply concatenate the
runtime system with the bytecode file produced by mosmlc
-noheader, but this adds 60-150 KB to the size of the
executable, depending on your version of Unix:
The following command-line options are recognized by mosmlc.
Compile only. Suppresses the linking phase of the compilation. Source code files are turned into compiled files (.ui and .uo), but no executable file is produced. This option is useful for compiling separate units.
Pass the names of files listed in file response-file to the linking phase just as if these names appeared on the command line. File names in response-file are separated by blanks (spaces, tabs, newlines) and must end either in .sml or .uo. A name U.sml appearing in the response file is equivalent to U.uo. Use this option to overcome silly limitations on the length of the command line (as in DOS).
This option causes some information about exception names to be written at the end of the executable bytecode file.
Causes the compiler to print the inferred signature of the unit body or bodies being compiled. Also causes the linker to list all object files linked. A U.sig file corresponding to a given U.sml file can be produced semi-automatically by piping the output of the compiler to a file U.out, and subsequently editing this file to obtain a file U.sig.
In version 1.42 and later, the linker automatically links in any additional object files required by the files explicitly specified on the command line. Option -noautolink reinstates the behaviour of previous versions: all object files must be explicitly specified in the appropriate order.
Specifies the standard library directory, which will be searched by
the compiler and linker for the .ui and .uo files corresponding to
units mentioned in the files being linked. The default standard
library is set when the system is created, and is usually
${HOME}/mosml/lib under Unix and c:\mosml\lib
under
DOS.
Add the given directory to the list of directories searched for compiled signature files (.ui) and compiled object code files (.uo). By default, the current directory is searched first, then the standard library directory. Directories added with -I are searched after the current directory, but before the standard library directory. When several directories are added with several -I options on the command line, these directories are searched from left to right.
Specify that the type checker should use `value polymorphism'; see Section 7. The default.
Specify that the type checker should distinguish imperative and applicative type variables, generalize all applicative type variables, and generalize imperative type variables only in non-expansive expressions. See Section 7.
Specify the name of the output file produced by the linker. In the absence of this option, a default name is used. In MS DOS, the default name is mosmlout.exe; in Unix it is a.out.
Determines which library units will be open at compile-time.
Additional library units to be linked in can be specified by listing them on the command line, or by using the -I directory option.
Causes the output file produced by the linker to contain only the bytecode, not preceded by any executable code. A file mosmlout thus obtained can be executed only by explicitly invoking the runtime system as follows: camlrunm mosmlout. This option is primarily used for recompiling the system.
Enable the quotation/antiquotation mechanism; see Section 8.
Print the version number of the various passes of the compiler.