next up previous contents index
Next: Expression simplification Up: Pre-translation Previous: Pre-translation   Contents   Index


Restricted Form

So far as the HPJava translator is concerned, a program is in restricted form if it respects certain limits on the complexity of expressions involving multiarrays. First we give two definitions:

Now the restrictions on expressions are:

  1. A composite multiarray expression may only appear as the right-hand-side of a top-level assignment (or, in the case of multiarray-valued method invocation, as a standalone statement expression). Here, a top-level assignment is defined to be an assignment expression appearing as a statement expression in a program block. This specifically excludes assignments appearing in for-loop headers. Also note that a variable declarator with an initializer is not an assignment expression, so the restricted form does not allow composite multiarray expressions to appear as initializers in declarations.
  2. All of the following must be simple expressions:
    a) the target object in accesses to multiarray-valued fields,
    b) the boolean expression in a multiarray-valued conditional expressions, and
    c) the array operand in array-restriction expression,
    d) the array operand of multiarray inquiry operations (rng(), grp(), etc)A.4,
    e) the range and group parameters of multiarray creation expressions,
    f) the range expression in the header of overall and at constructs.
In principle reducing a program to restricted form is a straightforward matter of precomputing subexpressions that break the rules above, and saving their values in temporary variables introduced by the pre-translator. Of course the subexpressions of the original expression are replaced by accesses to the temporaries.

Figures A.2 and A.3 illustrate the process of expression simplification. The source program is a slightly esoteric example involving array restriction, taken from section 4.8. In this example pre-translation shifts three kinds of composite array expression--multiarray creation, array section and array restriction--into top-level assignments. In the case of the array creation expressions it simply has to split the array declarations with initializers to blank declarations plus an assignment. In the case of the sections and restrictions, it has to introduce temporaries.

Figure A.2: Example source program prior to pre-translation.

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Proc...
... [[i, :]] / j, b [[:, j]] / i) ;
}\end{verbatim}\end{minipage}\end{displaymath}

Figure A.3: Example source program after pre-translation.

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Proc...
...ib.dotProduct(__$t2, __$t4) ;
}
}\end{verbatim}\end{minipage}\end{displaymath}

Besides simplifying variables, the pre-translation phase also breaks up multiarray declarations that declare several variables, outputting a series of declarations of individual multiarray variables. This slightly simplifies the work of the translation phase.


next up previous contents index
Next: Expression simplification Up: Pre-translation Previous: Pre-translation   Contents   Index
Bryan Carpenter 2003-04-15