\section{Implementation}
\label{implementation}

Implementation of the goals in Section~\ref{introduction} involve
three modifications to the Hermes system, and the design and
development of a program to perform the transformation.

\subsection{Modification to definition of program object}

The hidden field, of the {\tt program} record (see {\tt predefined}
definitions) contains execution oriented information.  This field, is
a {\tt prog} record (see {\tt interpform}), to which the following
fields have been added to support {\bf C}-coded Hermes.

\begin{verbatim}
      name: charstring,         -- some printable name for the process
      path: charstring,         -- full unix path of C-compiled object
      text: charstring,         -- generated source code (may be "")
      object: charstring,       -- loadable object code (may be "")
      handle: object_handle,    -- (cast) handle of loaded object code
                                        -- = 0 if not (yet) loaded
      pool: pooled_qualifiers   -- pooled compound qualifiers for c-code
\end{verbatim}

\subsection{Modification to interpreter to link object modules}

When a new process is created, if there is an object module, and it is
not yet linked, the dynamic loader is called to link the object code
to the interpreter.  After the module has been linked, the created
process control block may reference it.

Dynamic loaders differ radically from system to system.  {\bf SUN
OS4.1} supports {\em dlopen, dlsym} (in {\em libdl}); {\bf RS6000
AIXv3} supports {\em load, loadbind}.

\subsection{Modification to interpreter to perform residual instructions}

A new {\bf li}-code instruction, {\tt escape , Index}, has been added
to the greencard.  The module {\tt li/o{\uline}escape.c}, called by the
Hermes interpreter for an unlinked {\bf C}-coded process, calls
{\tt li/link{\uline}process.c}.

The Hermes dispatcher, {\tt mainloop.c} has been modified to recognize
{\tt escape} instructions efficiently.

\subsection{The Transformation Program}

The program which transforms the {\bf li}-code of a {\tt program} into
{\bf C}-code has three phases.

\begin{enumerate}
\item[1. ]
Partition the {\bf li}-code into residual {\bf li}-code sequences
separated by sequentially qualified escape codes,\footnote{
The {\bf li}-code of the escape instruction is:
\begin{quote}\tt escape \space , \space IntegerSwitchIndex \end{quote}
where {\tt IntegerSwitchIndex} is the index of the corresponding
case {\bf C}-code sequence in the {\bf C}-function, starting with
0 (see Section~\ref{structure}).}
If there are no interpreted {\bf li}-coded sequences, the entire
residual {\bf-li}-coded list of instructions consists of {\tt escape}
operations and {\bf C}-codable sequences.

\item[2. ] Improve the {\bf C}-codable sequences, and choose optimal
{\bf C}-coded representations for them.

\item[3. ]
Transform the representations into a text string (see
Section~\ref{structure}) and construct the object module.\footnote{
The object module must be compiled from the text string.  The initial
implementation writes a temporary source file, and writes and reads
a temporary {\bf C}-object file.}
\end{enumerate}

The transformation recurses for each nested program literal in a
{\tt prog{\uline}lit} instruction of the {\bf li}-code.
