docs: the FORTH standards v4 is held to -- FORTH-79, FORTH-83, ANS Forth 1994 (#189)
Captain Bob, 2026-11-14: the standard first, in the order 79, 83, ANS, then v3; the texts in the repository as references. FORTH-79 and FORTH-83 from the University of Vienna's FORTH archive (complang.tuwien.ac.at), ANS Forth's final draft (dpANS) from Taygeta, as fetched, with their sources in docs/reference/standards/README.md. Not pushed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
# The FORTH standards v4 is held to
|
||||
|
||||
Captain Bob, 2026-11-14, on v3's whole POST (#189 Phase 7; `docs/v4.0.0/POST-PARITY.md`): **"The standard
|
||||
first"**, in this order -- FORTH-79, then FORTH-83 for what 79 lacks, then ANS Forth 1994 for what both lack,
|
||||
then v3 (held to its own table where v3 contradicts it) only for what no standard defines. And: "Put the two
|
||||
standards' texts ... into the repository as references" -- "Yes, docs/reference/standards/".
|
||||
|
||||
| File | What | From (fetched 2026-11-14) |
|
||||
|---|---|---|
|
||||
| `FORTH-79.TXT` | The FORTH-79 Standard | https://www.complang.tuwien.ac.at/forth/fth79std/FORTH-79.TXT |
|
||||
| `FORTH83.TXT` | The FORTH-83 Standard | https://www.complang.tuwien.ac.at/forth/fth83std/FORTH83.TXT |
|
||||
| `ans94/` | ANS Forth (X3J14 dpANS-6, the 1994 standard's final draft), as HTML | https://www.taygeta.com/forth/dpans.htm |
|
||||
|
||||
Kept as fetched, unedited. A ruling or a POST rule that rests on one of them cites the file and the word's
|
||||
entry (or the section).
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpans4.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpans6.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=5.>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
<H1>5. Compliance and labeling</H1>
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=5.1>
|
||||
<H2>5.1 ANS Forth systems</H2>
|
||||
</a>
|
||||
|
||||
<p>
|
||||
<code>
|
||||
See:
|
||||
<a href=dpansa5.htm#A.5.1>A.5.1</a> ANS Forth systems
|
||||
</code>
|
||||
<p>
|
||||
|
||||
<hr>
|
||||
<A name=5.1.1>
|
||||
<H3>5.1.1 System compliance</H3>
|
||||
</a>
|
||||
|
||||
A system that complies with all the system requirements given in
|
||||
sections
|
||||
<a href=dpans3.htm#3.>3.</a> Usage requirements and
|
||||
<a href=dpans4.htm#4.1>4.1</a> System documentation and their
|
||||
sub-sections is a Standard System. An otherwise Standard System that
|
||||
provides only a portion of the Core words is a Standard System Subset.
|
||||
An otherwise Standard System (Subset) that fails to comply with one or
|
||||
more of the minimum values or ranges specified in
|
||||
<a href=dpans3.htm#3.>3.</a> Usage requirements
|
||||
and its sub-sections has environmental restrictions.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=5.1.2>
|
||||
<H3>5.1.2 System labeling</H3>
|
||||
</a>
|
||||
|
||||
A Standard System (Subset) shall be labeled an <B>ANS Forth System
|
||||
(Subset)</B>. That label, by itself, shall not be applied to Standard
|
||||
Systems or Standard System Subsets that have environmental restrictions.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>with Environmental Restrictions</B> shall be appended to
|
||||
the label of a Standard System (Subset) that has environmental
|
||||
restrictions.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>Providing name(s) from the Core Extensions word set</B>
|
||||
shall be appended to the label of any Standard System that provides
|
||||
portions of the Core Extensions word set.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>Providing the Core Extensions word set</B> shall be
|
||||
appended to the label of any Standard System that provides all of the
|
||||
Core Extensions word set.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=5.2>
|
||||
<H2>5.2 ANS Forth programs</H2>
|
||||
</a>
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=5.2.1>
|
||||
<H3>5.2.1 Program compliance</H3>
|
||||
</a>
|
||||
|
||||
A program that complies with all the program requirements given in
|
||||
sections
|
||||
<a href=dpans3.htm#3.>3.</a> Usage requirements and
|
||||
<a href=dpans4.htm#4.2>4.2</a> Program documentation and their
|
||||
sub-sections is a Standard Program.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=5.2.2>
|
||||
<H3>5.2.2 Program labeling</H3>
|
||||
</a>
|
||||
|
||||
A Standard Program shall be labeled an <B>ANS Forth Program</B>. That
|
||||
label, by itself, shall not be applied to Standard Programs that require
|
||||
the system to provide standard words outside the Core word set or that
|
||||
have environmental dependencies.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>with Environmental Dependencies</B> shall be appended to
|
||||
the label of Standard Programs that have environmental dependencies.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>Requiring name(s) from the Core Extensions word set</B>
|
||||
shall be appended to the label of Standard Programs that require the
|
||||
system to provide portions of the Core Extensions word set.
|
||||
|
||||
<P>
|
||||
|
||||
The phrase <B>Requiring the Core Extensions word set</B> shall be
|
||||
appended to the label of Standard Programs that require the system to
|
||||
provide all of the Core Extensions word set.
|
||||
|
||||
<P>
|
||||
<code>
|
||||
See:
|
||||
<a href=dpansa5.htm#A.5.2.2>A.5.2.2</a> Program labeling
|
||||
</code>
|
||||
<p>
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpans6.htm><IMG src="right.gif" ></A> Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,234 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpans17.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpansa2.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=A.>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
<H1>A. Rationale (informative annex)</H1>
|
||||
|
||||
|
||||
<hr>
|
||||
<a name=A.1>
|
||||
<H2>A.1 Introduction</H2>
|
||||
</a>
|
||||
|
||||
<hr>
|
||||
<a name=A.1.1></A>
|
||||
<H3>A.1.1 Purpose</H3>
|
||||
</a>
|
||||
|
||||
|
||||
<hr>
|
||||
<a name=A.1.2>
|
||||
<H3>A.1.2 Scope</H3>
|
||||
</a>
|
||||
|
||||
This Standard is more extensive than previous industry standards for the Forth
|
||||
language. Several things made this necessary:
|
||||
|
||||
<UL>
|
||||
<LI>the desire to resolve conflicts between previous standards;
|
||||
<LI>the need to eliminate semantic ambiguities and other inadequacies;
|
||||
<LI>the requirement to standardize common practice, where possible
|
||||
resolving divergences in a way that minimizes the cost of compliance;
|
||||
<LI>the desire to standardize common system techniques, including those
|
||||
germane to hardware.
|
||||
</UL>
|
||||
<P>
|
||||
|
||||
The result of the effort to satisfy all of these objectives is a
|
||||
Standard arranged so that the required word set remains small. Thus ANS
|
||||
Forth can be provided for resource-constrained embedded systems. Words
|
||||
beyond those in the required word set are organized into a number of
|
||||
optional word sets and their extensions, enabling implementation of
|
||||
tailored systems that are Standard.
|
||||
|
||||
<P>
|
||||
|
||||
When judging relative merits, the members of the X3J14 Technical
|
||||
Committee were guided by the following goals (listed in alphabetic
|
||||
order):
|
||||
|
||||
<P>
|
||||
|
||||
<DL>
|
||||
<DT><B>Consistency</B>
|
||||
<DD>The Standard provides a functionally complete
|
||||
set of words
|
||||
with minimal functional overlap.
|
||||
|
||||
<DT><B>Cost of compliance</B>
|
||||
<DD>This goal includes such issues as common
|
||||
practice, how
|
||||
much existing code would be broken by the proposed change, and the amount of
|
||||
effort required to bring existing applications and systems into conformity
|
||||
with the Standard.
|
||||
|
||||
<DT><B>Efficiency</B>
|
||||
<DD>Execution speed, memory compactness.
|
||||
|
||||
<DT><B>Portability</B>
|
||||
<DD>Words chosen for inclusion should be free of
|
||||
system-dependent
|
||||
features.
|
||||
|
||||
<DT><B>Readability</B>
|
||||
<DD>Forth definition names should clearly delineate
|
||||
their
|
||||
behavior. That behavior should have an apparent simplicity which supports
|
||||
rapid understanding. Forth should be easily taught and support readily
|
||||
maintained code.
|
||||
|
||||
<DT><B>Utility</B>
|
||||
<DD>Be judged to have sufficiently essential functionality
|
||||
and frequency
|
||||
of use to be deemed suitable for inclusion.</DL>
|
||||
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<a name=A.1.3>
|
||||
<H3>A.1.3 Document organization</H3>
|
||||
</a>
|
||||
|
||||
|
||||
<hr>
|
||||
<a name=A.1.3.1>
|
||||
<H4>A.1.3.1 Word sets</H4>
|
||||
</a>
|
||||
|
||||
From the beginning, the X3J14 Technical Committee faced not only
|
||||
conflicting ideas as to what <B>real</B> Forth is, but also conflicting
|
||||
needs of the various groups within the Forth community. At one extreme
|
||||
were those who pressed for a <B>bare</B> Forth. At the other extreme
|
||||
were those who wanted a <B>fat</B> Forth. Many were somewhere in
|
||||
between. All were convinced of the rightness of their own position and
|
||||
of the wrongness of at least one of the two extremes. The committee's
|
||||
composition reflected this full range of interests.
|
||||
|
||||
<P>
|
||||
|
||||
The approach we have taken is to define a
|
||||
<a href=dpans6.htm#6.1>Core word set</a>
|
||||
establishing a
|
||||
greatest lower bound for required system functionality and to provide a
|
||||
portfolio of optional word sets for special purposes. This simple
|
||||
approach parallels the fundamental nature of Forth as an extensible
|
||||
language, and thereby achieves a kind of meta-extensibility.
|
||||
|
||||
<P>
|
||||
|
||||
With this key, high-level compromise, regardless of the actual makeup of
|
||||
the individual word sets, a firm and workable framework is established
|
||||
for the long term. One may or may not agree that there should be a
|
||||
<a href=dpans13.htm>Locals word set</a>,
|
||||
or that the word
|
||||
<a href=dpans6.htm#6.2.0945>COMPILE,</a>
|
||||
belongs in the
|
||||
<a href=dpans6.htm#6.2>Core Extensions word set</a>.
|
||||
But at least there is a mechanism whereby such
|
||||
things can be included in a logical and orderly manner.
|
||||
|
||||
<P>
|
||||
|
||||
Several implications of this scheme of optional word sets are
|
||||
significant.
|
||||
|
||||
<P>
|
||||
|
||||
First, ANS Forth systems can continue to be implemented on a greater
|
||||
range of hardware than could be claimed by almost any other single
|
||||
language. Since only the
|
||||
Core word set is required, very limited
|
||||
hardware will be able to accommodate an ANS Forth implementation.
|
||||
|
||||
<P>
|
||||
|
||||
Second, a greater degree of portability of applications, and of
|
||||
programmers, is anticipated. The optional word sets standardize various
|
||||
functions (e.g., floating point) that were widely implemented before,
|
||||
but not with uniform definition names and methodologies, nor the same
|
||||
levels of completeness. With such words now standardized in the
|
||||
optional word sets, communications between programmers - verbally, via
|
||||
magazine or journal articles, etc. - will leap to a new level of
|
||||
facility, and the shareability of code and applications should rise
|
||||
dramatically.
|
||||
|
||||
<P>
|
||||
|
||||
Third, ANS Forth systems may be designed to offer the user the power to
|
||||
selectively, even dynamically, include or exclude one or more of the
|
||||
optional word sets or portions thereof. Also, lower-priced products may
|
||||
be offered for the user who needs the Core word set and not much more.
|
||||
Thus, virtually unlimited flexibility will be available to the user.
|
||||
|
||||
<P>
|
||||
|
||||
But these advantages have a price. The burden is on the user to decide
|
||||
what capabilities are desired, and to select product offerings
|
||||
accordingly, especially when portability of applications is important.
|
||||
We do not expect most implementors to attempt to provide all word sets,
|
||||
but rather to select those most valuable to their intended markets.
|
||||
|
||||
<P>
|
||||
|
||||
The basic requirement is that if the implementor claims to have a
|
||||
particular optional word set the entire required portion of that word
|
||||
set must be available. If the implementor wishes to offer only part of
|
||||
an optional word set, it is acceptable to say, for example, <B>This
|
||||
system offers portions of the [named] word set</B>, particularly if the
|
||||
selected or excluded words are itemized clearly.
|
||||
|
||||
<P>
|
||||
|
||||
Each optional word set will probably appeal to a particular
|
||||
constituency. For example, scientists performing complex mathematical
|
||||
analysis may place a higher value on the
|
||||
<a href=dpans12.htm>Floating-Point word set</a>
|
||||
than
|
||||
programmers developing simple embedded controllers. As in the case of
|
||||
the core extensions, we expect implementors to offer those word sets
|
||||
they expect will be valued by their users.
|
||||
|
||||
<P>
|
||||
|
||||
Optional word sets may be offered in source form or otherwise factored
|
||||
so that the user may selectively load them.
|
||||
|
||||
<P>
|
||||
|
||||
The extensions to the optional word sets include words which are deemed
|
||||
less essential to performing the primary activity supported by the word
|
||||
set, though clearly relevant to it. As in the case of the Core
|
||||
Extensions, implementors may selectively add itemized subsets of a word
|
||||
set extension providing the labeling doesn't mislead the user into
|
||||
thinking incorrectly that all words are present.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpansa2.htm><IMG src="right.gif" ></A>
|
||||
Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpansa13.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpansa15.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=A.14>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
<H2>A.14 The optional Memory-Allocation word set</H2>
|
||||
|
||||
The Memory-Allocation word set provides a means for acquiring memory
|
||||
other than the contiguous data space that is allocated by
|
||||
<a href=dpans6.htm#6.1.0710>ALLOT</a>. In
|
||||
many operating system environments it is inappropriate for a process to
|
||||
pre-allocate large amounts of contiguous memory (as would be necessary
|
||||
for the use of ALLOT). The Memory-Allocation word set can acquire
|
||||
memory from the system at any time, without knowing in advance the
|
||||
address of the memory that will be acquired.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpansa15.htm><IMG src="right.gif" ></A>
|
||||
Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -0,0 +1,279 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpansa14.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpansa16.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=A.15>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
<H2>A.15 The optional Programming-Tools word set</H2>
|
||||
|
||||
These words have been in widespread common use since the earliest Forth
|
||||
systems.
|
||||
|
||||
<P>
|
||||
|
||||
Although there are environmental dependencies intrinsic to programs
|
||||
using an assembler, virtually all Forth systems provide such a
|
||||
capability. Insofar as many Forth programs are intended for real-time
|
||||
applications and are intrinsically non-portable for this reason, the
|
||||
Technical Committee believes that providing a standard window into
|
||||
assemblers is a useful contribution to Forth programmers.
|
||||
|
||||
<P>
|
||||
|
||||
Similarly, the programming aids
|
||||
<a href=dpans15.htm#15.6.1.1280>DUMP</a>,
|
||||
etc., are valuable tools even
|
||||
though their specific formats will differ between CPUs and Forth
|
||||
implementations. These words are primarily intended for use by the
|
||||
programmer, and are rarely invoked in programs.
|
||||
|
||||
<P>
|
||||
|
||||
One of the original aims of Forth was to erase the boundary between
|
||||
<B>user</B> and <B>programmer</B> - to give all possible power to anyone
|
||||
who had occasion to use a computer. Nothing in the above labeling or
|
||||
remarks should be construed to mean that this goal has been abandoned.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6>
|
||||
<H3>A.15.6 Glossary</H3>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.1.0220>A.15.6.1.0220 .S</A>
|
||||
<P>
|
||||
|
||||
.S is a debugging convenience found on almost all Forth systems. It is
|
||||
universally mentioned in Forth texts.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.1.2194>A.15.6.1.2194 SEE</A>
|
||||
<P>
|
||||
|
||||
SEE acts as an on-line form of documentation of words, allowing modification
|
||||
of words by decompiling and regenerating with appropriate changes.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.1.2465>A.15.6.1.2465 WORDS</A>
|
||||
<P>
|
||||
|
||||
WORDS is a debugging convenience found on almost all Forth systems. It is
|
||||
universally referred to in Forth texts.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.0470>A.15.6.2.0470 ;CODE</A>
|
||||
<P>
|
||||
|
||||
Typical use: <code>: namex ... <create> ... ;CODE ...</code>
|
||||
|
||||
<P>
|
||||
|
||||
where namex is a defining word, and <create> is
|
||||
<a href=dpans6.htm#6.1.1000>CREATE</a> or any user
|
||||
defined
|
||||
word that calls CREATE.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.0930>A.15.6.2.0930 CODE</A>
|
||||
<P>
|
||||
|
||||
Some Forth systems implement the assembly function by adding an
|
||||
<a href=dpans15.htm#15.6.2.0740>ASSEMBLER</a>
|
||||
word list to the search order, using the text interpreter to
|
||||
parse a postfix assembly language with lexical characteristics similar
|
||||
to Forth source code. Typically, in such systems, assembly ends when a
|
||||
word END-CODE is interpreted.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.1015>A.15.6.2.1015 CS-PICK</A>
|
||||
<P>
|
||||
|
||||
The intent is to reiterate a dest on the control-flow stack so that it can be
|
||||
resolved more than once. For example:
|
||||
|
||||
<PRE>
|
||||
\ Conditionally transfer control to beginning of loop
|
||||
\ This is similar in spirit to C's "continue" statement.
|
||||
|
||||
: ?REPEAT ( dest -- dest ) \ Compilation
|
||||
( flag -- ) \ Execution
|
||||
0 CS-PICK POSTPONE UNTIL
|
||||
; IMMEDIATE
|
||||
|
||||
: XX ( -- ) \ Example use of ?REPEAT
|
||||
BEGIN
|
||||
...
|
||||
flag ?REPEAT ( Go back to BEGIN if flag is false )
|
||||
...
|
||||
flag ?REPEAT ( Go back to BEGIN if flag is false )
|
||||
...
|
||||
flag UNTIL ( Go back to BEGIN if flag is false )
|
||||
...
|
||||
;
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.1020>A.15.6.2.1020 CS-ROLL</A>
|
||||
<P>
|
||||
|
||||
The intent is to modify the order in which the origs and dests on the
|
||||
control-flow stack are to be resolved by subsequent control-flow words. For
|
||||
example,
|
||||
<a href=dpans6.htm#6.1.2430>WHILE</a> could be implemented in terms of
|
||||
<a href=dpans6.htm#6.1.1700>IF</a> and CS-ROLL, as follows:
|
||||
|
||||
<PRE>
|
||||
: WHILE ( dest -- orig dest ) POSTPONE IF 1 CS-ROLL ; IMMEDIATE
|
||||
</PRE>
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.1580>A.15.6.2.1580 FORGET</A>
|
||||
<P>
|
||||
|
||||
Typical use: <code>... FORGET name ...</code>
|
||||
|
||||
<P>
|
||||
|
||||
FORGET assumes that all the information needed to restore the dictionary to
|
||||
its previous state is inferable somehow from the forgotten word. While this
|
||||
may be true in simple linear dictionary models, it is difficult to implement
|
||||
in other Forth systems; e.g., those with multiple address spaces. For
|
||||
example, if Forth is embedded in ROM, how does FORGET know how much RAM to
|
||||
recover when an array is forgotten? A general and preferred solution is
|
||||
provided by
|
||||
<a href=dpans6.htm#6.2.1850>MARKER</a>.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.2531>A.15.6.2.2531 [ELSE]</A>
|
||||
<P>
|
||||
|
||||
Typical use: <code>... flag [IF] ... [ELSE] ... [THEN] ...</code>
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.2532>A.15.6.2.2532 [IF]</A>
|
||||
<P>
|
||||
|
||||
Typical use: <code>... flag [IF] ... [ELSE] ... [THEN] ...</code>
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.15.6.2.2533>A.15.6.2.2533 [THEN]</A>
|
||||
<P>
|
||||
|
||||
Typical use: <code>... flag [IF] ... [ELSE] ... [THEN] ...</code>
|
||||
|
||||
<P>
|
||||
|
||||
Software that runs in several system environments often contains some
|
||||
source code that is environmentally dependent. Conditional compilation - the
|
||||
selective inclusion or exclusion of portions of the source code at
|
||||
compile time - is one technique that is often used to assist in the
|
||||
maintenance of such source code.
|
||||
<P>
|
||||
|
||||
Conditional compilation is sometimes done with <B>smart comments</B> -
|
||||
definitions that either skip or do not skip the remainder of the line
|
||||
based on some test. For example:
|
||||
|
||||
<PRE>
|
||||
\ If 16-Bit? contains TRUE, lines preceded by 16BIT\
|
||||
\ will be skipped. Otherwise, they will not be skipped.
|
||||
|
||||
VARIABLE 16-BIT?
|
||||
|
||||
: 16BIT\ ( -- ) 16-BIT? @ IF POSTPONE \ THEN ; IMMEDIATE
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
This technique works on a line by line basis, and is good for short,
|
||||
isolated variant code sequences.
|
||||
|
||||
<P>
|
||||
|
||||
More complicated conditional compilation problems suggest a nestable
|
||||
method that can encompass more than one source line at a time. The
|
||||
words included in the ANS Forth optional Programming tools extensions
|
||||
word set are useful for this purpose. The implementation given below
|
||||
works with any input source (keyboard,
|
||||
<a href=dpans6.htm#6.1.1360>EVALUATE</a>,
|
||||
<a href=dpans7.htm#7.6.1.0800>BLOCK</a>, or text file).
|
||||
|
||||
<PRE>
|
||||
: [ELSE] ( -- )
|
||||
1 BEGIN \ level
|
||||
BEGIN
|
||||
BL WORD COUNT DUP WHILE \ level adr len
|
||||
2DUP S" [IF]" COMPARE 0=
|
||||
IF \ level adr len
|
||||
2DROP 1+ \ level'
|
||||
ELSE \ level adr len
|
||||
2DUP S" [ELSE]"
|
||||
COMPARE 0= IF \ level adr len
|
||||
2DROP 1- DUP IF 1+ THEN \ level'
|
||||
ELSE \ level adr len
|
||||
S" [THEN]" COMPARE 0= IF \ level
|
||||
1- \ level'
|
||||
THEN
|
||||
THEN
|
||||
THEN ?DUP 0= IF EXIT THEN \ level'
|
||||
REPEAT 2DROP \ level
|
||||
REFILL 0= UNTIL \ level
|
||||
DROP
|
||||
; IMMEDIATE
|
||||
|
||||
: [IF] ( flag -- )
|
||||
0= IF POSTPONE [ELSE] THEN ; IMMEDIATE
|
||||
|
||||
: [THEN] ( -- ) ; IMMEDIATE
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpansa16.htm><IMG src="right.gif" ></A>
|
||||
Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -0,0 +1,287 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpansa15.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpansa17.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=A.16>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
|
||||
<H2>A.16 The optional Search-Order word set</H2>
|
||||
|
||||
Search-order specification and control mechanisms vary widely. The
|
||||
FIG-Forth, Forth-79, polyFORTH, and Forth-83 vocabulary and search order
|
||||
mechanisms are all mutually incompatible. The complete list of
|
||||
incompatible mechanisms, in use or proposed, is much longer. The
|
||||
<a href=dpans16.htm#16.6.2.0715>ALSO</a>/<a href=dpans16.htm#16.6.2.1965>ONLY</a>
|
||||
scheme described in a Forth-83 Experimental Proposal has
|
||||
substantial community support. However, many consider it to be
|
||||
fundamentally flawed, and oppose it vigorously.
|
||||
|
||||
<P>
|
||||
|
||||
Recognizing this variation, this Standard specifies a new
|
||||
<B>primitive</B> set of tools from which various schemes may be
|
||||
constructed. This primitive search-order word set is intended to be a
|
||||
portable <B>construction set</B> from which search-order words may be
|
||||
built, rather than a user interface. ALSO/ONLY or the various
|
||||
<B>vocabulary</B> schemes supported by the major Forth vendors can be
|
||||
defined in terms of the primitive search-order word set.
|
||||
|
||||
<P>
|
||||
|
||||
The encoding for word list identifiers wid might be a small-integer
|
||||
index into an array of word-list definition records, the data-space
|
||||
address of such a record, a user-area offset, the execution token of a
|
||||
Forth-83 style sealed vocabulary, the link-field address of the first
|
||||
definition in a word list, or anything else. It is entirely up to the
|
||||
system implementor.
|
||||
|
||||
<P>
|
||||
|
||||
In some systems the interpretation of numeric literals is controlled by
|
||||
including <B>pseudo word lists</B> that recognize numbers at the end of
|
||||
the search order. This technique is accommodated by the <B>default
|
||||
search order</B> behavior of
|
||||
<a href=dpans16.htm#16.6.1.2197>SET-ORDER</a>
|
||||
when given an argument of -1. In
|
||||
a system using the traditional implementation of ALSO/ONLY , the minimum
|
||||
search order would be equivalent to the word ONLY.
|
||||
|
||||
<P>
|
||||
|
||||
There has never been a portable way to restore a saved search order.
|
||||
F83 (not Forth-83) introduced the word
|
||||
<a href=dpans16.htm#16.6.2.2037>PREVIOUS</a>, which almost made it
|
||||
possible to <B>unload</B> the search order by repeatedly executing the
|
||||
phrase <b><code>CONTEXT @ PREVIOUS</code></b>.
|
||||
The search order could be <B>reloaded</B> by
|
||||
repeating
|
||||
<b><code>ALSO CONTEXT !</code></b>.
|
||||
Unfortunately there was no portable way to
|
||||
determine how many word lists were in the search order.
|
||||
|
||||
<P>
|
||||
|
||||
ANS Forth has removed the word CONTEXT because in many systems its
|
||||
contents refer to more than one word list, compounding portability
|
||||
problems.
|
||||
|
||||
<P>
|
||||
|
||||
Note that :
|
||||
(<a href=dpans6.htm#6.1.0450>colon</a>)
|
||||
no longer affects the search order. The previous
|
||||
behavior, where the compilation word list replaces the first word list
|
||||
of the search order, can be emulated with the following redefinition of
|
||||
: (colon).
|
||||
|
||||
<PRE>
|
||||
: : GET-ORDER SWAP DROP GET-CURRENT SWAP SET-ORDER : ;
|
||||
</PRE>
|
||||
<P>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.16.2>
|
||||
<H3>A.16.2 Additional terms</H3>
|
||||
</a>
|
||||
|
||||
<DL>
|
||||
<DT><b>search order</b>
|
||||
<DD>Note that the use of the term <B>list</B> does not necessarily imply
|
||||
implementation as a linked list.</DL>
|
||||
|
||||
<P>
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.16.3.3>
|
||||
<H4>A.16.3.3 Finding definition names</H4>
|
||||
</a>
|
||||
|
||||
In other words, the following is not guaranteed to work:
|
||||
|
||||
<PRE>
|
||||
: FOO ... [ ... SET-CURRENT ] ... RECURSE ... ; IMMEDIATE
|
||||
</PRE>
|
||||
|
||||
<a href=dpans6.htm#6.1.2120>RECURSE</a>,
|
||||
; (<a href=dpans6.htm#6.1.0460>semicolon</a>), and
|
||||
<a href=dpans6.htm#6.1.1710>IMMEDIATE</a>
|
||||
may or may not need information stored
|
||||
in the compilation word list.
|
||||
|
||||
<P>
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.16.6>
|
||||
<H3>A.16.6 Glossary</H3>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.16.6.1.2192>A.16.6.1.2192 SEARCH-WORDLIST</A>
|
||||
<P>
|
||||
|
||||
The string argument to SEARCH-WORDLIST is represented by c-addr u,
|
||||
rather than by just c-addr as with
|
||||
<a href=dpans6.htm#6.1.1550>FIND</a>.
|
||||
The committee wishes to
|
||||
establish c-addr u as the preferred representation of a string on the
|
||||
stack, and has adopted that representation for all new functions that
|
||||
accept string arguments. While this decision may cause the
|
||||
implementation of SEARCH-WORDLIST to be somewhat more difficult in
|
||||
existing systems, the committee feels that the additional difficulty is
|
||||
minor.
|
||||
|
||||
<P>
|
||||
|
||||
When SEARCH-WORDLIST fails to find the word, it does not return the
|
||||
string, as does FIND. This is in accordance with the general principle
|
||||
that Forth words consume their arguments.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.16.6.2.0715>A.16.6.2.0715 ALSO</A>
|
||||
<P>
|
||||
|
||||
Here is an implementation of
|
||||
ALSO/<a href=dpans16.htm#16.6.2.1965>ONLY</a>
|
||||
in terms of the primitive
|
||||
search-order word set.
|
||||
|
||||
|
||||
<PRE>
|
||||
WORDLIST CONSTANT ROOT ROOT SET-CURRENT
|
||||
|
||||
: DO-VOCABULARY ( -- ) \ Implementation factor
|
||||
DOES> @ >R ( ) ( R: widnew )
|
||||
GET-ORDER SWAP DROP ( wid1 ... widn-1 n )
|
||||
R> SWAP SET-ORDER
|
||||
;
|
||||
|
||||
: DISCARD ( x1 .. xu u - ) \ Implementation factor
|
||||
0 ?DO DROP LOOP \ DROP u+1 stack items
|
||||
;
|
||||
|
||||
CREATE FORTH FORTH-WORDLIST , DO-VOCABULARY
|
||||
|
||||
: VOCABULARY ( name -- ) WORDLIST CREATE , DO-VOCABULARY ;
|
||||
|
||||
: ALSO ( -- ) GET-ORDER OVER SWAP 1+ SET-ORDER ;
|
||||
|
||||
: PREVIOUS ( -- ) GET-ORDER SWAP DROP 1- SET-ORDER ;
|
||||
|
||||
: DEFINITIONS ( -- ) GET-ORDER OVER SET-CURRENT DISCARD ;
|
||||
|
||||
: ONLY ( -- ) ROOT ROOT 2 SET-ORDER ;
|
||||
|
||||
\ Forth-83 version; just removes ONLY
|
||||
: SEAL ( -- ) GET-ORDER 1- SET-ORDER DROP ;
|
||||
|
||||
\ F83 and F-PC version; leaves only CONTEXT
|
||||
: SEAL ( -- ) GET-ORDER OVER 1 SET-ORDER DISCARD ;
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
The preceding definition of ONLY in terms of a <B>ROOT</B> word list
|
||||
follows F83 usage, and assumes that the default search order just
|
||||
includes ROOT and
|
||||
<a href=dpans16.htm#16.6.2.1590>FORTH</a>.
|
||||
A more portable definition of FORTH and ONLY,
|
||||
without the assumptions, is:
|
||||
|
||||
<PRE>
|
||||
<omit the ... WORDLIST CONSTANT ROOT ... line>
|
||||
|
||||
CREATE FORTH GET-ORDER OVER , DISCARD DO-VOCABULARY
|
||||
|
||||
: ONLY ( -- ) -1 SET-ORDER ;
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
Here is a simple implementation of
|
||||
<a href=dpans16.htm#16.6.1.1647>GET-ORDER</a> and
|
||||
<a href=dpans16.htm#16.6.1.2197>SET-ORDER</a>, including a
|
||||
corresponding definition of
|
||||
<a href=dpans6.htm#6.1.1550>FIND</a>. The implementations of
|
||||
<a href=dpans16.htm#16.6.1.2460>WORDLIST</a>,
|
||||
<a href=dpans16.htm#16.6.1.2192>SEARCH-WORDLIST</a>,
|
||||
<a href=dpans16.htm#16.6.1.1643>GET-CURRENT</a> and
|
||||
<a href=dpans16.htm#16.6.1.2195>SET-CURRENT</a>
|
||||
depend on system details
|
||||
and are not given here.
|
||||
|
||||
<PRE>
|
||||
16 CONSTANT #VOCS
|
||||
|
||||
VARIABLE #ORDER
|
||||
|
||||
CREATE CONTEXT #VOCS CELLS ALLOT
|
||||
|
||||
: GET-ORDER ( -- wid1 .. widn n )
|
||||
#ORDER @ 0 ?DO
|
||||
#ORDER @ I - 1- CELLS CONTEXT + @
|
||||
LOOP
|
||||
#ORDER @
|
||||
;
|
||||
|
||||
: SET-ORDER ( wid1 .. widn n -- )
|
||||
DUP -1 = IF
|
||||
DROP <push system default word lists and n>
|
||||
THEN
|
||||
DUP #ORDER !
|
||||
0 ?DO I CELLS CONTEXT + ! LOOP
|
||||
;
|
||||
|
||||
: FIND ( c-addr -- c-addr 0 | w 1 | w -1 )
|
||||
0 ( c-addr 0 )
|
||||
#ORDER @ 0 ?DO
|
||||
OVER COUNT ( c-addr 0 c-addr' u )
|
||||
I CELLS CONTEXT + @ ( c-addr 0 c-addr' u wid)
|
||||
SEARCH-WORDLIST ( c-addr 0; 0 | w 1 | w -1 )
|
||||
?DUP IF ( c-addr 0; w 1 | w -1 )
|
||||
2SWAP 2DROP LEAVE ( w 1 | w -1 )
|
||||
THEN ( c-addr 0 )
|
||||
LOOP ( c-addr 0 | w 1 | w -1 )
|
||||
;
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
In an implementation where the dictionary search mechanism uses a hash
|
||||
table or lookup cache to reduce the search time, SET-ORDER might need to
|
||||
reconstruct the hash table or flush the cache.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpansa17.htm><IMG src="right.gif" ></A>
|
||||
Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -0,0 +1,148 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>DPANS94</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<td align=left>
|
||||
<a href=dpansa16.htm><img src=left.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a href=dpansb.htm><img src=right.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
</td>
|
||||
<td align=right>
|
||||
<a href=dpans.htm#toc><img src=up.gif
|
||||
width=26 height=26 align=ALIGN border=0></a>
|
||||
<a name=A.17>Table of Contents</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<hr size=4>
|
||||
|
||||
<H2>A.17 The optional String word set</H2>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6>
|
||||
<H3>A.17.6 Glossary</H3>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.0245>A.17.6.1.0245 /STRING</A>
|
||||
<P>
|
||||
|
||||
/STRING is used to remove or add characters relative to the <B>left</B>
|
||||
end of the character string. Positive values of n will exclude
|
||||
characters from the string while negative values of n will include
|
||||
characters to the left of the string. /STRING is a natural factor of
|
||||
<a href=dpans6.htm#6.1.2450>WORD</a>
|
||||
and commonly available.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.0910>A.17.6.1.0910 CMOVE</A>
|
||||
<P>
|
||||
|
||||
If c-addr2 lies within the source region (i.e., when c-addr2 is not less
|
||||
than c-addr1 and c-addr2 is less than the quantity c-addr1 u
|
||||
<a href=dpans6.htm#6.1.0898>CHARS</a> +),
|
||||
memory propagation occurs.
|
||||
|
||||
<P>
|
||||
|
||||
Typical
|
||||
use: Assume a character string at address 100: <B>ABCD</B>. Then after
|
||||
|
||||
|
||||
<PRE>
|
||||
100 DUP CHAR+ 3 CMOVE
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
the string at address 100 is <B>AAAA</B>.
|
||||
|
||||
<P>
|
||||
|
||||
Rationale
|
||||
for CMOVE and
|
||||
<a href=dpans17.htm#17.6.1.0920>CMOVE></a> follows
|
||||
<a href=dpans6.htm#6.1.1900>MOVE</a>.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.0920>A.17.6.1.0920 CMOVE></A>
|
||||
<P>
|
||||
|
||||
If c-addr1 lies within the destination region (i.e., when c-addr1 is
|
||||
greater than or equal to c-addr2 and c-addr2 is less than the quantity
|
||||
c-addr1 u
|
||||
<a href=dpans6.htm#6.1.0898>CHARS</a> +), memory propagation occurs.
|
||||
|
||||
<P>
|
||||
|
||||
Typical use: Assume a character string at address 100: <B>ABCD</B>.
|
||||
Then after
|
||||
|
||||
|
||||
<PRE>
|
||||
100 DUP CHAR+ SWAP 3 CMOVE>
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
|
||||
the string at address 100 is <B>DDDD</B>.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.0935>A.17.6.1.0935 COMPARE</A>
|
||||
<P>
|
||||
|
||||
Existing Forth systems perform string comparison operations using words that
|
||||
differ in spelling, input and output arguments, and case sensitivity. One in
|
||||
widespread use was chosen.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.2191>A.17.6.1.2191 SEARCH</A>
|
||||
<P>
|
||||
|
||||
Existing Forth systems perform string searching operations using words that
|
||||
differ in spelling, input and output arguments, and case sensitivity. One in
|
||||
widespread use was chosen.
|
||||
|
||||
<P>
|
||||
|
||||
<hr>
|
||||
<A name=A.17.6.1.2212>A.17.6.1.2212 SLITERAL</A>
|
||||
<P>
|
||||
|
||||
The current functionality of
|
||||
<a href=dpans6.htm#6.1.2165>6.1.2165</a> S" may be provided by the following
|
||||
definition:
|
||||
|
||||
<PRE>
|
||||
: S" ( "ccc<quote>" -- )
|
||||
[CHAR] " PARSE POSTPONE SLITERAL ; IMMEDIATE
|
||||
|
||||
</PRE>
|
||||
<P>
|
||||
|
||||
|
||||
<hr>
|
||||
<A href=dpans.htm#toc><IMG src="up.gif" ></A> Table of Contents
|
||||
<BR>
|
||||
<A href=dpansb.htm><IMG src="right.gif" ></A>
|
||||
Next Section
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user