]> thyrsus.com Git - mad.git/commitdiff
More appendix text.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 25 May 2004 16:57:30 +0000 (16:57 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 25 May 2004 16:57:30 +0000 (16:57 +0000)
doc/mad-manual.xml

index 44c5da56b18447df18d2dd7d44a4727bff3bff13..ea10d8300fff9554b1beebb87fd14c130c110af5 100644 (file)
@@ -5021,6 +5021,93 @@ character, such as *, +(binary), -(binary), or /.  Unary minus can be
 referred to in such statements by the name -U.  Unary plus should not
 be used.</para>
 
+</sect1>
+<sect1><title>The MODE STRUCTURE STATEMENT</title>
+
+<para>The choice of an appropriate sequence of instructions to perform
+a given operation assumes knowledge not only of the operator in
+question, but also of the modes of the operands.  Thus A + B will be
+computed via one sequence if A and B are both floating point numbers,
+and via the same floating point sequence preceeded by an
+integer-to-floating point conversion sequence if one of the operands
+is an integer and the other is a floating point number.  The
+specification of an operator together with the modes of its operands
+(or operand, if unary) will be called a <emphasis>context</emphasis>,
+and indicated by expressions such as 1 + 1, 0 .ADD. 0, .ABS. 0, 1
+.P. 0.  In these expressions, the integers represent the
+<emphasis>modes</emphasis> of the operands, and if the operator is
+unary, the mode is given only for the right-most (or
+<emphasis>b</emphasis>) operand position.  The left operand will be
+referred to as the <emphasis>a</emphasis> operand.</para>
+
+<para>A <emphasis>mode scheme</emphasis> may be described as being of
+one of two types:</para>
+
+<para>(1) <emphasis>M TO r,</emphasis> used for operator definitions, or
+<emphasis>M TO N,</emphasis> where M and N are contexts containing the
+same operators but different in exactly one operand mode, and r is a
+mode number.  Examples of mode schemes are 2 .LOGADD .2 to 2, 1 + 1 TO
+1, 1 .ADD. 0 To 1 .ADD. 1.  In the first case the operator .LOGADD. is
+applied to two Boolean arguents to produce a Boolean result.  In the
+second case we have ordinary integer addition, producing an integer
+result.  The third example illustrates a mode conversion.  The
+operator .ADD. has occurred with an <emphasis>a</emphasis> operand in
+floating point mode and a <emphasis>b</emphasis> operand in integer
+mode.  The mode scheme given describes the conversation of the
+<emphasis>b</emphasis> operand to floating point mode.  These schemes
+are used in MODE STRUCTURE statements (see below) to indicate the
+effect of the associated sequence on the operands involved.  Reference
+will be made below to schemes of "type 1" and "type 2" as indicated
+above, and to the M and N contexts and the mode number r which appear
+in these schemes.</para>
+
+<para>After the DEFINE statement (but not necessarily immediately
+after) must be one or more <emphasis>sequence definition
+programs</emphasis>.  Each of these programs consists of one MODE
+STRUCTURE statement followed by a "sequence".  In case a new mode is
+created, one may find occasion to write definition programs without
+any new operators being defined.</para>
+
+<!-- in the original, first occurrence of "type" lacked a closing quote -->
+<para>Immediately after the words MODE STRUCTURE is a list of one or more
+mode schemes, separated by commas.  In any one MODE STRUCTURE
+statement all mode schemes must be of the same "type" (see above),
+which will then be referred to as the "type" of the MODE STRUCTURE
+statement itself, and as the "type" of the sequence definition program
+which contains this statement.  A statement of type I will precede a
+sequence which will accept as input one or two operands and produce a
+result.  (See "sequence" below.)  The "sequence" will be inserted in
+the object program, however, only when the operator and modes of the
+operands correspond to a context appearing in one of the mode schems
+in the MODE STRUCTURE statement.  Thus, in the example above, if the
+operator .LOGADD. appears between two operands of Boolean or integer
+mode, the sequence which follows will be processed as outlined below.
+If .LOGADD. appears between two operands, either (or both) of which is
+of a different mode, this sequence will not be applicable.  If no
+other sequence definition programs are provided, the context being
+translated is illegal, and an error indication is produced.  the mode
+number r is taken as the mode of the result of the computation which
+results from the sequence.  This is needed in establishing contexts of
+succeeding operations.</para>
+
+<para>Since schemes of type 2 require their M and N contexts to agree in the
+operator they contain and one of the mode numbers, they have the form:
+2.LOGADD. 1 to 2 .LOGADD. 2.  The sequence which follows a MODE
+STRUCTURE statement containing <emphasis>this</emphasis> scheme will
+be written so as to perform the conversion of the second operand of
+.LOGADD. from integer to Boolean form in some manner.</para>
+
+<para>The following general rules apply to all sequence definition
+programs:</para>
+
+<para>(1) A context appearing in an M position may not already exist in the
+MAD language or appear in the M position in another MODE STRUCTURE
+statement.</para>
+
+<para>(2) Every context appearing in the program containing the
+definition program must appear in an M position in some MODE STRUCTURE
+statement.  This applies in particular to contexts occurring in N
+positions in MODE STRUCTURE statements of type 2.</para>
 
 </sect1>
 </appendix>