SML# Document Version 4.1.0
14 SML# feature: separate compilation

14.1 Separate compilation overview

A standard step of separate compilation consists of the following steps.

  1. 1.

    Decompose the system into a set of compilation units. Each component cab be of any size and can contain any sequence of SML# declarations. Here we suppose that we decompose the system into part1 and part2.

  2. 2.

    For each decomposed component, define its interface. The interface is described in the interface language we shall explain in Section 14.3. In our scenario of decomposing the system into part1 and part2, we first define their interface files part1.smi and part2.smi.

  3. 3.

    For each interface file, develop a source file that implements it. Each source file is independently compiled to an object file.

    In the above scenario, develop part1.sml and part2.sml for part1.smi and part2.smi, compile them to generate part1.o and part2.o. Developing each of the source files and its compilation can be done independently of the other source file. For example, even if part2 uses some functions in part1, part2.sml can be compiled before writing part1.sml. In ML, type error detection during compilation plays an important role in source file development. So the ability to separately compiling each source file independently of any other source files are important feature in large software development.

  4. 4.

    Link the set of object files with necessary libraries and external object files to generate an executable file. For example, if part1 and part2 uses C files and libraries, then link part1.o and part2.o with those compiled C files and libraries to generate an executable file.

A more advanced scenario can be the following.

  1. 1.

    Decompose the system into the part to be written in C and the part to be written in SML#.

  2. 2.

    For the C part, develop header files (.h files) and source files (.c files).

  3. 3.

    For the SML# part, develop interface files (.smi files) and source files (.sml files).

  4. 4.

    Create Makefile using the dependency analysis of SML#.

  5. 5.

    Do make to compile and link the necessary files.

The SML# system itself is a large project including a few tools, all of which are written in C and SML#, and developed in this scenario.