Previous Up Next

4  How to compile Moby programs

The Moby compiler is a batch compiler. You should write your program using your favorite text editor and then save it in a file with a ``.mby'' suffix.

4.1  The compilation environment

In order to compile a Moby source file the compiler needs to be able to determine the signatures of imported modules.
This release does not support separate compilation of Moby modules, so the only MBI files are either hand written or generated by tools like charon and moby-idl.

4.2  The filemap

When the compiler encounters a free module identifier it must find the MBI file that specifies the module's interface. This task requires a mapping from modules to their signatures, a mapping from modules and signatures to source files, and a list of the imported libraries. These mappings are usually specified using a filemap file for each library and application program.

Filemaps have the following simple syntax:
FileMap
::= Entry*
Entry
::= include String ;
| library LibraryName ;
| signature UnitId ;
| module UnitId (: UnitId)opt ;
| module UnitId ( (UnitId (, UnitId)*)opt ) (: UnitId)opt ;
LibraryName
::= LibraryId
| String
UnitId
::= Id (@ String)opt
The lexical class of identifiers are upper-case Moby identifiers; Moby-style comments are also supported.

4.3  An example

As an example of how Moby programs are compiled, consider the example of an application that consists of two modules: the main program (Main) in main.mby and an utility module (Util) in util.mby. Furthermore, assume that the Util module has the signature UTIL in the file util-sig.mby. Lastly, assume that the application uses the ConsoleIO module from the console-io library. The FILEMAP file for this application is given in Figure 1.

library console-io;
module Util @ "util.mby : UTIL @ "util-sig.mby";
module Main @ "main.mby";

Figure 1: A sample FILEMAP


The first line specifies that the console-io library is being used, the next line specifies the source code location for the UTIL signature, the third line specifies the signature and source-cde location for the Util module, and the last line specifies the source-code location for the Main module (which we assume has an anonymous or implicit signature).

Since mobyc is a batch compiler, we can use Unix make to build our program. Figure 2 gives the source of a possible Makefile.1

SOURCES = main.mby util.mby util-sig.mby
OBJECTS = main.o   util.o

prog : $(OBJECTS)
        mobyc -o prog $(OBJECTS)

main.o : main.mby util.mbi util-sig.mbi FILEMAP
        mobyc -c main.mby

util.mbi : util.o

util.o : util.mby util-sig.mbi FILEMAP
        mobyc -c util.mby

util-sig.mbi : util-sig.mby FILEMAP
        mobyc -c util-sig.mby

Figure 2: A sample Makefile



Previous Up Next