Presentation of part IIWe describe the set of elements of the environment included in the language
distribution. There one finds different compilers, numerous libraries,
program analysis tools, lexical and syntactic analysis tools, and an
interface with the C language.
Objective CAML is a compiled language offering two types of code generation:
The Objective CAML toplevel uses bytecode to execute the phrases submitted to it.
It constitutes the primary development aid, offering the possibility of
rapid typing, compilation and testing of function definitions. Moreover,
it offers a trace mechanism visualizing parameter values and return values
bytecode to be executed by a virtual machine;
- native code to be executed directly by a microprocessor.
The other usual development tools are supplied by the distribution as well:
file dependency computation, debugging and profiling. The debugger allows
one to execute programs step-by-step, use breakpoints and inspect values.
The profiling tool gives measurements of the number of calls or the amount
of time spent in a particular function or a particular part of the code.
These two tools are only available for Unix platforms.
The richness of a language derives from its core but also from the
libraries, sets of reusable programs, which come with it. Objective CAML is no
exception to the rule. We have already portrayed to a large extent the
graphical library that comes with the distribution. There are many others
which we will describe. Libraries bring new functionality to the language,
but they are not without drawbacks. In particular, they can present some
difficulty vis-a-vis the type discipline.
However rich a language's set of libraries may be, it will always be
necessary that it be able to communicate with another language. The
Objective CAML distribution includes an interface with the C language allowing
Objective CAML to call C functions or be called by them. The difficulty of
understanding and implementing this interface lies in the fact that the
memory models of Objective CAML and C are different. The essential reason for
this difference is that an Objective CAML program includes a garbage collection
C as well as Objective CAML allow dynamic memory allocation, and thus fine
control over space according to the needs of a program. This only makes
sense if unused space can be reclaimed for other use during the course of
execution. Garbage collection frees the programmer from responsibility for
managing deallocation, a frequent source of execution errors. This feature
constitutes one of the safety elements of the Objective CAML language.
However, this mechanism has an impact on the representation of data. Also,
knowledge of the guiding principles of memory management is indispensable
in order to use communication between the Objective CAML world and the C world
Chapter 7 presents the basic elements of the
Objective CAML system: virtual machine, compilers, and execution library. It
describes the language's different compilation modes and compares their
portability and efficiency.
Chapter 8 gives a bird's-eye view of the set
of predefined types, functions, and exceptions that come with the system
distribution. It does not do away with the need to read the reference
manual ([LRVD99]) which describes these libraries very well. On
the contrary it focuses on the new functionalities supplied by some of
them. In particular we may mention output formatting, persistence of
values and interfacing with the operating system.
Chapter 9 presents different garbage collection methods
in order to then describe the mechanism used by Objective CAML.
Chapter 10 presents debugging tools for Objective CAML
programs. Although still somewhat frustrating in some respects, these
tools quite often allow one to understand why a program does not work.
Chapter 11 describes the language's different
approaches to lexical and syntactic analysis problems: a regular expression
library, the ocamlex and ocamlyacc tools, but also the
use of streams.
Chapter 12 describes the interface with the C language.
It is no longer possible for a language to be completely isolated from
other languages. This interface lets an Objective CAML program call a C
function, while passing it values from the Objective CAML world, and vice-versa.
The main difficulty with this interface stems from the memory model. For
this reason it is recommended that you read the 9 chapter
Chapter 13 covers two applications: an
improved graphics library based on a hierarchical model of graphical
components inspired by the JAVA AWT2; and a classic program to find least-cost paths in a graph using
our new graphical interface as well as a cache memory mechanism.