Compilation and its Semantics

Table of Contents
use -- Import module to current environment.
rsc -- Compile a module.

We have already used the concept of loading above. The compiler introduces some other concepts that need to be understood in order for the compilation process to make sense.

Compiling a module involves translating the source code in the source files to a different format that is no longer in the form of source code. The off-line module compiler puts the result of this translation in a file called the module image file (extension .mif).

The module index (.mx) file contains various names that are important to the linker, in particular module entry points and a list of dynamically linked (extension .so) files. The module index file and the module image file are both logically part of the "object code" generated by the compiler and should always be manipulated together. In particular, they should both be installed in the same directory.

The contents of this module image file can then be added to your interactive RScheme enviroment in a way similar to loading described above. Conceptually, this process is divided into two steps, the link step and the import step. Linking simply takes the module image file and incorporates it into the interactive RScheme enviroment without making any connection between the linked module and the current module. Linking is just the extension, at runtime, of the set of modules present in the heap; the system starts out with a set of default modules already present and linked. Importing, on the other hand, simply binds names in the current module to the exported variables of the imported module.

In the interactive RScheme environment, you typically use the command ,(use module) to import a module, where module is the name (in the form of a symbol) of a module. The module image file is formed by adding a .mif extension to the string form of the symbol. Recall that forms that start with a comma are conceptually executed outside the interactive environment. The command ,(use foo) will first check whether the module foo has already been linked. If not, then it tries to find the module image file and link it. If it cannot find the module image file, an error message is given. If the module is already linked, or if the module file was found and successfully linked, the ,(use foo) command will procede to the population step and add the exported top-level bindings to the interactive RScheme environment.

Conceptually, the meaning of the linking step is similar to the meaning of loading source. It is during the linking step that top-level forms in the source code (i.e. the .scm files that were mentioned during compilation) are conceptually evaluated in order. We say ``conceptually'' because the compiler is free to replace this top-level evaluation by something more efficient provided that the effect in the interactive RScheme environment is the same. The most important such transformation that the compiler does is to convert each lambda expression to machine code that has the same effect as the lambda expression itself, except that it is much faster.