SML# Compiler

The SML# version 0.20 installer generates the following two command files:

This is the SML# compiler. It operates in one of the following modes: evaluation mode, compilation mode, and prelude compilation mode.
This is the SML# runtime system. This is used to run a compiled object file.

This page explains basic usage of these commands.

How to use the compiler

Evaluation mode.

Without "-c" option, SML# runs in evaluation mode.

In this mode, the source program is compiled and executed immediately.

If no argument is specified, SML# accepts source code interactively.

$ smlsharp
# val x = 1;
val x = 1 : int
# ^D

If some arguments are specified, SML# interprets the first argument as the source program file.

$ cat foo.sml
print "foo\n";

$ smlsharp ./foo.sml

The rest of the arguments can be accessed from the source program by 'CommandLine.arguments' as shown in the following example.

$ cat bar.sml
app print (CommandLine.arguments ());

$ smlsharp ./bar.sml foo bar boo

Compilation mode.

If "-c" option is specified, SML# runs in compilation mode.

In this mode, the source program is compiled into an object file. If no object file name is given then the system use the default name "a.sme".

$ smlsharp -c
# print "foo\n";
# ^D

$ ls a.sme

The generated object file can be run through smlsharprun command. If this command is installed in a location which is included in PATH environment variable, then the generated object file can be invoked within an operating system shell directly.

$ ./a.sme

Otherwise, you need to invoke smlsharprun explicitly as follow.

$ smlsharprun a.sme

As in the evaluation mode, if invoked with arguments, the compiler reads source code from the file specified in the first argument.

$ cat foo.sml
print "foo\n";

$ smlsharp -c foo.sml
$ ls a.sme

Unlike in evaluation mode, however, the compiler ignores any other arguments.

The arguments with which the object file is invoked are passed to the program.

$ cat bar.sml
app print (CommandLine.arguments ());

$ smlsharp -c ./bar.sml
$ smlsharprun a.sme foo bar boo

$ ./a.sme foo bar boo

Prelude compilation mode.

If invoked with "--make-compiled-prelude" option, the compiler generates a compiled prelude file.

$ smlsharp --make-compiled-prelude -o myprelude.smc myprelude.sml

After compilation of the source code, the internal state of SML# is saved into a compiled prelude file.

If "--compiled-prelude" option is specified, SML# restores its internal state before compiling the source code.

$ smlsharp --compiled-prelude=./myprelude.smc

Command options.

Command options of smlsharp.


smlsharp [options ...] [ { -e EXP | --expression=EXP | --stdin | FILE } ARGS ...]

Options specifying compilation mode.

Runs in compilation mode.
-o FILE / --output=FILE
Specifies name of object file generated by compiler.

Options specifying source.

Reads source code from standard input.
-I DIR / --load-path=DIR
Adds a directory to the load path list. About load path list, see File path resolution.

Options controlling verbosity.

-q / --quiet
Suppresses message printing.
Suppresses warning message.
Suppresses printing binding information.

Options for information.

-v / --version
Prints version information.
-h / --help
Displays command options.
Display non-standard command line options.

Options specifying prelude.

Uses the minimum prelude, instead of the default prelude.
Uses a source file FILE as prelude, instead of the default prelude.
Uses a compiled file FILE as prelude, instead of the default prelude.
Generates precompiled prelude.

Non-standard options

Other options are available for fine-tuning and for development. These are some of them.

a hint to decide the size of SML# heap.
a hint to decide the size of frame stack of SML# runtime.
file path of SML# runtime program.

All non-standard options are displayed by '-X' option.

These options can be specified with command line options which start with '--x', or with environments which start with 'IML_'. For example, the size of SML# runtime heap can be specified with --xVMHeapSize option or with an environment IML_VMHeapSize.

$ smlsharp --xVMHeapSize=1024000
$ env IML_VMHeapSize=1024000 smlsharp

Command options of smlsharprun.


smlsharprun [-heap heapsize] [-stack stacksize] FILE
-heap NUM
Allocates NUM words for the runtime heap.
-stack NUM
Allocates NUM words for the runtime frame stack.

Environment variables affecting SML#

This variable specifies paths added to load path list. See the file path resolution information.



In evaluation mode, SML# built by SML/NJ runs on two processes. One for the compiler, the other for the runtime. The compiler and the runtime communicate to each other, via pipe (on Unix) or socket (on Windows). The compiler sends object code to the runtime process. The runtime executes it and sends back the result to the compiler. The compiler reports the result to user.

It is to be noted that some unstable situation occurs if either the compiler or the runtime aborts without telling to the other. This is an issue which should be fixed in future. If you encounters such situation, you should kill the remaining process by manual. The name of process to be killed is smlsharp or smlsharprun.

If you use SML# built by MLton, because the compiler and the runtime run in single process, this problem does not appear.

Last modified:2007/03/30 07:49:52