% "chapters/common.tex"
%	$Id: common.tex,v 1.2 2005/05/06 02:51:22 fang Exp $

\chapter{Common Primitives}
\label{app:common}

This appendix describes the formats of common sub-structures of
the \hackt\ Object File Format.  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Strings}
\label{app:common:strings}

The binary format for strings is simply the length of the string (4B), 
followed by the contents of the string.  
Null-termination on write is not necessary because the length is known.  
Upon reconstruction however, 
the reader will automatically add null-termination.  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Pointers}
\label{app:common:pointers}

All pointers (references to other persistent objects) are translated
by the POM into an integer (4B), 
the index of the object in the body section of the object file.  
The obvious limitation of this is that there's a hard limit of 
$2^{32}$ manageable objects.  
Talk to me when you exceed this limit.  
For the gory details on this subject, please refer to the entire
``Fang's C++ Utility Belt'' document.  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Sequences}
\label{app:common:sequence}

The standard format of any sequence (list, array, etc.)
is the number of elements (4B), followed by the data for each
element in sequence.  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Expressions}
\label{app:common:expr}

The storage for all forms of expressions follow straight from the 
language itself.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Booleans}
\label{sec:common:expr:pbool}

Single boolean values are stored as one byte each.  
Groups of bools, however may be compacted into the same byte (bit-fields), 
as long as the reader and writer for a particular set of bools is consistent.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Integers}
\label{sec:common:expr:pint}

Integers are stored as 4 bytes each, unless noted otherwise.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Floating-point}
\label{app:common:expr:float}

Haven't added support for floating-point values yet.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Indices}
\label{app:common:expr:index}

An index is just a sequence of pointers to integer-expressions.  
Currently, the size limit is 4, the limit of number of dimensions
supported by the compiler.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Ranges}
\label{app:common:expr:range}

A range is a pair of pointers to integer-expressions.  

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Binary expressions}
\label{app:common:expr:binary}

All binary expressions are stored as:

\begin{enumerate}
\item char: representing the operation
\item pointer to left operand expression
\item pointer to right operand expression
\end{enumerate}

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\subsection{Unary expressions}
\label{app:common:expr:unary}

All unary expressions are stored as:

\begin{enumerate}
\item char: representing the operation
\item pointer to operand expression
\end{enumerate}



