% FILE. . . . . /home/hak/ngo/doc/hak/design/backend.tex
% EDIT BY . . . Hassan Ait Kaci
% ON MACHINE. . Latitude314.Ilog.Fr
% STARTED ON. . Tue Jun 25 09:31:17 2002

% Last modified on Tue Jun 25 09:31:26 2002 by Hak

\chapter{The backend system}

\Section{The runtime system}{runtime-system}

This is the class defining a runtime object. Such an object serves
as the common execution environment context shared by \txt{Instruction}s being
executed. It encapsulates a state of comptutation that is
effected by each instruction as it is executed in its context.

A \txt{Runtime} object consists of attributes and structures that
together define a state of computation, and methods that are used by
instructions to effect this state as they are executed. Thus, each
instruction class defines an \txt{execute(Runtime)} method that
specifies its operational semantics as a state transformation of its
given runtime context.



Initiating execution of a \txt{Runtime} object consists of setting
its code array to a given instruction sequence, setting its
instruction pointer \txt{\_ip} to its code's first instruction and
repeatedly calling \txt{execute(this)} on whatever instruction is
currently at address \txt{\_ip} in the current code array. The
final state is reached when a flag indicating that it is so is set to
\txt{true}. Each instruction is responsible for appropriately
setting the next state according to its semantics, including saving
and restoring states, and (re)setting the code array and the various
runtime registers pointing into the state's structures.



Runtime states encapsulated by objects in this class are essentially
those of a stack automaton, specifically conceived to support the
computations of a higher-order functional language with lexical
closures---{\em i.e.}, a $\lambda$-calculus machine---extended to
support additional features---\textit{e.g.}, assignment side-effects,
objects, automatic currying\ldots\ As such it may viewed as an optimized
variant of Peter Landin's SECD machine~\cite{secd}---in the same spirit
as Luca Cardelli's Functional Abstract Machine (FAM)~\cite{fam},
although our design is quite different from Cardelli's in its structure
and operations.



Because this is a Java implementation, in order to avoid the space and
performance overhead of being confined to boxed values for primitive
type computations, three concurrent sets of structures are maintained:
in addition to those needed for boxed (Java object) values, two extra
ones are used to support unboxed integer and floating-point values,
respectively. The runtime operations performed by instructions on a
\txt{Runtime} object are guaranteed to be type-safe in that each state
is always such as it must be expected for the correct accessing and
setting of values. Such a guarantee must be (and is!) provided by the
\txt{TypeChecker} and the \txt{Sanitizer}, which ascertain all the
conditions that must be met prior to having a \txt{Compiler} proceed to
generating instructions which will safely act on the appropriate stacks
and environments of the correct sort (integer, floating-point, or
object).

\Section{The runtime objects}{runtime-objects}

\Section{The display manager}{display-manager}

\Section{The error manager}{erro-manager}


