version 1.30, 1996/01/25 16:45:50
|
version 1.33, 1996/05/13 16:36:56
|
Line 9
|
Line 9
|
@ifinfo |
@ifinfo |
This file documents Gforth 0.2 |
This file documents Gforth 0.2 |
|
|
Copyright @copyright{} 1995 Free Software Foundation, Inc. |
Copyright @copyright{} 1995,1996 Free Software Foundation, Inc. |
|
|
Permission is granted to make and distribute verbatim copies of |
Permission is granted to make and distribute verbatim copies of |
this manual provided the copyright notice and this permission notice |
this manual provided the copyright notice and this permission notice |
Line 51 Copyright @copyright{} 1995 Free Softwar
|
Line 51 Copyright @copyright{} 1995 Free Softwar
|
@comment The following two commands start the copyright page. |
@comment The following two commands start the copyright page. |
@page |
@page |
@vskip 0pt plus 1filll |
@vskip 0pt plus 1filll |
Copyright @copyright{} 1995 Free Software Foundation, Inc. |
Copyright @copyright{} 1995,1996 Free Software Foundation, Inc. |
|
|
@comment !! Published by ... or You can get a copy of this manual ... |
@comment !! Published by ... or You can get a copy of this manual ... |
|
|
Line 1141 system that only supplies @code{THEN} is
|
Line 1141 system that only supplies @code{THEN} is
|
Forth's @code{THEN} has the meaning 2b, whereas @code{THEN} in Pascal |
Forth's @code{THEN} has the meaning 2b, whereas @code{THEN} in Pascal |
and many other programming languages has the meaning 3d.] |
and many other programming languages has the meaning 3d.] |
|
|
We also provide the words @code{?dup-if} and @code{?dup-0=-if}, so you |
Gforth also provides the words @code{?dup-if} and @code{?dup-0=-if}, so |
can avoid using @code{?dup}. |
you can avoid using @code{?dup}. Using these alternatives is also more |
|
efficient than using @code{?dup}. Definitions in plain standard Forth |
|
for @code{ENDIF}, @code{?DUP-IF} and @code{?DUP-0=-IF} are provided in |
|
@file{compat/control.fs}. |
|
|
@example |
@example |
@var{n} |
@var{n} |
Line 1325 doc-else
|
Line 1328 doc-else
|
doc-while |
doc-while |
doc-repeat |
doc-repeat |
|
|
|
Gforth adds some more control-structure words: |
|
|
|
doc-endif |
|
doc-?dup-if |
|
doc-?dup-0=-if |
|
|
Counted loop words constitute a separate group of words: |
Counted loop words constitute a separate group of words: |
|
|
doc-?do |
doc-?do |
Line 1724 E.g., a definition using @code{TO} might
|
Line 1733 E.g., a definition using @code{TO} might
|
: strcmp @{ addr1 u1 addr2 u2 -- n @} |
: strcmp @{ addr1 u1 addr2 u2 -- n @} |
u1 u2 min 0 |
u1 u2 min 0 |
?do |
?do |
addr1 c@ addr2 c@ - ?dup |
addr1 c@ addr2 c@ - |
if |
?dup-if |
unloop exit |
unloop exit |
then |
then |
addr1 char+ TO addr1 |
addr1 char+ TO addr1 |
Line 1747 are initialized with the right value for
|
Line 1756 are initialized with the right value for
|
addr1 addr2 |
addr1 addr2 |
u1 u2 min 0 |
u1 u2 min 0 |
?do @{ s1 s2 @} |
?do @{ s1 s2 @} |
s1 c@ s2 c@ - ?dup |
s1 c@ s2 c@ - |
if |
?dup-if |
unloop exit |
unloop exit |
then |
then |
s1 char+ s2 char+ |
s1 char+ s2 char+ |
Line 3189 Not implemented (yet).
|
Line 3198 Not implemented (yet).
|
@table @i |
@table @i |
|
|
@item changing the compilation wordlist (during compilation): |
@item changing the compilation wordlist (during compilation): |
The definition is put into the wordlist that is the compilation wordlist |
The word is entered into the wordlist that was the compilation wordlist |
when @code{REVEAL} is executed (by @code{;}, @code{DOES>}, |
at the start of the definition. Any changes to the name field (e.g., |
@code{RECURSIVE}, etc.). |
@code{immediate}) or the code field (e.g., when executing @code{DOES>}) |
|
are applied to the latest defined word (as reported by @code{last} or |
|
@code{lastxt}), if possible, irrespective of the compilation wordlist. |
|
|
@item search order empty (@code{previous}): |
@item search order empty (@code{previous}): |
@code{abort" Vocstack empty"}. |
@code{abort" Vocstack empty"}. |
Line 3209 when @code{REVEAL} is executed (by @code
|
Line 3220 when @code{REVEAL} is executed (by @code
|
@chapter Emacs and Gforth |
@chapter Emacs and Gforth |
|
|
Gforth comes with @file{gforth.el}, an improved version of |
Gforth comes with @file{gforth.el}, an improved version of |
@file{forth.el} by Goran Rydqvist (icluded in the TILE package). The |
@file{forth.el} by Goran Rydqvist (included in the TILE package). The |
improvements are a better (but still not perfect) handling of |
improvements are a better (but still not perfect) handling of |
indentation. I have also added comment paragraph filling (@kbd{M-q}), |
indentation. I have also added comment paragraph filling (@kbd{M-q}), |
commenting (@kbd{C-x \}) and uncommenting (@kbd{C-u C-x \}) regions and |
commenting (@kbd{C-x \}) and uncommenting (@kbd{C-u C-x \}) regions and |
Line 3234 several tags files at the same time (e.g
|
Line 3245 several tags files at the same time (e.g
|
and one for your program, @pxref{Select Tags Table,,Selecting a Tags |
and one for your program, @pxref{Select Tags Table,,Selecting a Tags |
Table,emacs, Emacs Manual}). The TAGS file for the preloaded words is |
Table,emacs, Emacs Manual}). The TAGS file for the preloaded words is |
@file{$(datadir)/gforth/$(VERSION)/TAGS} (e.g., |
@file{$(datadir)/gforth/$(VERSION)/TAGS} (e.g., |
@file{/usr/local/share/gforth/0.2/TAGS}). |
@file{/usr/local/share/gforth/0.2.0/TAGS}). |
|
|
To get all these benefits, add the following lines to your @file{.emacs} |
To get all these benefits, add the following lines to your @file{.emacs} |
file: |
file: |
Line 3289 limitations: GNU C, the version of C pro
|
Line 3300 limitations: GNU C, the version of C pro
|
GNU C Manual}). Its labels as values feature (@pxref{Labels as Values, , |
GNU C Manual}). Its labels as values feature (@pxref{Labels as Values, , |
Labels as Values, gcc.info, GNU C Manual}) makes direct and indirect |
Labels as Values, gcc.info, GNU C Manual}) makes direct and indirect |
threading possible, its @code{long long} type (@pxref{Long Long, , |
threading possible, its @code{long long} type (@pxref{Long Long, , |
Double-Word Integers, gcc.info, GNU C Manual}) corresponds to Forths |
Double-Word Integers, gcc.info, GNU C Manual}) corresponds to Forth's |
double numbers. GNU C is available for free on all important (and many |
double numbers@footnote{Unfortunately, long longs are not implemented |
unimportant) UNIX machines, VMS, 80386s running MS-DOS, the Amiga, and |
properly on all machines (e.g., on alpha-osf1, long longs are only 64 |
the Atari ST, so a Forth written in GNU C can run on all these |
bits, the same size as longs (and pointers), but they should be twice as |
machines. |
long according to @ref{Long Long, , Double-Word Integers, gcc.info, GNU |
|
C Manual}). So, we had to implement doubles in C after all. Still, on |
|
most machines we can use long longs and achieve better performance than |
|
with the emulation package.}. GNU C is available for free on all |
|
important (and many unimportant) UNIX machines, VMS, 80386s running |
|
MS-DOS, the Amiga, and the Atari ST, so a Forth written in GNU C can run |
|
on all these machines. |
|
|
Writing in a portable language has the reputation of producing code that |
Writing in a portable language has the reputation of producing code that |
is slower than assembly. For our Forth engine we repeatedly looked at |
is slower than assembly. For our Forth engine we repeatedly looked at |
Line 3648 Gforth (direct threaded, compiled with @
|
Line 3665 Gforth (direct threaded, compiled with @
|
1994) and Eforth (with and without peephole (aka pinhole) optimization |
1994) and Eforth (with and without peephole (aka pinhole) optimization |
of the threaded code); all these systems were written in assembly |
of the threaded code); all these systems were written in assembly |
language. We also compared Gforth with three systems written in C: |
language. We also compared Gforth with three systems written in C: |
PFE-0.9.11 (compiled with @code{gcc-2.6.3} with the default |
PFE-0.9.14 (compiled with @code{gcc-2.6.3} with the default |
configuration for Linux: @code{-O2 -fomit-frame-pointer -DUSE_REGS}), |
configuration for Linux: @code{-O2 -fomit-frame-pointer -DUSE_REGS |
ThisForth Beta (compiled with gcc-2.6.3 -O3 -fomit-frame-pointer; |
-DUNROLL_NEXT}), ThisForth Beta (compiled with gcc-2.6.3 -O3 |
ThisForth employs peephole optimization of the threaded code) and TILE |
-fomit-frame-pointer; ThisForth employs peephole optimization of the |
(compiled with @code{make opt}). We benchmarked Gforth, PFE, ThisForth |
threaded code) and TILE (compiled with @code{make opt}). We benchmarked |
and TILE on a 486DX2/66 under Linux. Kenneth O'Heskin kindly provided |
Gforth, PFE, ThisForth and TILE on a 486DX2/66 under Linux. Kenneth |
the results for Win32Forth and NT Forth on a 486DX2/66 with similar |
O'Heskin kindly provided the results for Win32Forth and NT Forth on a |
memory performance under Windows NT. Marcel Hendrix ported Eforth to |
486DX2/66 with similar memory performance under Windows NT. Marcel |
Linux, then extended it to run the benchmarks, added the peephole |
Hendrix ported Eforth to Linux, then extended it to run the benchmarks, |
optimizer, ran the benchmarks and reported the results. |
added the peephole optimizer, ran the benchmarks and reported the |
|
results. |
|
|
We used four small benchmarks: the ubiquitous Sieve; bubble-sorting and |
We used four small benchmarks: the ubiquitous Sieve; bubble-sorting and |
matrix multiplication come from the Stanford integer benchmarks and have |
matrix multiplication come from the Stanford integer benchmarks and have |
Line 3671 factor that Gforth achieved over the oth
|
Line 3689 factor that Gforth achieved over the oth
|
@example |
@example |
relative Win32- NT eforth This- |
relative Win32- NT eforth This- |
time Gforth Forth Forth eforth +opt PFE Forth TILE |
time Gforth Forth Forth eforth +opt PFE Forth TILE |
sieve 1.00 1.39 1.14 1.39 0.85 1.78 3.18 8.58 |
sieve 1.00 1.39 1.14 1.39 0.85 1.58 3.18 8.58 |
bubble 1.00 1.31 1.41 1.48 0.88 1.67 3.88 |
bubble 1.00 1.31 1.41 1.48 0.88 1.50 3.88 |
matmul 1.00 1.47 1.35 1.46 1.16 2.36 4.09 |
matmul 1.00 1.47 1.35 1.46 1.16 1.58 4.09 |
fib 1.00 1.52 1.34 1.22 1.13 1.93 2.99 4.30 |
fib 1.00 1.52 1.34 1.22 1.13 1.74 2.99 4.30 |
@end example |
@end example |
|
|
You may find the good performance of Gforth compared with the systems |
You may find the good performance of Gforth compared with the systems |
Line 3721 numbers for Gforth on various machines i
|
Line 3739 numbers for Gforth on various machines i
|
Known bugs are described in the file BUGS in the Gforth distribution. |
Known bugs are described in the file BUGS in the Gforth distribution. |
|
|
If you find a bug, please send a bug report to |
If you find a bug, please send a bug report to |
@code{gforth-bugs@@mips.complang.tuwien.ac.at}. A bug report should |
@code{bug-gforth@@gnu.ai.mit.edu}. A bug report should |
describe the Gforth version used (it is announced at the start of an |
describe the Gforth version used (it is announced at the start of an |
interactive Gforth session), the machine and operating system (on Unix |
interactive Gforth session), the machine and operating system (on Unix |
systems you can use @code{uname -a} to produce this information), the |
systems you can use @code{uname -a} to produce this information), the |