Commit 94ba6543 authored by pknaggs's avatar pknaggs

Replaced ANS Forth specific sections with F94 retrospective

Added ISOForth section
Removed Differenced from Forth 83
Added outline for Differenced from Forth 94
parent 79079ffd
% !TeX root = forth.tex
% !TeX spellcheck = en_US
\cbstart
\cbstart\patch{compatibility}
\annex[Compatibility analysis]{Compatibility analysis of ANS Forth\strike{4}{80}} % D (informative annex)
\label{annex:diff}
\cbend
\label{annex:diff}
\setwordlist{core}
Prior to \replace{F94}{ANS Forth}{this standard}, there were several industry standards for Forth.
\replace{compatibility}{Prior to}{Before} this standard, there were several industry standards for Forth.
The most influential are listed here in chronological order, along
with the major differences between \replace{F94}{ANS Forth}{this standard} and the most recent,
\replace{F94}{Forth 83}{ANS Forth}.
with the major differences between this standard and the most recent,
\replace{compatibility}{ANS Forth}{Forth 94}.
\section{FIG Forth (circa 1978)} % D.1
......@@ -17,12 +17,12 @@ FIG Forth was a ``model'' implementation of the Forth language
developed by the Forth Interest Group (FIG). In FIG Forth, a
relatively small number of words were implemented in processor-dependent
machine language and the rest of the words were implemented in Forth.
The FIG model was placed in the public domain, and was ported to a
wide variety of computer systems. Because the bulk of the FIG Forth
The FIG model was placed in the public domain, and was ported to a wide
variety of computer systems. Because the bulk of the FIG Forth
implementation was the same across all machines, programs written in
FIG Forth enjoyed a substantial degree of portability, even for
``system-level'' programs that directly manipulate the internals of
the Forth system implementation.
``system-level'' programs that directly manipulate the internals
of the Forth system implementation.
FIG Forth implementations were influential in increasing the number
of people interested in using Forth. Many people associate the
......@@ -79,103 +79,115 @@ of successful Forth vendors did not convert their implementations to
be Forth 83 compliant. For example, the most successful commercial
Forth for Apple Macintosh computers is based on Forth 79.
\section{Recent developments} % D.4
\cbstart\patch{compatibility}
\section[Recent developments]{\sout{Recent developments}} % D.4
\label{diff:development}
\sout{%
Since the Forth-83 Standard was published, the computer industry has
undergone rapid and profound changes. The speed, memory capacity, and
disk capacity of affordable personal computers have increased by
factors of more than 100. 8-bit processors have given way to 16-bit
processors, and now 32-bit processors are commonplace.
processors, and now 32-bit processors are commonplace.}
\sout{%
The operating systems and programming-language environments of small
systems are much more powerful than they were in the early 80's.
systems are much more powerful than they were in the early 80's.}
\sout{%
The personal-computer marketplace has changed from a predominantly
``hobbyist'' market to a mature business and commercial market.
``hobbyist'' market to a mature business and commercial market.}
\sout{%
Improved technology for designing custom microprocessors has resulted
in the design of numerous ``Forth chips'', computers optimized for
the execution of the Forth language.
the execution of the Forth language.}
\sout{%
The market for ROM-based embedded control computers has grown
substantially.
substantially.}
\sout{%
In order to take full advantage of this evolving technology, and to
better compete with other programming languages, many recent Forth
implementations have ignored some of the ``rules'' of previous Forth
standards. In particular:
standards. In particular:}
\begin{itemize}
\item 32-bit Forth implementations are now common.
\item Some Forth systems adopt the address-alignment restrictions of
the hardware on which they run.
\item Some Forth systems use native-code generation, microcode
\item \sout{32-bit Forth implementations are now common.}
\item \sout{Some Forth systems adopt the address-alignment restrictions of
the hardware on which they run.}
\item \sout{Some Forth systems use native-code generation, microcode
generation, and optimization techniques, rather than the
traditional ``threaded code''.
\item Some Forth systems exploit segmented addressing architectures,
placing portions of the Forth ``dictionary'' in different segments.
\item More and more Forth systems now run in the environment of another
traditional ``threaded code''.}
\item \sout{Some Forth systems exploit segmented addressing architectures,
placing portions of the Forth ``dictionary'' in different segments.}
\item \sout{More and more Forth systems now run in the environment of another
``standard'' operating system, using OS text files for source code,
rather than the traditional Forth ``blocks''.
\item Some Forth systems allow external operating system software,
rather than the traditional Forth ``blocks''.}
\item \sout{Some Forth systems allow external operating system software,
windowing software, terminal con\-cen\-tratores, or communications
channels to handle or preprocess user input, resulting in deviations
from the input editing, character set availability, and screen
management behavior prescribed by Forth 83.
management behavior prescribed by Forth 83.}
\end{itemize}
\sout{%
Competitive pressure from other programming languages (predominantly
``C'') and from other Forth ven\-dors have led Forth vendors to
optimizations that do not fit in well with the ``virtual machine
model'' implied by existing Forth standards.
model'' implied by existing Forth standards.}
\cbstart\patch{F94}
\section[ANS Forth (1994)]{ANS Forth approach\strike{4}{60} (1994)\strike{-2}{40}} % D.5
\section[ANS Forth approach]{\sout{ANS Forth approach}} % D.5
\label{diff:ans}
\cbend
\sout{%
The ANS Forth committee addressed the serious fragmentation of the
Forth community caused by the differences between Forth 79 and
Forth 83, and the divergence from either of these two industry
standards caused by marketplace pressures.
standards caused by marketplace pressures.}
Consequently, the committee \replace{F94}{has chosen}{chose} to base its compatibility
\sout{%
Consequently, the committee has chosen to base its compatibility
decisions not upon a strict comparison with the Forth-83 Standard,
but instead upon consideration of the variety of existing
implementations, especially those with substantial user bases and/or
considerable success in the marketplace.
considerable success in the marketplace.}
The committee \replace{F94}{feels}{felt} that, if ANS Forth prescribes stringent
\sout{%
The committee feels that, if ANS Forth prescribes stringent
requirements upon the virtual machine model, as did the previous
standards, then many implementors will chose not to comply with
ANS Forth. The committee \replace{F94}{hopes}{hoped} that ANS Forth \replace{F94}{will}{would} serve to unify
ANS Forth. The committee hopes that ANS Forth will serve to unify
rather than to further divide the Forth community, and thus
\replace{F94}{has chosen}{chose} to encompass rather than invalidate popular implementation
techniques.
has chosen to encompass rather than invalidate popular implementation
techniques.}
Many of the changes from Forth 83 \replace{F94}{are}{where} justified by this rationale.
\sout{%
Many of the changes from Forth 83 are justified by this rationale.
Most fall into the category that ``an ANS Forth Standard Program may
not assume x'', where ``x'' is an entitlement resulting from the
virtual machine model prescribed by the Forth-83 Standard. The
committee \replace{F94}{feels}{felt} that these restrictions are reasonable, especially
committee feels that these restrictions are reasonable, especially
considering that a substantial number of existing Forth implementations
\replace{F94}{do}{that did} not correctly implement the Forth-83 virtual model, thus the Forth-83
entitlements exist ``in theory'' but not ``in practice''.
do not correctly implement the Forth-83 virtual model, thus the Forth-83
entitlements exist ``in theory'' but not ``in practice''.}
\sout{%
Another way of looking at this is that while ANS Forth acknowledges
the diversity of \remove{F94}{current} Forth practice, it \replace{F94}{attempts}{attempted} to document the
similarity therein. In some sense, ANS Forth \replace{F94}{is}{was} thus a ``description
the diversity of current Forth practice, it attempts to document the
similarity therein. In some sense, ANS Forth is thus a ``description
of reality'' rather than a ``prescription for a particular virtual
machine''.
machine''.}
\remove{F94}{%
\sout{%
Since there is no previous American National Standard for Forth, the
action requirements prescribed by section 3.4 of X3/SD-9,
``Policy and Guidelines'', regarding previous standards do not apply.
}
\remove{F94}{%
\sout{%
The following discussion describes differences between ANS Forth and
Forth 83. In most cases, Forth 83 is representative of Forth 79 and
FIG Forth for the purposes of this discussion. In many of these cases,
......@@ -183,13 +195,62 @@ however, ANS Forth is more representative of the existing state of the
Forth industry than the previously-published standards.
}
\place{F94}{The American National Standards Institution (ANSI) published
the ANS Forth Standard in 1994 with the title ``\emph{ANSI X3.215-1994
\section[ANS Forth (1994)]{\uline{ANS Forth (1994)}} % D.5
\uline{%
In the mid to late 1980s the computer industry underwent a rapid and
profound change. The personal-com\-put\-er market matured into a business
and commercial market, while the market for ROM-based embedded control
computers grew substantially. Improvements in custom processor design
allowed for the de\-vel\-op\-ment of numerous ``Forth chips,'' customized
for the execution of the Forth language.}
\uline{%
In order to take full advantage of evolving technology, many Forth
implementations ignored some of the restrictions imposed by the
implied ``virtual machine'' of previous standards.
The ANS Forth committee was formed in 1987 to address the fragmentation
within the Forth community caused not only by the difference between
Forth 79 and Forth 83 but the exploitation of technical developments.}
\uline{%
The committee undertook a comprehensive review of a variety of existing
implementations, especially those with substantial user bases and/or
considerable success in the market place. This allowed them to identify
and document features common to these systems, many of which had not been
included in any previous standard.}
\uline{%
The committee chose to move away from prescribing stringent requirements
as previous standards had, with the specification of a virtual machine.
It preferred to describe the operation of the virtual machine, without
reference to its implementation, thus allowing an implementor to take
full advantage of any technical developments while providing the
developer with a complete list of entitlements.}
\uline{%
This required the identification of implicit assumptions made by the
previous standards, making them explicit and abstracting them into
more general concepts where possible. A good example of this is the
size of an item on the stack. In previous standards this was assumed
to be 16-bits wide. This was no longer a valid assumption. ANS Forth
introduced the concept of the \emph{cell}, allowing the an implementation
to use a stack size most suited to the environment.}
\uline{%
This was the most comprehensive review of Forth systems to date, taking
eighty seven days covering twenty three meetings over eight years.
The inclusive nature of the standard allowed the various factions within
the community to unify in support of ANS Forth, with many systems
providing a comparability layer.}
\uline{%
The American National Standards Institution (ANSI) published the ANS
Forth Standard in 1994 with the title ``\emph{ANSI X3.215-1994
Information Systems --- Programming Language FORTH}''. This is referenced
throughout this document as Forth 94.}
\cbstart\patch{F94}
\section[ISO Forth (1997)]{ISO Forth (1997)\strike{-2}{110}}
\section[ISO Forth (1997)]{\uline{ISO Forth (1997)}}
\label{diff:iso}
\uline{%
......@@ -201,93 +262,126 @@ The ISO/IEC adopted the Forth 94 document as an international standard
in 1997, publishing it under the title ``\emph{ISO/IEC 15145:1997
Information technology. Programming languages. FORTH}''.
}
\cbend
\section{Differences from Forth 83} % D.6
\place{F94}{%
The following discussion describes differences between this standard and
Forth 83. In most cases, Forth 83 is representative of Forth 79 and
FIG Forth for the purposes of this discussion. In many of these cases,
however, this standard is more representative of the existing state of the
Forth industry than the previously-published standards.
}
\section[Approach of this Standard]{\uline{Approach of this Standard}} % D.6
\label{diff:approach}
\subsection{Stack width} % D.6.1
\uline{%
During a workshop on the Forth standard at the EuroForth conference in
2004 it was agreed that the Forth 94 required updating.}
\uline{%
A committee was formed and agreed that the process should be as open
as possible, adopting the Usenet RfD/CfV (Request for Discussion/Call
for Votes) process to produce semi-formal proposals for changes to the
standard. In addition to general discussion on the \texttt{comp.lang.forth}
usenet news group, a moderated mailing list (with public archive) was
created for those who do not follow the news group.
Standards meetings to discuss CfVs were held in public in
conjunction with the EuroForth conference.}
\uline{%
The work of the Forth 94 Committee was the basis of this standard,
informally called Forth 200\emph{x}. The aim of the Forth 200\emph{x}
committe is to produce a rolling document, with the standard constantly
being updated based on discussion of proposals and the corresponding
votes. A snapshot document is occasionally produced, with this document
being the first.}
\uline{%
The Forth 200\emph{x} committee defined a procedure for proposals. In
addition to the formal text of the proposal, they had to include:
the rationale behind the change;
a reference implementation, or a description of the reason a reference
implementation cannot be presented;
unit testing for the proposed change, especially for border conditions.
See \xref[Process]{process} (page \pageref{process}) for a full description.}
\section[Differences from Forth 83]{\sout{Differences from Forth 83}} % D.6
\subsection[Stack width]{\sout{Stack width}} % D.6.1
\sout{%
Forth 83 specifies that stack items occupy 16 bits. This includes
addresses, flags, and numbers. ANS Forth specifies that stack items
are at least 16 bits; the actual size must be documented by the
implementation.
implementation.}
\begin{description}
\item[Words affected:]
all arithmetic, logical and addressing operators
\item[\sout{Words affected:}]
\sout{all arithmetic, logical and addressing operators}
\item[Reason:]
32-bit machines are becoming commonplace. A 16-bit Forth
system on a 32-bit machine is not competitive.
\item[\sout{Reason:}]
\sout{32-bit machines are becoming commonplace. A 16-bit Forth
system on a 32-bit machine is not competitive.}
\item[Impact:]
Programs that assume 16-bit stack width will continue to run on
\item[\sout{Impact:}]
\sout{Programs that assume 16-bit stack width will continue to run on
16-bit machines; ANS Forth does not require a different stack
width, but simply allows it. Many programs will be unaffected
(but see ``address unit'').
(but see ``address unit'').}
\item[Transition/Conversion:]
Programs which use bit masks with the high bits set may have to
\item[\sout{Transition/Conversion:}]
\sout{Programs which use bit masks with the high bits set may have to
be changed, substituting either an implementation-defined bit-mask
constant, or a procedure to calculate a bit mask in a
stack-width-independent way. Here are some procedures for
constructing width-in\-de\-pend\-ent bit masks:
constructing width-in\-de\-pend\-ent bit masks:}
\begin{tt}
1 \word{CONSTANT} LO-BIT \\
\word{TRUE} 1 \word{RSHIFT}
\sout{1 \word{CONSTANT} LO-BIT} \\
\sout{\word{TRUE} 1 \word{RSHIFT}
\quad \word{INVERT}
\quad \word{CONSTANT} HI-BIT \\
\word{:} LO-BITS \word{p} n -{}- mask )
\quad \word{CONSTANT} HI-BIT} \\
\sout{\word{:} LO-BITS \word{p} n -{}- mask )
0 \word{SWAP} 0 \word{qDO}
1 \word{LSHIFT} LO-BIT \word{OR}
\word{LOOP}
\word{;} \\
\word{:} HI-BITS \word{p} n -{}- mask )
\word{;}} \\
\sout{\word{:} HI-BITS \word{p} n -{}- mask )
0 \word{SWAP} 0 \word{qDO}
1 \word{RSHIFT} HI-BIT \word{OR}
\word{LOOP}
\word{;}
\word{;}}
\end{tt}
\end{description}
\sout{%
Programs that depend upon the ``modulo 65536'' behavior implicit in
16-bit arithmetic operations will need to be rewritten to explicitly
perform the modulus operation in the appropriate places. The committee
believes that such assumptions occur infrequently. Examples: some
checksum or CRC calculations, some random number generators and most
fixed-point fractional math.
fixed-point fractional math.}
\subsection{Number representation} % D.6.2
\subsection[Number representation]{\sout{Number representation}} % D.6.2
\sout{%
Forth 83 specifies two's-complement number representation and
arithmetic. ANS Forth also allows one's-complement and
signed-magnitude.
signed-magnitude.}
\begin{description}
\item[Words affected:]
\item[\sout{Words affected:}]
\sout{%
all arithmetic and logical operators,
\word{LOOP},
\word{+LOOP}.
\word{+LOOP}.}
\item[Reason:]
\item[\sout{Reason:}]
\sout{%
Some computers use one's-complement or signed-magnitude. The
committee did not wish to force Forth implementations for those
machines to emulate two's-complement arithmetic, and thus incur
severe performance penalties. The experience of some committee
members with such machines indicates that the usage restrictions
necessary to support their number representations are not overly
burdensome.
burdensome.}
\item[Impact:]
\item[\sout{Impact:}]
\sout{%
An ANS Forth Standard Program may declare an ``environmental
dependency on two's-com\-ple\-ment arithmetic''. This means that the
otherwise-Standard Program is only guaranteed to work on
......@@ -296,9 +390,10 @@ signed-magnitude.
computers use two's-complement. The committee knows of no Forth-83
com\-pli\-ant implementations for non-two's-complement machines at
present, so existing Forth-83 programs will still work on the same
class of machines on which they currently work.
class of machines on which they currently work.}
\item[Transition/Conversion:]
\item[\sout{Transition/Conversion:}]
\sout{%
Existing programs wishing to take advantage of the possibility of
ANS Forth Standard Systems on non-two's-complement machines may
do so by eliminating the use of a\-rith\-me\-tic operators to perform
......@@ -306,28 +401,31 @@ signed-magnitude.
operations as described in the section about stack width, by
restricting the usage range of unsigned numbers to the range of
positive numbers, and by using the provided operators for
conversion from single numbers to double numbers.
conversion from single numbers to double numbers.}
\end{description}
\subsection{Address units} % D.6.3
\subsection[Address units]{\sout{Address units}} % D.6.3
\sout{%
Forth 83 specifies that each unique address refers to an 8-bit byte
in memory. ANS Forth specifies that the size of the item referred to
by each unique address is implementation-defined, but, by default,
is the size of one character. Forth 83 describes many memory
operations in terms of a number of bytes. ANS Forth describes those
operations in terms of a number of either characters or address
units.
units.}
\begin{description}
\item[Words affected:]
those with ``address unit'' arguments
\item[\sout{Words affected:}]
\sout{those with ``address unit'' arguments}
\item[Reason:]
\item[\sout{Reason:}]
\sout{%
Some machines, including the most popular Forth chip, address
16-bit memory locations instead of 8-bit bytes.
16-bit memory locations instead of 8-bit bytes.}
\item[Impact:]
\item[\sout{Impact:}]
\sout{%
Programs may choose to declare an environmental dependency on
byte addressing, and will continue to work on the class of
machines for which they now work. In order for a Forth
......@@ -337,169 +435,191 @@ units.
knows of no such Forth-83 implementations for such machines,
thus an environmental dependency on byte addressing does not
restrict a Standard Program beyond its current de facto
restrictions.
restrictions.}
\item[Transition/Conversion:]
\item[\sout{Transition/Conversion:}]
\sout{%
The new \word{CHARS} and \word{CHAR+} address arithmetic operators
should be used for programs that require portability to
non-byte-addressed machines. The places where such conversion is
necessary may be identified by searching for occurrences of words
that accept a number of address units as an argument (e.g.,
\word{MOVE}, \word{ALLOT}).
\word{MOVE}, \word{ALLOT}).}
\end{description}
\subsection{Address increment for a cell is no longer two} % D.6.4
\subsection[Address increment for a cell is no longer two]{\sout{Address increment for a cell is no longer two}} % D.6.4
\sout{%
As a consequence of Forth-83's simultaneous specification of 16-bit
stack width and byte addressing, the number two could reliably be used
in address calculations involving memory arrays containing items from
the stack. Since ANS Forth requires neither 16-bit stack width nor
byte addressing, the number two is no longer necessarily appropriate
for such calculations.
for such calculations.}
\begin{description}
\item[Words affected:]
\item[\sout{Words affected:}]
\sout{%
\word{@} \word{!} \word{+!} \texttt{2+}
\word{2*} \texttt{2-} \word{+LOOP}
\word{2*} \texttt{2-} \word{+LOOP}}
\item[Reason:]
See reasons for ``Address Units'' and ``Stack Width''
\item[\sout{Reason:}]
\sout{%
See reasons for ``Address Units'' and ``Stack Width''}
\item[Impact:]
\item[\sout{Impact:}]
\sout{%
In this respect, existing programs will continue to work on
machines where a stack cell occupies two address units when
stored in memory. This includes most machines for which
Forth 83 compliant implementations currently exist. In principle,
it would also include 16-bit-word-addressed machines with 32-bit
stack width, but the committee knows of no examples of such
machines.
machines.}
\item[Transition/Conversion:]
\item[\sout{Transition/Conversion:}]
\sout{%
The new \word{CELLS} and \word{CELL+} address arithmetic operators
should be used for portable programs. The places where such
conversion is necessary may be identified by searching for the
character ``2'' and determining whether or not it is used as part
of an address calculation. The following substitutions are
appropriate within address calculations:
appropriate within address calculations:}
\begin{center}
\begin{tabular}{cl}
\hline\hline
Old & New \\
\sout{Old} & \sout{New} \\
\hline
\texttt{2+} or \texttt{2} \word{+} & \word{CELL+} \\
\word{2*} or \texttt{2} \word{*} & \word{CELLS} \\
\texttt{2-} or \texttt{2} \word{-} & 1 \word{CELLS} \word{-} \\
\word{2/} or \texttt{2} \word{/} & 1 \word{CELLS} \word{/} \\
\texttt{2} & 1 \word{CELLS} \\
\sout{\texttt{2+} or \texttt{2} \word{+}} & \sout{\word{CELL+}} \\
\sout{\word{2*} or \texttt{2} \word{*}} & \sout{\word{CELLS}} \\
\sout{\texttt{2-} or \texttt{2} \word{-}} & \sout{1 \word{CELLS} \word{-}} \\
\sout{\word{2/} or \texttt{2} \word{/}} & \sout{1 \word{CELLS} \word{/}} \\
\sout{\texttt{2}} & \sout{1 \word{CELLS}} \\
\hline\hline
\end{tabular}
\end{center}
\end{description}
\sout{%
The number ``2'' by itself is sometimes used for address calculations
as an argument to \word{+LOOP}, when the loop index is an address. When
converting the word \word{2/} which operates on negative dividends, one
should be cognizant of the rounding method used.
should be cognizant of the rounding method used.}
\subsection{Address alignment} % D.6.5
\subsection[Address alignment]{\sout{Address alignment}} % D.6.5
\sout{%
Forth 83 imposes no restriction upon the alignment of addresses to
any boundary. ANS Forth specifies that a Standard System may require
alignment of addresses for use with various ``\word{@}'' and
``\word{!}'' operators.
``\word{!}'' operators.}
\begin{description}
\item[Words Affected:]
\item[\sout{Words Affected:}]
\sout{%
\word{!} \word{+!} \word{2!} \word{2@}
\word{@} \word[tools]{q} \word{,}
\word{@} \word[tools]{q} \word{,}}
\item[Reason:]
\item[\sout{Reason:}]
\sout{%
Many computers have hardware restrictions that favor the use of
aligned addresses. On some machines, the native memory-access
instructions will cause an exception trap if used with an
unaligned address. Even on machines where unaligned accesses do
not cause exception traps, aligned accesses are usually faster.
not cause exception traps, aligned accesses are usually faster.}
\item[Impact:]
\item[\sout{Impact:}]
\sout{%
All of the ANS Forth words that return addresses suitable for
use with aligned ``\word{@}'' and ``\word{!}'' words must return
aligned addresses. In most cases, there will be no problem.
Problems can arise from the use of user-defined data structures
containing a mixture of character data and cell-sized data.
containing a mixture of character data and cell-sized data.}
\sout{%
Many existing Forth systems, especially those currently in use on
computers with strong alignment requirements, already require
alignment. Much existing Forth code that is currently in use on
such machines has already been converted for use in an aligned
environment.
environment.}
\item[Transition/Conversion:]
\item[\sout{Transition/Conversion:}]
\sout{%
There are two possible approaches to conversion of programs for
use on a system requiring address alignment.
use on a system requiring address alignment.}
\sout{%
The easiest approach is to redefine the system's aligned
``\word{@}'' and ``\word{!}'' operators so that they do not
require alignment. For example, on a 16-bit little-endian
byte-addressed machine, unaligned ``\word{@}'' and ``\word{!}''
could be defined:
could be defined:}
\begin{quote}\ttfamily
\word{:} \word{@} \word{p} addr -{}- x )
\sout{\word{:} \word{@} \word{p} addr -{}- x )
\word{DUP} \word{C@} \word{SWAP}
\word{CHAR+} \word{C@} 8
\word{LSHIFT} \word{OR}
\word{;} \\
\word{:} \word{!} \word{p} x addr -{}- )
\word{;}} \\
\sout{\word{:} \word{!} \word{p} x addr -{}- )
\word{OVER} 8 \word{RSHIFT}
\word{OVER} \word{CHAR+}
\word{C!} \word{C!}
\word{;}
\word{;}}
\end{quote}
\sout{%
These definitions, and similar ones for ``\word{+!}'',
``\word{2@}'', ``\word{2!}'', ``\word{,}'', and
``\word[tools]{q}'' as needed, can be compiled before an
unaligned application, which will then work as expected.
unaligned application, which will then work as expected.}
\sout{%
This approach may conserve memory if the application uses
substantial numbers of data structures containing unaligned
fields.
fields.}
\sout{%
Another approach is to modify the application's source code to
eliminate unaligned data fields. The ANS Forth words \word{ALIGN}
and \word{ALIGNED} may be used to force alignment of data fields.
The places where such alignment is needed may be determined by
inspecting the parts of the application where data structures
(other than simple variables) are defined, or by ``smart compiler''
techniques (see the ``Smart Compiler'' discussion below).
techniques (see the ``Smart Compiler'' discussion below).}
\sout{%
This approach will probably result in faster application execution
speed, at the possible expense of increased memory utilization for
data structures.
data structures.}
\sout{%
Finally, it is possible to combine the preceding techniques by
identifying exactly those data fields that are unaligned, and
using ``unaligned'' versions of the memory access operators for
only those fields. This ``hybrid'' approach affects a compromise
between execution speed and memory utilization.
between execution speed and memory utilization.}
\end{description}
\subsection{Division/modulus rounding direction} % D.6.6
\subsection[Division/modulus rounding direction]{\sout{Division/modulus rounding direction}} % D.6.6
\sout{%
Forth 79 specifies that division rounds toward 0 and the remainder
carries the sign of the dividend. Forth 83 specifies that division
rounds toward negative infinity and the remainder carries the sign
of the divisor. ANS Forth allows either behavior for the division
operators listed below, at the discretion of the implementor, and
provides a pair of division primitives to allow the user to
synthesize either explicit behavior.
synthesize either explicit behavior.}
\begin{description}
\item[Words Affected:]
\item[\sout{Words Affected:}]
\sout{%
\word{/} \word{MOD} \word{/MOD}
\word{*/MOD} \word{*/}
\word{*/MOD} \word{*/}}
\item[Reason:]
\item[\sout{Reason:}]
\sout{%
The difference between the division behaviors in Forth 79 and
Forth 83 was a point of much contention, and many Forth
implementations did not switch to the Forth 83 behavior. Both
......@@ -517,16 +637,18 @@ synthesize either explicit behavior.
the behavior that is supported by the native CPU instruction set,
thus maximizing execution speed, or could choose the behavior
that is most appropriate for the intended application domain of
the system.
the system.}
\item[Impact:]
\item[\sout{Impact:}]
\sout{%
The issue only affects programs that use a negative dividend with
a positive divisor, or a positive dividend with a negative divisor.
The vast majority of uses of division occur with both a positive
dividend and a positive divisor; in that case, the results are the
same for both allowed division behaviors.
same for both allowed division behaviors.}
\item[Transition/Conversion:]
\item[\sout{Transition/Conversion:}]
\sout{%
For programs that require a specific rounding behavior with division
operands of mixed sign, the division operators used by the program
may be redefined in terms of one of the new ANS Forth division
......@@ -534,45 +656,49 @@ synthesize either explicit behavior.
zero) or \word{FM/MOD} (floored division, i.e., round toward
negative infinity). Then the program may be recompiled without
change. For example, the Forth 83 style division operators may be
defined by:
defined by:}
\begin{quote}\ttfamily
\word{:} \word{/MOD}~ \word{p} n1 n2 -{}- n3 n4 ) ~~
\word{toR} \word{StoD} \word{Rfrom} \word{FM/MOD} \word{;} \\
\word{:} \word{MOD}~~ \word{p} n1 n2 -{}- n3 ) ~~~~~
\word{/MOD} \word{DROP} \word{;} \\
\word{:} \word{/}~~~~ \word{p} n1 n2 -{}- n3 ) ~~~~~
\word{/MOD} \word{SWAP} \word{DROP} \word{;} \\
\word{:} \word{*/MOD} \word{p} n1 n2 n3 -{}- n4 n5 )
\word{toR} \word{M*} \word{Rfrom} \word{FM/MOD} \word{;} \\
\word{:} \word{*/}~~~ \word{p} n1 n2 n3 -{}- n4 n5 )
\word{*/MOD} \word{SWAP} \word{DROP} \word{;} \\
\sout{\word{:} \word{/MOD}~ \word{p} n1 n2 -{}- n3 n4 ) ~~
\word{toR} \word{StoD} \word{Rfrom} \word{FM/MOD} \word{;}} \\
\sout{\word{:} \word{MOD}~~ \word{p} n1 n2 -{}- n3 ) ~~~~~
\word{/MOD} \word{DROP} \word{;}} \\
\sout{\word{:} \word{/}~~~~ \word{p} n1 n2 -{}- n3 ) ~~~~~
\word{/MOD} \word{SWAP} \word{DROP} \word{;}} \\
\sout{\word{:} \word{*/MOD} \word{p} n1 n2 n3 -{}- n4 n5 )
\word{toR} \word{M*} \word{Rfrom} \word{FM/MOD} \word{;}} \\
\sout{\word{:} \word{*/}~~~ \word{p} n1 n2 n3 -{}- n4 n5 )
\word{*/MOD} \word{SWAP} \word{DROP} \word{;}} \\
\end{quote}
\end{description}
\subsection{Immediacy} % D.6.7
\subsection[Immediacy]{\sout{Immediacy}} % D.6.7
\label{diff:immediate}
\sout{%
Forth 83 specified that a number of ``compiling words'' are
``immediate'', meaning that they are executed instead of compiled