version 1.25, 1995/11/28 18:45:28
|
version 1.47, 1997/03/20 14:39:50
|
Line 7
|
Line 7
|
@comment %**end of header (This is for running Texinfo on a region.) |
@comment %**end of header (This is for running Texinfo on a region.) |
|
|
@ifinfo |
@ifinfo |
This file documents Gforth 0.1 |
This file documents Gforth 0.3 |
|
|
Copyright @copyright{} 1995 Free Software Foundation, Inc. |
Copyright @copyright{} 1995-1997 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 41 Copyright @copyright{} 1995 Free Softwar
|
Line 41 Copyright @copyright{} 1995 Free Softwar
|
@sp 10 |
@sp 10 |
@center @titlefont{Gforth Manual} |
@center @titlefont{Gforth Manual} |
@sp 2 |
@sp 2 |
@center for version 0.1 |
@center for version 0.3 |
@sp 2 |
@sp 2 |
@center Anton Ertl |
@center Anton Ertl |
@center Bernd Paysan |
@center Bernd Paysan |
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--1997 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 77 Copyright @copyright{} 1995 Free Softwar
|
Line 77 Copyright @copyright{} 1995 Free Softwar
|
@node Top, License, (dir), (dir) |
@node Top, License, (dir), (dir) |
@ifinfo |
@ifinfo |
Gforth is a free implementation of ANS Forth available on many |
Gforth is a free implementation of ANS Forth available on many |
personal machines. This manual corresponds to version 0.1. |
personal machines. This manual corresponds to version 0.3. |
@end ifinfo |
@end ifinfo |
|
|
@menu |
@menu |
* License:: |
* License:: |
* Goals:: About the Gforth Project |
* Goals:: About the Gforth Project |
* Other Books:: Things you might want to read |
* Other Books:: Things you might want to read |
* Invocation:: Starting Gforth |
* Invoking Gforth:: Starting Gforth |
* Words:: Forth words available in Gforth |
* Words:: Forth words available in Gforth |
|
* Tools:: Programming tools |
* ANS conformance:: Implementation-defined options etc. |
* ANS conformance:: Implementation-defined options etc. |
* Model:: The abstract machine of Gforth |
* Model:: The abstract machine of Gforth |
|
* Integrating Gforth:: Forth as scripting language for applications |
* Emacs and Gforth:: The Gforth Mode |
* Emacs and Gforth:: The Gforth Mode |
* Internals:: Implementation details |
* Image Files:: @code{.fi} files contain compiled code |
|
* Engine:: The inner interpreter and the primitives |
* Bugs:: How to report them |
* Bugs:: How to report them |
* Pedigree:: Ancestors of Gforth |
* Origin:: Authors and ancestors of Gforth |
* Word Index:: An item for each Forth word |
* Word Index:: An item for each Forth word |
* Node Index:: An item for each node |
* Concept Index:: A menu covering many topics |
@end menu |
@end menu |
|
|
@node License, Goals, Top, Top |
@node License, Goals, Top, Top |
Line 489 library. If this is what you want to do
|
Line 492 library. If this is what you want to do
|
Public License instead of this License. |
Public License instead of this License. |
|
|
@iftex |
@iftex |
@node Preface |
|
@comment node-name, next, previous, up |
|
@unnumbered Preface |
@unnumbered Preface |
@cindex Preface |
@cindex Preface |
This manual documents Gforth. The reader is expected to know |
This manual documents Gforth. The reader is expected to know |
Line 503 for introductory material.
|
Line 504 for introductory material.
|
@chapter Goals of Gforth |
@chapter Goals of Gforth |
@cindex Goals |
@cindex Goals |
The goal of the Gforth Project is to develop a standard model for |
The goal of the Gforth Project is to develop a standard model for |
ANSI Forth. This can be split into several subgoals: |
ANS Forth. This can be split into several subgoals: |
|
|
@itemize @bullet |
@itemize @bullet |
@item |
@item |
Gforth should conform to the ANSI Forth standard. |
Gforth should conform to the Forth standard (ANS Forth). |
@item |
@item |
It should be a model, i.e. it should define all the |
It should be a model, i.e. it should define all the |
implementation-dependent things. |
implementation-dependent things. |
Line 541 powerful features, but not yet everythin
|
Line 542 powerful features, but not yet everythin
|
certainly have achieved our execution speed goals (@pxref{Performance}). |
certainly have achieved our execution speed goals (@pxref{Performance}). |
It is free and available on many machines. |
It is free and available on many machines. |
|
|
@node Other Books, Invocation, Goals, Top |
@node Other Books, Invoking Gforth, Goals, Top |
@chapter Other books on ANS Forth |
@chapter Other books on ANS Forth |
|
@cindex books on Forth |
|
|
As the standard is relatively new, there are not many books out yet. It |
As the standard is relatively new, there are not many books out yet. It |
is not recommended to learn Forth by using Gforth and a book that is |
is not recommended to learn Forth by using Gforth and a book that is |
not written for ANS Forth, as you will not know your mistakes from the |
not written for ANS Forth, as you will not know your mistakes from the |
deviations of the book. |
deviations of the book. |
|
|
|
@cindex standard document for ANS Forth |
|
@cindex ANS Forth document |
There is, of course, the standard, the definite reference if you want to |
There is, of course, the standard, the definite reference if you want to |
write ANS Forth programs. It is available in printed form from the |
write ANS Forth programs. It is available in printed form from the |
National Standards Institute Sales Department (Tel.: USA (212) 642-4900; |
National Standards Institute Sales Department (Tel.: USA (212) 642-4900; |
Line 562 format, and it has been converted to HTM
|
Line 566 format, and it has been converted to HTM
|
versions can be found through |
versions can be found through |
@*@file{http://www.complang.tuwien.ac.at/projects/forth.html}. |
@*@file{http://www.complang.tuwien.ac.at/projects/forth.html}. |
|
|
@cite{Forth: The new model} by Jack Woehr (Prentice-Hall, 1993) is an |
@cindex introductory book |
|
@cindex book, introductory |
|
@cindex Woehr, Jack: @cite{Forth: The New Model} |
|
@cindex @cite{Forth: The new model} (book) |
|
@cite{Forth: The New Model} by Jack Woehr (Prentice-Hall, 1993) is an |
introductory book based on a draft version of the standard. It does not |
introductory book based on a draft version of the standard. It does not |
cover the whole standard. It also contains interesting background |
cover the whole standard. It also contains interesting background |
information (Jack Woehr was in the ANS Forth Technical Committe). It is |
information (Jack Woehr was in the ANS Forth Technical Committee). It is |
not appropriate for complete newbies, but programmers experienced in |
not appropriate for complete newbies, but programmers experienced in |
other languages should find it ok. |
other languages should find it ok. |
|
|
@node Invocation, Words, Other Books, Top |
@node Invoking Gforth, Words, Other Books, Top |
@chapter Invocation |
@chapter Invoking Gforth |
|
@cindex invoking Gforth |
|
@cindex running Gforth |
|
@cindex command-line options |
|
@cindex options on the command line |
|
@cindex flags on the command line |
|
|
You will usually just say @code{gforth}. In many other cases the default |
You will usually just say @code{gforth}. In many other cases the default |
Gforth image will be invoked like this: |
Gforth image will be invoked like this: |
Line 592 The initialization options must come bef
|
Line 605 The initialization options must come bef
|
line. They are: |
line. They are: |
|
|
@table @code |
@table @code |
|
@cindex -i, command-line option |
|
@cindex --image-file, command-line option |
@item --image-file @var{file} |
@item --image-file @var{file} |
@item -i @var{file} |
@itemx -i @var{file} |
Loads the Forth image @var{file} instead of the default |
Loads the Forth image @var{file} instead of the default |
@file{gforth.fi}. |
@file{gforth.fi} (@pxref{Image Files}). |
|
|
|
@cindex --path, command-line option |
|
@cindex -p, command-line option |
@item --path @var{path} |
@item --path @var{path} |
@item -p @var{path} |
@itemx -p @var{path} |
Uses @var{path} for searching the image file and Forth source code |
Uses @var{path} for searching the image file and Forth source code files |
files instead of the default in the environment variable |
instead of the default in the environment variable @code{GFORTHPATH} or |
@code{GFORTHPATH} or the path specified at installation time (typically |
the path specified at installation time (e.g., |
@file{/usr/local/lib/gforth:.}). A path is given as a @code{:}-separated |
@file{/usr/local/share/gforth/0.2.0:.}). A path is given as a list of |
list. |
directories, separated by @samp{:} (on Unix) or @samp{;} (on other OSs). |
|
|
|
@cindex --dictionary-size, command-line option |
|
@cindex -m, command-line option |
|
@cindex @var{size} parameters for command-line options |
|
@cindex size of the dictionary and the stacks |
@item --dictionary-size @var{size} |
@item --dictionary-size @var{size} |
@item -m @var{size} |
@itemx -m @var{size} |
Allocate @var{size} space for the Forth dictionary space instead of |
Allocate @var{size} space for the Forth dictionary space instead of |
using the default specified in the image (typically 256K). The |
using the default specified in the image (typically 256K). The |
@var{size} specification consists of an integer and a unit (e.g., |
@var{size} specification consists of an integer and a unit (e.g., |
Line 614 using the default specified in the image
|
Line 635 using the default specified in the image
|
size, in this case Cells), @code{k} (kilobytes), and @code{M} |
size, in this case Cells), @code{k} (kilobytes), and @code{M} |
(Megabytes). If no unit is specified, @code{e} is used. |
(Megabytes). If no unit is specified, @code{e} is used. |
|
|
|
@cindex --data-stack-size, command-line option |
|
@cindex -d, command-line option |
@item --data-stack-size @var{size} |
@item --data-stack-size @var{size} |
@item -d @var{size} |
@itemx -d @var{size} |
Allocate @var{size} space for the data stack instead of using the |
Allocate @var{size} space for the data stack instead of using the |
default specified in the image (typically 16K). |
default specified in the image (typically 16K). |
|
|
|
@cindex --return-stack-size, command-line option |
|
@cindex -r, command-line option |
@item --return-stack-size @var{size} |
@item --return-stack-size @var{size} |
@item -r @var{size} |
@itemx -r @var{size} |
Allocate @var{size} space for the return stack instead of using the |
Allocate @var{size} space for the return stack instead of using the |
default specified in the image (typically 16K). |
default specified in the image (typically 15K). |
|
|
|
@cindex --fp-stack-size, command-line option |
|
@cindex -f, command-line option |
@item --fp-stack-size @var{size} |
@item --fp-stack-size @var{size} |
@item -f @var{size} |
@itemx -f @var{size} |
Allocate @var{size} space for the floating point stack instead of |
Allocate @var{size} space for the floating point stack instead of |
using the default specified in the image (typically 16K). In this case |
using the default specified in the image (typically 15.5K). In this case |
the unit specifier @code{e} refers to floating point numbers. |
the unit specifier @code{e} refers to floating point numbers. |
|
|
|
@cindex --locals-stack-size, command-line option |
|
@cindex -l, command-line option |
@item --locals-stack-size @var{size} |
@item --locals-stack-size @var{size} |
@item -l @var{size} |
@itemx -l @var{size} |
Allocate @var{size} space for the locals stack instead of using the |
Allocate @var{size} space for the locals stack instead of using the |
default specified in the image (typically 16K). |
default specified in the image (typically 14.5K). |
|
|
|
@cindex -h, command-line option |
|
@cindex --help, command-line option |
|
@item --help |
|
@itemx -h |
|
Print a message about the command-line options |
|
|
|
@cindex -v, command-line option |
|
@cindex --version, command-line option |
|
@item --version |
|
@itemx -v |
|
Print version and exit |
|
|
|
@cindex --debug, command-line option |
|
@item --debug |
|
Print some information useful for debugging on startup. |
|
|
|
@cindex --offset-image, command-line option |
|
@item --offset-image |
|
Start the dictionary at a slightly different position than would be used |
|
otherwise (useful for creating data-relocatable images, |
|
@pxref{Data-Relocatable Image Files}). |
|
|
|
@cindex --clear-dictionary, command-line option |
|
@item --clear-dictionary |
|
Initialize all bytes in the dictionary to 0 before loading the image |
|
(@pxref{Data-Relocatable Image Files}). |
@end table |
@end table |
|
|
|
@cindex loading files at startup |
|
@cindex executing code on startup |
|
@cindex batch processing with Gforth |
As explained above, the image-specific command-line arguments for the |
As explained above, the image-specific command-line arguments for the |
default image @file{gforth.fi} consist of a sequence of filenames and |
default image @file{gforth.fi} consist of a sequence of filenames and |
@code{-e @var{forth-code}} options that are interpreted in the seqence |
@code{-e @var{forth-code}} options that are interpreted in the sequence |
in which they are given. The @code{-e @var{forth-code}} or |
in which they are given. The @code{-e @var{forth-code}} or |
@code{--evaluate @var{forth-code}} option evaluates the forth |
@code{--evaluate @var{forth-code}} option evaluates the forth |
code. This option takes only one argument; if you want to evaluate more |
code. This option takes only one argument; if you want to evaluate more |
Line 647 Forth words, you have to quote them or u
|
Line 705 Forth words, you have to quote them or u
|
after processing the command line (instead of entering interactive mode) |
after processing the command line (instead of entering interactive mode) |
append @code{-e bye} to the command line. |
append @code{-e bye} to the command line. |
|
|
|
@cindex versions, invoking other versions of Gforth |
If you have several versions of Gforth installed, @code{gforth} will |
If you have several versions of Gforth installed, @code{gforth} will |
invoke the version that was installed last. @code{gforth-@var{version}} |
invoke the version that was installed last. @code{gforth-@var{version}} |
invokes a specific version. You may want to use the option |
invokes a specific version. You may want to use the option |
Line 661 the user initialization file @file{.gfor
|
Line 720 the user initialization file @file{.gfor
|
option @code{--no-rc} is given; this file is first searched in @file{.}, |
option @code{--no-rc} is given; this file is first searched in @file{.}, |
then in @file{~}, then in the normal path (see above). |
then in @file{~}, then in the normal path (see above). |
|
|
@node Words, ANS conformance, Invocation, Top |
@node Words, Tools, Invoking Gforth, Top |
@chapter Forth Words |
@chapter Forth Words |
|
@cindex Words |
|
|
@menu |
@menu |
* Notation:: |
* Notation:: |
* Arithmetic:: |
* Arithmetic:: |
* Stack Manipulation:: |
* Stack Manipulation:: |
* Memory access:: |
* Memory:: |
* Control Structures:: |
* Control Structures:: |
* Locals:: |
* Locals:: |
* Defining Words:: |
* Defining Words:: |
|
* Tokens for Words:: |
* Wordlists:: |
* Wordlists:: |
* Files:: |
* Files:: |
* Blocks:: |
* Blocks:: |
Line 683 then in @file{~}, then in the normal pat
|
Line 744 then in @file{~}, then in the normal pat
|
|
|
@node Notation, Arithmetic, Words, Words |
@node Notation, Arithmetic, Words, Words |
@section Notation |
@section Notation |
|
@cindex notation of glossary entries |
|
@cindex format of glossary entries |
|
@cindex glossary notation format |
|
@cindex word glossary entry format |
|
|
The Forth words are described in this section in the glossary notation |
The Forth words are described in this section in the glossary notation |
that has become a de-facto standard for Forth texts, i.e. |
that has become a de-facto standard for Forth texts, i.e., |
|
|
@format |
@format |
@var{word} @var{Stack effect} @var{wordset} @var{pronunciation} |
@var{word} @var{Stack effect} @var{wordset} @var{pronunciation} |
Line 694 that has become a de-facto standard for
|
Line 759 that has become a de-facto standard for
|
|
|
@table @var |
@table @var |
@item word |
@item word |
|
@cindex case insensitivity |
The name of the word. BTW, Gforth is case insensitive, so you can |
The name of the word. BTW, Gforth is case insensitive, so you can |
type the words in in lower case (However, @pxref{core-idef}). |
type the words in in lower case (However, @pxref{core-idef}). |
|
|
@item Stack effect |
@item Stack effect |
|
@cindex stack effect |
The stack effect is written in the notation @code{@var{before} -- |
The stack effect is written in the notation @code{@var{before} -- |
@var{after}}, where @var{before} and @var{after} describe the top of |
@var{after}}, where @var{before} and @var{after} describe the top of |
stack entries before and after the execution of the word. The rest of |
stack entries before and after the execution of the word. The rest of |
Line 716 this standard behaviour, or the word doe
|
Line 783 this standard behaviour, or the word doe
|
compile time, both stack effects are shown; otherwise only the run-time |
compile time, both stack effects are shown; otherwise only the run-time |
stack effect is shown. |
stack effect is shown. |
|
|
|
@cindex pronounciation of words |
@item pronunciation |
@item pronunciation |
How the word is pronounced |
How the word is pronounced. |
|
|
|
@cindex wordset |
@item wordset |
@item wordset |
The ANS Forth standard is divided into several wordsets. A standard |
The ANS Forth standard is divided into several wordsets. A standard |
system need not support all of them. So, the fewer wordsets your program |
system need not support all of them. So, the fewer wordsets your program |
Line 735 strings are also displayed like words; y
|
Line 804 strings are also displayed like words; y
|
A description of the behaviour of the word. |
A description of the behaviour of the word. |
@end table |
@end table |
|
|
|
@cindex types of stack items |
|
@cindex stack item types |
The type of a stack item is specified by the character(s) the name |
The type of a stack item is specified by the character(s) the name |
starts with: |
starts with: |
|
|
@table @code |
@table @code |
@item f |
@item f |
Bool, i.e. @code{false} or @code{true}. |
@cindex @code{f}, stack item type |
|
Boolean flags, i.e. @code{false} or @code{true}. |
@item c |
@item c |
|
@cindex @code{c}, stack item type |
Char |
Char |
@item w |
@item w |
|
@cindex @code{w}, stack item type |
Cell, can contain an integer or an address |
Cell, can contain an integer or an address |
@item n |
@item n |
|
@cindex @code{n}, stack item type |
signed integer |
signed integer |
@item u |
@item u |
|
@cindex @code{u}, stack item type |
unsigned integer |
unsigned integer |
@item d |
@item d |
|
@cindex @code{d}, stack item type |
double sized signed integer |
double sized signed integer |
@item ud |
@item ud |
|
@cindex @code{ud}, stack item type |
double sized unsigned integer |
double sized unsigned integer |
@item r |
@item r |
Float |
@cindex @code{r}, stack item type |
|
Float (on the FP stack) |
@item a_ |
@item a_ |
|
@cindex @code{a_}, stack item type |
Cell-aligned address |
Cell-aligned address |
@item c_ |
@item c_ |
Char-aligned address (note that a Char is two bytes in Windows NT) |
@cindex @code{c_}, stack item type |
|
Char-aligned address (note that a Char may have two bytes in Windows NT) |
@item f_ |
@item f_ |
|
@cindex @code{f_}, stack item type |
Float-aligned address |
Float-aligned address |
@item df_ |
@item df_ |
|
@cindex @code{df_}, stack item type |
Address aligned for IEEE double precision float |
Address aligned for IEEE double precision float |
@item sf_ |
@item sf_ |
|
@cindex @code{sf_}, stack item type |
Address aligned for IEEE single precision float |
Address aligned for IEEE single precision float |
@item xt |
@item xt |
|
@cindex @code{xt}, stack item type |
Execution token, same size as Cell |
Execution token, same size as Cell |
@item wid |
@item wid |
|
@cindex @code{wid}, stack item type |
Wordlist ID, same size as Cell |
Wordlist ID, same size as Cell |
@item f83name |
@item f83name |
|
@cindex @code{f83name}, stack item type |
Pointer to a name structure |
Pointer to a name structure |
|
@item " |
|
@cindex @code{"}, stack item type |
|
string in the input stream (not the stack). The terminating character is |
|
a blank by default. If it is not a blank, it is shown in @code{<>} |
|
quotes. |
@end table |
@end table |
|
|
@node Arithmetic, Stack Manipulation, Notation, Words |
@node Arithmetic, Stack Manipulation, Notation, Words |
@section Arithmetic |
@section Arithmetic |
|
@cindex arithmetic words |
|
|
|
@cindex division with potentially negative operands |
Forth arithmetic is not checked, i.e., you will not hear about integer |
Forth arithmetic is not checked, i.e., you will not hear about integer |
overflow on addition or multiplication, you may hear about division by |
overflow on addition or multiplication, you may hear about division by |
zero if you are lucky. The operator is written after the operands, but |
zero if you are lucky. The operator is written after the operands, but |
Line 795 former, @pxref{Mixed precision}).
|
Line 890 former, @pxref{Mixed precision}).
|
|
|
@node Single precision, Bitwise operations, Arithmetic, Arithmetic |
@node Single precision, Bitwise operations, Arithmetic, Arithmetic |
@subsection Single precision |
@subsection Single precision |
|
@cindex single precision arithmetic words |
|
|
doc-+ |
doc-+ |
doc-- |
doc-- |
doc-* |
doc-* |
Line 808 doc-max
|
Line 905 doc-max
|
|
|
@node Bitwise operations, Mixed precision, Single precision, Arithmetic |
@node Bitwise operations, Mixed precision, Single precision, Arithmetic |
@subsection Bitwise operations |
@subsection Bitwise operations |
|
@cindex bitwise operation words |
|
|
doc-and |
doc-and |
doc-or |
doc-or |
doc-xor |
doc-xor |
Line 817 doc-2/
|
Line 916 doc-2/
|
|
|
@node Mixed precision, Double precision, Bitwise operations, Arithmetic |
@node Mixed precision, Double precision, Bitwise operations, Arithmetic |
@subsection Mixed precision |
@subsection Mixed precision |
|
@cindex mixed precision arithmetic words |
|
|
doc-m+ |
doc-m+ |
doc-*/ |
doc-*/ |
doc-*/mod |
doc-*/mod |
Line 829 doc-sm/rem
|
Line 930 doc-sm/rem
|
|
|
@node Double precision, Floating Point, Mixed precision, Arithmetic |
@node Double precision, Floating Point, Mixed precision, Arithmetic |
@subsection Double precision |
@subsection Double precision |
|
@cindex double precision arithmetic words |
|
|
|
@cindex double-cell numbers, input format |
|
@cindex input format for double-cell numbers |
The outer (aka text) interpreter converts numbers containing a dot into |
The outer (aka text) interpreter converts numbers containing a dot into |
a double precision number. Note that only numbers with the dot as last |
a double precision number. Note that only numbers with the dot as last |
character are standard-conforming. |
character are standard-conforming. |
Line 843 doc-dmax
|
Line 947 doc-dmax
|
|
|
@node Floating Point, , Double precision, Arithmetic |
@node Floating Point, , Double precision, Arithmetic |
@subsection Floating Point |
@subsection Floating Point |
|
@cindex floating point arithmetic words |
|
|
|
@cindex floating-point numbers, input format |
|
@cindex input format for floating-point numbers |
The format of floating point numbers recognized by the outer (aka text) |
The format of floating point numbers recognized by the outer (aka text) |
interpreter is: a signed decimal number, possibly containing a decimal |
interpreter is: a signed decimal number, possibly containing a decimal |
point (@code{.}), followed by @code{E} or @code{e}, optionally followed |
point (@code{.}), followed by @code{E} or @code{e}, optionally followed |
by a signed integer (the exponent). E.g., @code{1e} ist the same as |
by a signed integer (the exponent). E.g., @code{1e} is the same as |
@code{+1.0e+1}. Note that a number without @code{e} |
@code{+1.0e+0}. Note that a number without @code{e} |
is not interpreted as floating-point number, but as double (if the |
is not interpreted as floating-point number, but as double (if the |
number contains a @code{.}) or single precision integer. Also, |
number contains a @code{.}) or single precision integer. Also, |
conversions between string and floating point numbers always use base |
conversions between string and floating point numbers always use base |
Line 857 value greater then 14, the @code{E} may
|
Line 964 value greater then 14, the @code{E} may
|
number will be interpreted as integer, unless it has a signed exponent |
number will be interpreted as integer, unless it has a signed exponent |
(both @code{+} and @code{-} are allowed as signs). |
(both @code{+} and @code{-} are allowed as signs). |
|
|
|
@cindex angles in trigonometric operations |
|
@cindex trigonometric operations |
Angles in floating point operations are given in radians (a full circle |
Angles in floating point operations are given in radians (a full circle |
has 2 pi radians). Note, that Gforth has a separate floating point |
has 2 pi radians). Note, that Gforth has a separate floating point |
stack, but we use the unified notation. |
stack, but we use the unified notation. |
|
|
|
@cindex floating-point arithmetic, pitfalls |
Floating point numbers have a number of unpleasant surprises for the |
Floating point numbers have a number of unpleasant surprises for the |
unwary (e.g., floating point addition is not associative) and even a few |
unwary (e.g., floating point addition is not associative) and even a few |
for the wary. You should not use them unless you know what you are doing |
for the wary. You should not use them unless you know what you are doing |
Line 903 doc-fasinh
|
Line 1013 doc-fasinh
|
doc-facosh |
doc-facosh |
doc-fatanh |
doc-fatanh |
|
|
@node Stack Manipulation, Memory access, Arithmetic, Words |
@node Stack Manipulation, Memory, Arithmetic, Words |
@section Stack Manipulation |
@section Stack Manipulation |
|
@cindex stack manipulation words |
|
|
|
@cindex floating-point stack in the standard |
Gforth has a data stack (aka parameter stack) for characters, cells, |
Gforth has a data stack (aka parameter stack) for characters, cells, |
addresses, and double cells, a floating point stack for floating point |
addresses, and double cells, a floating point stack for floating point |
numbers, a return stack for storing the return addresses of colon |
numbers, a return stack for storing the return addresses of colon |
Line 919 they work also for a unified stack model
|
Line 1031 they work also for a unified stack model
|
it. Instead, just say that your program has an environmental dependency |
it. Instead, just say that your program has an environmental dependency |
on a separate FP stack. |
on a separate FP stack. |
|
|
|
@cindex return stack and locals |
|
@cindex locals and return stack |
Also, a Forth system is allowed to keep the local variables on the |
Also, a Forth system is allowed to keep the local variables on the |
return stack. This is reasonable, as local variables usually eliminate |
return stack. This is reasonable, as local variables usually eliminate |
the need to use the return stack explicitly. So, if you want to produce |
the need to use the return stack explicitly. So, if you want to produce |
Line 936 standard document for the exact rules).
|
Line 1050 standard document for the exact rules).
|
|
|
@node Data stack, Floating point stack, Stack Manipulation, Stack Manipulation |
@node Data stack, Floating point stack, Stack Manipulation, Stack Manipulation |
@subsection Data stack |
@subsection Data stack |
|
@cindex data stack manipulation words |
|
@cindex stack manipulations words, data stack |
|
|
doc-drop |
doc-drop |
doc-nip |
doc-nip |
doc-dup |
doc-dup |
Line 957 doc-2rot
|
Line 1074 doc-2rot
|
|
|
@node Floating point stack, Return stack, Data stack, Stack Manipulation |
@node Floating point stack, Return stack, Data stack, Stack Manipulation |
@subsection Floating point stack |
@subsection Floating point stack |
|
@cindex floating-point stack manipulation words |
|
@cindex stack manipulation words, floating-point stack |
|
|
doc-fdrop |
doc-fdrop |
doc-fnip |
doc-fnip |
doc-fdup |
doc-fdup |
Line 967 doc-frot
|
Line 1087 doc-frot
|
|
|
@node Return stack, Locals stack, Floating point stack, Stack Manipulation |
@node Return stack, Locals stack, Floating point stack, Stack Manipulation |
@subsection Return stack |
@subsection Return stack |
|
@cindex return stack manipulation words |
|
@cindex stack manipulation words, return stack |
|
|
doc->r |
doc->r |
doc-r> |
doc-r> |
doc-r@ |
doc-r@ |
Line 981 doc-2rdrop
|
Line 1104 doc-2rdrop
|
|
|
@node Stack pointer manipulation, , Locals stack, Stack Manipulation |
@node Stack pointer manipulation, , Locals stack, Stack Manipulation |
@subsection Stack pointer manipulation |
@subsection Stack pointer manipulation |
|
@cindex stack pointer manipulation words |
|
|
doc-sp@ |
doc-sp@ |
doc-sp! |
doc-sp! |
doc-fp@ |
doc-fp@ |
Line 990 doc-rp!
|
Line 1115 doc-rp!
|
doc-lp@ |
doc-lp@ |
doc-lp! |
doc-lp! |
|
|
@node Memory access, Control Structures, Stack Manipulation, Words |
@node Memory, Control Structures, Stack Manipulation, Words |
@section Memory access |
@section Memory |
|
@cindex Memory words |
|
|
@menu |
@menu |
* Stack-Memory transfers:: |
* Memory Access:: |
* Address arithmetic:: |
* Address arithmetic:: |
* Memory block access:: |
* Memory Blocks:: |
@end menu |
@end menu |
|
|
@node Stack-Memory transfers, Address arithmetic, Memory access, Memory access |
@node Memory Access, Address arithmetic, Memory, Memory |
@subsection Stack-Memory transfers |
@subsection Memory Access |
|
@cindex memory access words |
|
|
doc-@ |
doc-@ |
doc-! |
doc-! |
Line 1016 doc-sf!
|
Line 1143 doc-sf!
|
doc-df@ |
doc-df@ |
doc-df! |
doc-df! |
|
|
@node Address arithmetic, Memory block access, Stack-Memory transfers, Memory access |
@node Address arithmetic, Memory Blocks, Memory Access, Memory |
@subsection Address arithmetic |
@subsection Address arithmetic |
|
@cindex address arithmetic words |
|
|
ANS Forth does not specify the sizes of the data types. Instead, it |
ANS Forth does not specify the sizes of the data types. Instead, it |
offers a number of words for computing sizes and doing address |
offers a number of words for computing sizes and doing address |
Line 1026 address units (aus); on most systems the
|
Line 1154 address units (aus); on most systems the
|
that a character may have more than one au, so @code{chars} is no noop |
that a character may have more than one au, so @code{chars} is no noop |
(on systems where it is a noop, it compiles to nothing). |
(on systems where it is a noop, it compiles to nothing). |
|
|
|
@cindex alignment of addresses for types |
ANS Forth also defines words for aligning addresses for specific |
ANS Forth also defines words for aligning addresses for specific |
addresses. Many computers require that accesses to specific data types |
types. Many computers require that accesses to specific data types |
must only occur at specific addresses; e.g., that cells may only be |
must only occur at specific addresses; e.g., that cells may only be |
accessed at addresses divisible by 4. Even if a machine allows unaligned |
accessed at addresses divisible by 4. Even if a machine allows unaligned |
accesses, it can usually perform aligned accesses faster. |
accesses, it can usually perform aligned accesses faster. |
Line 1041 an oversight, but reflects the fact that
|
Line 1170 an oversight, but reflects the fact that
|
char-aligned have no use in the standard and therefore will not be |
char-aligned have no use in the standard and therefore will not be |
created. |
created. |
|
|
|
@cindex @code{CREATE} and alignment |
The standard guarantees that addresses returned by @code{CREATE}d words |
The standard guarantees that addresses returned by @code{CREATE}d words |
are cell-aligned; in addition, Gforth guarantees that these addresses |
are cell-aligned; in addition, Gforth guarantees that these addresses |
are aligned for all purposes. |
are aligned for all purposes. |
Line 1052 doc-chars
|
Line 1182 doc-chars
|
doc-char+ |
doc-char+ |
doc-cells |
doc-cells |
doc-cell+ |
doc-cell+ |
|
doc-cell |
doc-align |
doc-align |
doc-aligned |
doc-aligned |
doc-floats |
doc-floats |
doc-float+ |
doc-float+ |
|
doc-float |
doc-falign |
doc-falign |
doc-faligned |
doc-faligned |
doc-sfloats |
doc-sfloats |
Line 1072 doc-cfalign
|
Line 1204 doc-cfalign
|
doc-cfaligned |
doc-cfaligned |
doc-address-unit-bits |
doc-address-unit-bits |
|
|
@node Memory block access, , Address arithmetic, Memory access |
@node Memory Blocks, , Address arithmetic, Memory |
@subsection Memory block access |
@subsection Memory Blocks |
|
@cindex memory block words |
|
|
doc-move |
doc-move |
doc-erase |
doc-erase |
Line 1086 doc-cmove>
|
Line 1219 doc-cmove>
|
doc-fill |
doc-fill |
doc-blank |
doc-blank |
|
|
@node Control Structures, Locals, Memory access, Words |
@node Control Structures, Locals, Memory, Words |
@section Control Structures |
@section Control Structures |
|
@cindex control structures |
|
|
Control structures in Forth cannot be used in interpret state, only in |
Control structures in Forth cannot be used in interpret state, only in |
compile state, i.e., in a colon definition. We do not like this |
compile state@footnote{More precisely, they have no interpretation |
limitation, but have not seen a satisfying way around it yet, although |
semantics (@pxref{Interpretation and Compilation Semantics})}, i.e., in |
many schemes have been proposed. |
a colon definition. We do not like this limitation, but have not seen a |
|
satisfying way around it yet, although many schemes have been proposed. |
|
|
@menu |
@menu |
* Selection:: |
* Selection:: |
Line 1105 many schemes have been proposed.
|
Line 1240 many schemes have been proposed.
|
|
|
@node Selection, Simple Loops, Control Structures, Control Structures |
@node Selection, Simple Loops, Control Structures, Control Structures |
@subsection Selection |
@subsection Selection |
|
@cindex selection control structures |
|
@cindex control structures for selection |
|
|
|
@cindex @code{IF} control structure |
@example |
@example |
@var{flag} |
@var{flag} |
IF |
IF |
Line 1141 system that only supplies @code{THEN} is
|
Line 1279 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}. |
|
|
|
@cindex @code{CASE} control structure |
@example |
@example |
@var{n} |
@var{n} |
CASE |
CASE |
Line 1160 but must not consume it.
|
Line 1302 but must not consume it.
|
|
|
@node Simple Loops, Counted Loops, Selection, Control Structures |
@node Simple Loops, Counted Loops, Selection, Control Structures |
@subsection Simple Loops |
@subsection Simple Loops |
|
@cindex simple loops |
|
@cindex loops without count |
|
|
|
@cindex @code{WHILE} loop |
@example |
@example |
BEGIN |
BEGIN |
@var{code1} |
@var{code1} |
Line 1171 REPEAT
|
Line 1316 REPEAT
|
@end example |
@end example |
|
|
@var{code1} is executed and @var{flag} is computed. If it is true, |
@var{code1} is executed and @var{flag} is computed. If it is true, |
@var{code2} is executed and the loop is restarted; If @var{flag} is false, execution continues after the @code{REPEAT}. |
@var{code2} is executed and the loop is restarted; If @var{flag} is |
|
false, execution continues after the @code{REPEAT}. |
|
|
|
@cindex @code{UNTIL} loop |
@example |
@example |
BEGIN |
BEGIN |
@var{code} |
@var{code} |
Line 1182 UNTIL
|
Line 1329 UNTIL
|
|
|
@var{code} is executed. The loop is restarted if @code{flag} is false. |
@var{code} is executed. The loop is restarted if @code{flag} is false. |
|
|
|
@cindex endless loop |
|
@cindex loops, endless |
@example |
@example |
BEGIN |
BEGIN |
@var{code} |
@var{code} |
Line 1192 This is an endless loop.
|
Line 1341 This is an endless loop.
|
|
|
@node Counted Loops, Arbitrary control structures, Simple Loops, Control Structures |
@node Counted Loops, Arbitrary control structures, Simple Loops, Control Structures |
@subsection Counted Loops |
@subsection Counted Loops |
|
@cindex counted loops |
|
@cindex loops, counted |
|
@cindex @code{DO} loops |
|
|
The basic counted loop is: |
The basic counted loop is: |
@example |
@example |
Line 1217 The index of the innermost loop can be a
|
Line 1369 The index of the innermost loop can be a
|
of the next loop with @code{j}, and the index of the third loop with |
of the next loop with @code{j}, and the index of the third loop with |
@code{k}. |
@code{k}. |
|
|
|
doc-i |
|
doc-j |
|
doc-k |
|
|
The loop control data are kept on the return stack, so there are some |
The loop control data are kept on the return stack, so there are some |
restrictions on mixing return stack accesses and counted loop |
restrictions on mixing return stack accesses and counted loop |
words. E.g., if you put values on the return stack outside the loop, you |
words. E.g., if you put values on the return stack outside the loop, you |
Line 1234 arithmetic). This behaviour is usually n
|
Line 1390 arithmetic). This behaviour is usually n
|
Gforth offers @code{+DO} and @code{U+DO} (as replacements for |
Gforth offers @code{+DO} and @code{U+DO} (as replacements for |
@code{?DO}), which do not enter the loop if @var{start} is greater than |
@code{?DO}), which do not enter the loop if @var{start} is greater than |
@var{limit}; @code{+DO} is for signed loop parameters, @code{U+DO} for |
@var{limit}; @code{+DO} is for signed loop parameters, @code{U+DO} for |
unsigned loop parameters. These words can be implemented easily on |
unsigned loop parameters. |
standard systems, so using them does not make your programs hard to |
|
port; e.g.: |
|
@example |
|
: +DO ( compile-time: -- do-sys; run-time: n1 n2 -- ) |
|
POSTPONE over POSTPONE min POSTPONE ?DO ; immediate |
|
@end example |
|
|
|
@code{LOOP} can be replaced with @code{@var{n} +LOOP}; this updates the |
@code{LOOP} can be replaced with @code{@var{n} +LOOP}; this updates the |
index by @var{n} instead of by 1. The loop is terminated when the border |
index by @var{n} instead of by 1. The loop is terminated when the border |
Line 1250 between @var{limit-1} and @var{limit} is
|
Line 1400 between @var{limit-1} and @var{limit} is
|
|
|
@code{4 1 +DO i . 2 +LOOP} prints @code{1 3} |
@code{4 1 +DO i . 2 +LOOP} prints @code{1 3} |
|
|
|
@cindex negative increment for counted loops |
|
@cindex counted loops with negative increment |
The behaviour of @code{@var{n} +LOOP} is peculiar when @var{n} is negative: |
The behaviour of @code{@var{n} +LOOP} is peculiar when @var{n} is negative: |
|
|
@code{-1 0 ?DO i . -1 +LOOP} prints @code{0 -1} |
@code{-1 0 ?DO i . -1 +LOOP} prints @code{0 -1} |
Line 1268 between @var{limit+1} and @var{limit} is
|
Line 1420 between @var{limit+1} and @var{limit} is
|
|
|
@code{ 0 0 -DO i . 1 -LOOP} prints nothing |
@code{ 0 0 -DO i . 1 -LOOP} prints nothing |
|
|
Another alternative is @code{@var{n} S+LOOP}, where the negative |
Unfortunately, @code{+DO}, @code{U+DO}, @code{-DO}, @code{U-DO} and |
case behaves symmetrical to the positive case: |
@code{-LOOP} are not in the ANS Forth standard. However, an |
|
implementation for these words that uses only standard words is provided |
@code{-2 0 -DO i . -1 S+LOOP} prints @code{0 -1} |
in @file{compat/loops.fs}. |
|
|
The loop is terminated when the border between @var{limit@minus{}sgn(n)} |
|
and @var{limit} is crossed. Unfortunately, neither @code{-LOOP} nor |
|
@code{S+LOOP} are part of the ANS Forth standard, and they are not easy |
|
to implement using standard words. If you want to write standard |
|
programs, just avoid counting down. |
|
|
|
@code{?DO} can also be replaced by @code{DO}. @code{DO} always enters |
@code{?DO} can also be replaced by @code{DO}. @code{DO} always enters |
the loop, independent of the loop parameters. Do not use @code{DO}, even |
the loop, independent of the loop parameters. Do not use @code{DO}, even |
Line 1289 to become invalid during maintenance of
|
Line 1435 to become invalid during maintenance of
|
@code{EXIT}. @code{UNLOOP} removes the loop control parameters from the |
@code{EXIT}. @code{UNLOOP} removes the loop control parameters from the |
return stack so @code{EXIT} can get to its return address. |
return stack so @code{EXIT} can get to its return address. |
|
|
|
@cindex @code{FOR} loops |
Another counted loop is |
Another counted loop is |
@example |
@example |
@var{n} |
@var{n} |
Line 1300 This is the preferred loop of native cod
|
Line 1447 This is the preferred loop of native cod
|
lazy to optimize @code{?DO} loops properly. In Gforth, this loop |
lazy to optimize @code{?DO} loops properly. In Gforth, this loop |
iterates @var{n+1} times; @code{i} produces values starting with @var{n} |
iterates @var{n+1} times; @code{i} produces values starting with @var{n} |
and ending with 0. Other Forth systems may behave differently, even if |
and ending with 0. Other Forth systems may behave differently, even if |
they support @code{FOR} loops. |
they support @code{FOR} loops. To avoid problems, don't use @code{FOR} |
|
loops. |
|
|
@node Arbitrary control structures, Calls and returns, Counted Loops, Control Structures |
@node Arbitrary control structures, Calls and returns, Counted Loops, Control Structures |
@subsection Arbitrary control structures |
@subsection Arbitrary control structures |
|
@cindex control structures, user-defined |
|
|
|
@cindex control-flow stack |
ANS Forth permits and supports using control structures in a non-nested |
ANS Forth permits and supports using control structures in a non-nested |
way. Information about incomplete control structures is stored on the |
way. Information about incomplete control structures is stored on the |
control-flow stack. This stack may be implemented on the Forth data |
control-flow stack. This stack may be implemented on the Forth data |
stack, and this is what we have done in Gforth. |
stack, and this is what we have done in Gforth. |
|
|
|
@cindex @code{orig}, control-flow stack item |
|
@cindex @code{dest}, control-flow stack item |
An @i{orig} entry represents an unresolved forward branch, a @i{dest} |
An @i{orig} entry represents an unresolved forward branch, a @i{dest} |
entry represents a backward branch target. A few words are the basis for |
entry represents a backward branch target. A few words are the basis for |
building any control structure possible (except control structures that |
building any control structure possible (except control structures that |
Line 1336 doc-else
|
Line 1488 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 1346 doc-u-do
|
Line 1504 doc-u-do
|
doc-do |
doc-do |
doc-for |
doc-for |
doc-loop |
doc-loop |
doc-s+loop |
|
doc-+loop |
doc-+loop |
doc--loop |
doc--loop |
doc-next |
doc-next |
Line 1411 while
|
Line 1568 while
|
repeat |
repeat |
@end example |
@end example |
|
|
That's much easier to read, isn't it? Of course, @code{BEGIN} and |
That's much easier to read, isn't it? Of course, @code{REPEAT} and |
@code{WHILE} are predefined, so in this example it would not be |
@code{WHILE} are predefined, so in this example it would not be |
necessary to define them. |
necessary to define them. |
|
|
@node Calls and returns, Exception Handling, Arbitrary control structures, Control Structures |
@node Calls and returns, Exception Handling, Arbitrary control structures, Control Structures |
@subsection Calls and returns |
@subsection Calls and returns |
|
@cindex calling a definition |
|
@cindex returning from a definition |
|
|
A definition can be called simply be writing the name of the |
A definition can be called simply be writing the name of the |
definition. When the end of the definition is reached, it returns. An |
definition. When the end of the definition is reached, it returns. An |
Line 1432 doc-;s
|
Line 1591 doc-;s
|
|
|
@node Exception Handling, , Calls and returns, Control Structures |
@node Exception Handling, , Calls and returns, Control Structures |
@subsection Exception Handling |
@subsection Exception Handling |
|
@cindex Exceptions |
|
|
doc-catch |
doc-catch |
doc-throw |
doc-throw |
|
|
@node Locals, Defining Words, Control Structures, Words |
@node Locals, Defining Words, Control Structures, Words |
@section Locals |
@section Locals |
|
@cindex locals |
|
|
Local variables can make Forth programming more enjoyable and Forth |
Local variables can make Forth programming more enjoyable and Forth |
programs easier to read. Unfortunately, the locals of ANS Forth are |
programs easier to read. Unfortunately, the locals of ANS Forth are |
Line 1457 at EuroForth '94; it is available at
|
Line 1618 at EuroForth '94; it is available at
|
|
|
@node Gforth locals, ANS Forth locals, Locals, Locals |
@node Gforth locals, ANS Forth locals, Locals, Locals |
@subsection Gforth locals |
@subsection Gforth locals |
|
@cindex Gforth locals |
|
@cindex locals, Gforth style |
|
|
Locals can be defined with |
Locals can be defined with |
|
|
Line 1489 find. However, this problem can be avoid
|
Line 1652 find. However, this problem can be avoid
|
conventions: Do not use both notations in the same program. If you do, |
conventions: Do not use both notations in the same program. If you do, |
they should be distinguished using additional means, e.g. by position. |
they should be distinguished using additional means, e.g. by position. |
|
|
|
@cindex types of locals |
|
@cindex locals types |
The name of the local may be preceded by a type specifier, e.g., |
The name of the local may be preceded by a type specifier, e.g., |
@code{F:} for a floating point value: |
@code{F:} for a floating point value: |
|
|
Line 1499 The name of the local may be preceded by
|
Line 1664 The name of the local may be preceded by
|
Ar Bi f* Ai Br f* f+ ; |
Ar Bi f* Ai Br f* f+ ; |
@end example |
@end example |
|
|
|
@cindex flavours of locals |
|
@cindex locals flavours |
|
@cindex value-flavoured locals |
|
@cindex variable-flavoured locals |
Gforth currently supports cells (@code{W:}, @code{W^}), doubles |
Gforth currently supports cells (@code{W:}, @code{W^}), doubles |
(@code{D:}, @code{D^}), floats (@code{F:}, @code{F^}) and characters |
(@code{D:}, @code{D^}), floats (@code{F:}, @code{F^}) and characters |
(@code{C:}, @code{C^}) in two flavours: a value-flavoured local (defined |
(@code{C:}, @code{C^}) in two flavours: a value-flavoured local (defined |
with @code{W:}, @code{D:} etc.) produces its value and can be changed |
with @code{W:}, @code{D:} etc.) produces its value and can be changed |
with @code{TO}. A variable-flavoured local (defined with @code{W^} etc.) |
with @code{TO}. A variable-flavoured local (defined with @code{W^} etc.) |
produces its address (which becomes invalid when the variable's scope is |
produces its address (which becomes invalid when the variable's scope is |
left). E.g., the standard word @code{emit} can be defined in therms of |
left). E.g., the standard word @code{emit} can be defined in terms of |
@code{type} like this: |
@code{type} like this: |
|
|
@example |
@example |
Line 1513 left). E.g., the standard word @code{emi
|
Line 1682 left). E.g., the standard word @code{emi
|
char* 1 type ; |
char* 1 type ; |
@end example |
@end example |
|
|
|
@cindex default type of locals |
|
@cindex locals, default type |
A local without type specifier is a @code{W:} local. Both flavours of |
A local without type specifier is a @code{W:} local. Both flavours of |
locals are initialized with values from the data or FP stack. |
locals are initialized with values from the data or FP stack. |
|
|
Line 1531 poses the following questions:
|
Line 1702 poses the following questions:
|
|
|
@node Where are locals visible by name?, How long do locals live?, Gforth locals, Gforth locals |
@node Where are locals visible by name?, How long do locals live?, Gforth locals, Gforth locals |
@subsubsection Where are locals visible by name? |
@subsubsection Where are locals visible by name? |
|
@cindex locals visibility |
|
@cindex visibility of locals |
|
@cindex scope of locals |
|
|
Basically, the answer is that locals are visible where you would expect |
Basically, the answer is that locals are visible where you would expect |
it in block-structured languages, and sometimes a little longer. If you |
it in block-structured languages, and sometimes a little longer. If you |
Line 1564 definition? Which local is meant, if the
|
Line 1738 definition? Which local is meant, if the
|
two independent control flow paths? |
two independent control flow paths? |
|
|
This should be enough detail for nearly all users, so you can skip the |
This should be enough detail for nearly all users, so you can skip the |
rest of this section. If you relly must know all the gory details and |
rest of this section. If you really must know all the gory details and |
options, read on. |
options, read on. |
|
|
In order to implement this rule, the compiler has to know which places |
In order to implement this rule, the compiler has to know which places |
Line 1577 that the visibility of some locals is mo
|
Line 1751 that the visibility of some locals is mo
|
says. If @code{UNREACHABLE} is used where it should not (i.e., if you |
says. If @code{UNREACHABLE} is used where it should not (i.e., if you |
lie to the compiler), buggy code will be produced. |
lie to the compiler), buggy code will be produced. |
|
|
|
doc-unreachable |
|
|
Another problem with this rule is that at @code{BEGIN}, the compiler |
Another problem with this rule is that at @code{BEGIN}, the compiler |
does not know which locals will be visible on the incoming |
does not know which locals will be visible on the incoming |
back-edge. All problems discussed in the following are due to this |
back-edge. All problems discussed in the following are due to this |
Line 1617 are entered only through the @code{BEGIN
|
Line 1793 are entered only through the @code{BEGIN
|
@code{BEGIN}...@code{UNTIL} loops and it is implemented in our |
@code{BEGIN}...@code{UNTIL} loops and it is implemented in our |
compiler. When the branch to the @code{BEGIN} is finally generated by |
compiler. When the branch to the @code{BEGIN} is finally generated by |
@code{AGAIN} or @code{UNTIL}, the compiler checks the guess and |
@code{AGAIN} or @code{UNTIL}, the compiler checks the guess and |
warns the user if it was too optimisitic: |
warns the user if it was too optimistic: |
@example |
@example |
IF |
IF |
@{ x @} |
@{ x @} |
Line 1690 REPEAT
|
Line 1866 REPEAT
|
|
|
@node How long do locals live?, Programming Style, Where are locals visible by name?, Gforth locals |
@node How long do locals live?, Programming Style, Where are locals visible by name?, Gforth locals |
@subsubsection How long do locals live? |
@subsubsection How long do locals live? |
|
@cindex locals lifetime |
|
@cindex lifetime of locals |
|
|
The right answer for the lifetime question would be: A local lives at |
The right answer for the lifetime question would be: A local lives at |
least as long as it can be accessed. For a value-flavoured local this |
least as long as it can be accessed. For a value-flavoured local this |
Line 1704 afterwards are erroneous).
|
Line 1882 afterwards are erroneous).
|
|
|
@node Programming Style, Implementation, How long do locals live?, Gforth locals |
@node Programming Style, Implementation, How long do locals live?, Gforth locals |
@subsubsection Programming Style |
@subsubsection Programming Style |
|
@cindex locals programming style |
|
@cindex programming style, locals |
|
|
The freedom to define locals anywhere has the potential to change |
The freedom to define locals anywhere has the potential to change |
programming styles dramatically. In particular, the need to use the |
programming styles dramatically. In particular, the need to use the |
Line 1724 readable. Of course, this benefit will o
|
Line 1904 readable. Of course, this benefit will o
|
programmers continue to honour the principle of factoring instead of |
programmers continue to honour the principle of factoring instead of |
using the added latitude to make the words longer. |
using the added latitude to make the words longer. |
|
|
|
@cindex single-assignment style for locals |
Using @code{TO} can and should be avoided. Without @code{TO}, |
Using @code{TO} can and should be avoided. Without @code{TO}, |
every value-flavoured local has only a single assignment and many |
every value-flavoured local has only a single assignment and many |
advantages of functional languages apply to Forth. I.e., programs are |
advantages of functional languages apply to Forth. I.e., programs are |
Line 1736 E.g., a definition using @code{TO} might
|
Line 1917 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 1759 are initialized with the right value for
|
Line 1940 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 1773 in every loop iteration.
|
Line 1954 in every loop iteration.
|
|
|
@node Implementation, , Programming Style, Gforth locals |
@node Implementation, , Programming Style, Gforth locals |
@subsubsection Implementation |
@subsubsection Implementation |
|
@cindex locals implementation |
|
@cindex implementation of locals |
|
|
|
@cindex locals stack |
Gforth uses an extra locals stack. The most compelling reason for |
Gforth uses an extra locals stack. The most compelling reason for |
this is that the return stack is not float-aligned; using an extra stack |
this is that the return stack is not float-aligned; using an extra stack |
also eliminates the problems and restrictions of using the return stack |
also eliminates the problems and restrictions of using the return stack |
Line 1809 area and @code{@}} switches it back and
|
Line 1993 area and @code{@}} switches it back and
|
initializing code. @code{W:} etc.@ are normal defining words. This |
initializing code. @code{W:} etc.@ are normal defining words. This |
special area is cleared at the start of every colon definition. |
special area is cleared at the start of every colon definition. |
|
|
|
@cindex wordlist for defining locals |
A special feature of Gforth's dictionary is used to implement the |
A special feature of Gforth's dictionary is used to implement the |
definition of locals without type specifiers: every wordlist (aka |
definition of locals without type specifiers: every wordlist (aka |
vocabulary) has its own methods for searching |
vocabulary) has its own methods for searching |
Line 1855 level to the level at the orig point, so
|
Line 2040 level to the level at the orig point, so
|
adjustment from the current level to the right level after the |
adjustment from the current level to the right level after the |
@code{THEN}. |
@code{THEN}. |
|
|
|
@cindex locals information on the control-flow stack |
|
@cindex control-flow stack items, locals information |
In a conventional Forth implementation a dest control-flow stack entry |
In a conventional Forth implementation a dest control-flow stack entry |
is just the target address and an orig entry is just the address to be |
is just the target address and an orig entry is just the address to be |
patched. Our locals implementation adds a wordlist to every orig or dest |
patched. Our locals implementation adds a wordlist to every orig or dest |
Line 1901 usually less than reclaiming this space
|
Line 2088 usually less than reclaiming this space
|
|
|
@node ANS Forth locals, , Gforth locals, Locals |
@node ANS Forth locals, , Gforth locals, Locals |
@subsection ANS Forth locals |
@subsection ANS Forth locals |
|
@cindex locals, ANS Forth style |
|
|
The ANS Forth locals wordset does not define a syntax for locals, but |
The ANS Forth locals wordset does not define a syntax for locals, but |
words that make it possible to define various syntaxes. One of the |
words that make it possible to define various syntaxes. One of the |
Line 1933 stack easier.
|
Line 2121 stack easier.
|
The whole definition must be in one line. |
The whole definition must be in one line. |
@end itemize |
@end itemize |
|
|
Locals defined in this way behave like @code{VALUE}s |
Locals defined in this way behave like @code{VALUE}s (@xref{Simple |
(@xref{Values}). I.e., they are initialized from the stack. Using their |
Defining Words}). I.e., they are initialized from the stack. Using their |
name produces their value. Their value can be changed using @code{TO}. |
name produces their value. Their value can be changed using @code{TO}. |
|
|
Since this syntax is supported by Gforth directly, you need not do |
Since this syntax is supported by Gforth directly, you need not do |
anything to use it. If you want to port a program using this syntax to |
anything to use it. If you want to port a program using this syntax to |
another ANS Forth system, use @file{anslocal.fs} to implement the syntax |
another ANS Forth system, use @file{compat/anslocal.fs} to implement the |
on the other system. |
syntax on the other system. |
|
|
Note that a syntax shown in the standard, section A.13 looks |
Note that a syntax shown in the standard, section A.13 looks |
similar, but is quite different in having the order of locals |
similar, but is quite different in having the order of locals |
Line 1959 programs harder to read, and easier to m
|
Line 2147 programs harder to read, and easier to m
|
merit of this syntax is that it is easy to implement using the ANS Forth |
merit of this syntax is that it is easy to implement using the ANS Forth |
locals wordset. |
locals wordset. |
|
|
@node Defining Words, Wordlists, Locals, Words |
@node Defining Words, Tokens for Words, Locals, Words |
@section Defining Words |
@section Defining Words |
|
@cindex defining words |
|
|
@menu |
@menu |
* Values:: |
* Simple Defining Words:: |
|
* Colon Definitions:: |
|
* User-defined Defining Words:: |
|
* Supplying names:: |
|
* Interpretation and Compilation Semantics:: |
@end menu |
@end menu |
|
|
@node Values, , Defining Words, Defining Words |
@node Simple Defining Words, Colon Definitions, Defining Words, Defining Words |
@subsection Values |
@subsection Simple Defining Words |
|
@cindex simple defining words |
|
@cindex defining words, simple |
|
|
|
doc-constant |
|
doc-2constant |
|
doc-fconstant |
|
doc-variable |
|
doc-2variable |
|
doc-fvariable |
|
doc-create |
|
doc-user |
|
doc-value |
|
doc-to |
|
doc-defer |
|
doc-is |
|
|
|
@node Colon Definitions, User-defined Defining Words, Simple Defining Words, Defining Words |
|
@subsection Colon Definitions |
|
@cindex colon definitions |
|
|
|
@example |
|
: name ( ... -- ... ) |
|
word1 word2 word3 ; |
|
@end example |
|
|
|
creates a word called @code{name}, that, upon execution, executes |
|
@code{word1 word2 word3}. @code{name} is a @dfn{(colon) definition}. |
|
|
|
The explanation above is somewhat superficial. @xref{Interpretation and |
|
Compilation Semantics} for an in-depth discussion of some of the issues |
|
involved. |
|
|
|
doc-: |
|
doc-; |
|
|
|
@node User-defined Defining Words, Supplying names, Colon Definitions, Defining Words |
|
@subsection User-defined Defining Words |
|
@cindex user-defined defining words |
|
@cindex defining words, user-defined |
|
|
|
You can create new defining words simply by wrapping defining-time code |
|
around existing defining words and putting the sequence in a colon |
|
definition. |
|
|
|
@cindex @code{CREATE} ... @code{DOES>} |
|
If you want the words defined with your defining words to behave |
|
differently from words defined with standard defining words, you can |
|
write your defining word like this: |
|
|
|
@example |
|
: def-word ( "name" -- ) |
|
Create @var{code1} |
|
DOES> ( ... -- ... ) |
|
@var{code2} ; |
|
|
|
def-word name |
|
@end example |
|
|
|
Technically, this fragment defines a defining word @code{def-word}, and |
|
a word @code{name}; when you execute @code{name}, the address of the |
|
body of @code{name} is put on the data stack and @var{code2} is executed |
|
(the address of the body of @code{name} is the address @code{HERE} |
|
returns immediately after the @code{CREATE}). |
|
|
|
In other words, if you make the following definitions: |
|
|
|
@example |
|
: def-word1 ( "name" -- ) |
|
Create @var{code1} ; |
|
|
|
: action1 ( ... -- ... ) |
|
@var{code2} ; |
|
|
|
def-word name1 |
|
@end example |
|
|
|
Using @code{name1 action1} is equivalent to using @code{name}. |
|
|
|
E.g., you can implement @code{Constant} in this way: |
|
|
|
@example |
|
: constant ( w "name" -- ) |
|
create , |
|
DOES> ( -- w ) |
|
@@ ; |
|
@end example |
|
|
|
When you create a constant with @code{5 constant five}, first a new word |
|
@code{five} is created, then the value 5 is laid down in the body of |
|
@code{five} with @code{,}. When @code{five} is invoked, the address of |
|
the body is put on the stack, and @code{@@} retrieves the value 5. |
|
|
|
@cindex stack effect of @code{DOES>}-parts |
|
@cindex @code{DOES>}-parts, stack effect |
|
In the example above the stack comment after the @code{DOES>} specifies |
|
the stack effect of the defined words, not the stack effect of the |
|
following code (the following code expects the address of the body on |
|
the top of stack, which is not reflected in the stack comment). This is |
|
the convention that I use and recommend (it clashes a bit with using |
|
locals declarations for stack effect specification, though). |
|
|
|
@subsubsection Applications of @code{CREATE..DOES>} |
|
@cindex @code{CREATE} ... @code{DOES>}, applications |
|
|
|
You may wonder how to use this feature. Here are some usage patterns: |
|
|
|
@cindex factoring similar colon definitions |
|
When you see a sequence of code occurring several times, and you can |
|
identify a meaning, you will factor it out as a colon definition. When |
|
you see similar colon definitions, you can factor them using |
|
@code{CREATE..DOES>}. E.g., an assembler usually defines several words |
|
that look very similar: |
|
@example |
|
: ori, ( reg-target reg-source n -- ) |
|
0 asm-reg-reg-imm ; |
|
: andi, ( reg-target reg-source n -- ) |
|
1 asm-reg-reg-imm ; |
|
@end example |
|
|
|
This could be factored with: |
|
@example |
|
: reg-reg-imm ( op-code -- ) |
|
create , |
|
DOES> ( reg-target reg-source n -- ) |
|
@@ asm-reg-reg-imm ; |
|
|
|
0 reg-reg-imm ori, |
|
1 reg-reg-imm andi, |
|
@end example |
|
|
@node Wordlists, Files, Defining Words, Words |
@cindex currying |
|
Another view of @code{CREATE..DOES>} is to consider it as a crude way to |
|
supply a part of the parameters for a word (known as @dfn{currying} in |
|
the functional language community). E.g., @code{+} needs two |
|
parameters. Creating versions of @code{+} with one parameter fixed can |
|
be done like this: |
|
@example |
|
: curry+ ( n1 -- ) |
|
create , |
|
DOES> ( n2 -- n1+n2 ) |
|
@@ + ; |
|
|
|
3 curry+ 3+ |
|
-2 curry+ 2- |
|
@end example |
|
|
|
@subsubsection The gory details of @code{CREATE..DOES>} |
|
@cindex @code{CREATE} ... @code{DOES>}, details |
|
|
|
doc-does> |
|
|
|
@cindex @code{DOES>} in a separate definition |
|
This means that you need not use @code{CREATE} and @code{DOES>} in the |
|
same definition; E.g., you can put the @code{DOES>}-part in a separate |
|
definition. This allows us to, e.g., select among different DOES>-parts: |
|
@example |
|
: does1 |
|
DOES> ( ... -- ... ) |
|
... ; |
|
|
|
: does2 |
|
DOES> ( ... -- ... ) |
|
... ; |
|
|
|
: def-word ( ... -- ... ) |
|
create ... |
|
IF |
|
does1 |
|
ELSE |
|
does2 |
|
ENDIF ; |
|
@end example |
|
|
|
@cindex @code{DOES>} in interpretation state |
|
In a standard program you can apply a @code{DOES>}-part only if the last |
|
word was defined with @code{CREATE}. In Gforth, the @code{DOES>}-part |
|
will override the behaviour of the last word defined in any case. In a |
|
standard program, you can use @code{DOES>} only in a colon |
|
definition. In Gforth, you can also use it in interpretation state, in a |
|
kind of one-shot mode: |
|
@example |
|
CREATE name ( ... -- ... ) |
|
@var{initialization} |
|
DOES> |
|
@var{code} ; |
|
@end example |
|
This is equivalent to the standard |
|
@example |
|
:noname |
|
DOES> |
|
@var{code} ; |
|
CREATE name EXECUTE ( ... -- ... ) |
|
@var{initialization} |
|
@end example |
|
|
|
You can get the address of the body of a word with |
|
|
|
doc->body |
|
|
|
@node Supplying names, Interpretation and Compilation Semantics, User-defined Defining Words, Defining Words |
|
@subsection Supplying names for the defined words |
|
@cindex names for defined words |
|
@cindex defining words, name parameter |
|
|
|
@cindex defining words, name given in a string |
|
By default, defining words take the names for the defined words from the |
|
input stream. Sometimes you want to supply the name from a string. You |
|
can do this with |
|
|
|
doc-nextname |
|
|
|
E.g., |
|
|
|
@example |
|
s" foo" nextname create |
|
@end example |
|
is equivalent to |
|
@example |
|
create foo |
|
@end example |
|
|
|
@cindex defining words without name |
|
Sometimes you want to define a word without a name. You can do this with |
|
|
|
doc-noname |
|
|
|
@cindex execution token of last defined word |
|
To make any use of the newly defined word, you need its execution |
|
token. You can get it with |
|
|
|
doc-lastxt |
|
|
|
E.g., you can initialize a deferred word with an anonymous colon |
|
definition: |
|
@example |
|
Defer deferred |
|
noname : ( ... -- ... ) |
|
... ; |
|
lastxt IS deferred |
|
@end example |
|
|
|
@code{lastxt} also works when the last word was not defined as |
|
@code{noname}. |
|
|
|
The standard has also recognized the need for anonymous words and |
|
provides |
|
|
|
doc-:noname |
|
|
|
This leaves the execution token for the word on the stack after the |
|
closing @code{;}. You can rewrite the last example with @code{:noname}: |
|
@example |
|
Defer deferred |
|
:noname ( ... -- ... ) |
|
... ; |
|
IS deferred |
|
@end example |
|
|
|
@node Interpretation and Compilation Semantics, , Supplying names, Defining Words |
|
@subsection Interpretation and Compilation Semantics |
|
@cindex semantics, interpretation and compilation |
|
|
|
@cindex interpretation semantics |
|
The @dfn{interpretation semantics} of a word are what the text |
|
interpreter does when it encounters the word in interpret state. It also |
|
appears in some other contexts, e.g., the execution token returned by |
|
@code{' @var{word}} identifies the interpretation semantics of |
|
@var{word} (in other words, @code{' @var{word} execute} is equivalent to |
|
interpret-state text interpretation of @code{@var{word}}). |
|
|
|
@cindex compilation semantics |
|
The @dfn{compilation semantics} of a word are what the text interpreter |
|
does when it encounters the word in compile state. It also appears in |
|
other contexts, e.g, @code{POSTPONE @var{word}} compiles@footnote{In |
|
standard terminology, ``appends to the current definition''.} the |
|
compilation semantics of @var{word}. |
|
|
|
@cindex execution semantics |
|
The standard also talks about @dfn{execution semantics}. They are used |
|
only for defining the interpretation and compilation semantics of many |
|
words. By default, the interpretation semantics of a word are to |
|
@code{execute} its execution semantics, and the compilation semantics of |
|
a word are to @code{compile,} its execution semantics.@footnote{In |
|
standard terminology: The default interpretation semantics are its |
|
execution semantics; the default compilation semantics are to append its |
|
execution semantics to the execution semantics of the current |
|
definition.} |
|
|
|
@cindex immediate words |
|
You can change the compilation semantics into @code{execute}ing the |
|
execution semantics with |
|
|
|
doc-immediate |
|
|
|
@cindex compile-only words |
|
You can remove the interpretation semantics of a word with |
|
|
|
doc-compile-only |
|
doc-restrict |
|
|
|
Note that ticking (@code{'}) compile-only words gives an error |
|
(``Interpreting a compile-only word''). |
|
|
|
Gforth also allows you to define words with arbitrary combinations of |
|
interpretation and compilation semantics. |
|
|
|
doc-interpret/compile: |
|
|
|
This feature was introduced for implementing @code{TO} and @code{S"}. I |
|
recommend that you do not define such words, as cute as they may be: |
|
they make it hard to get at both parts of the word in some contexts. |
|
E.g., assume you want to get an execution token for the compilation |
|
part. Instead, define two words, one that embodies the interpretation |
|
part, and one that embodies the compilation part. |
|
|
|
There is, however, a potentially useful application of this feature: |
|
Providing differing implementations for the default semantics. While |
|
this introduces redundancy and is therefore usually a bad idea, a |
|
performance improvement may be worth the trouble. E.g., consider the |
|
word @code{foobar}: |
|
|
|
@example |
|
: foobar |
|
foo bar ; |
|
@end example |
|
|
|
Let us assume that @code{foobar} is called so frequently that the |
|
calling overhead would take a significant amount of the run-time. We can |
|
optimize it with @code{interpret/compile:}: |
|
|
|
@example |
|
:noname |
|
foo bar ; |
|
:noname |
|
POSTPONE foo POSTPONE bar ; |
|
interpret/compile: foobar |
|
@end example |
|
|
|
This definition has the same interpretation semantics and essentially |
|
the same compilation semantics as the simple definition of |
|
@code{foobar}, but the implementation of the compilation semantics is |
|
more efficient with respect to run-time. |
|
|
|
@cindex state-smart words are a bad idea |
|
Some people try to use state-smart words to emulate the feature provided |
|
by @code{interpret/compile:} (words are state-smart if they check |
|
@code{STATE} during execution). E.g., they would try to code |
|
@code{foobar} like this: |
|
|
|
@example |
|
: foobar |
|
STATE @@ |
|
IF ( compilation state ) |
|
POSTPONE foo POSTPONE bar |
|
ELSE |
|
foo bar |
|
ENDIF ; immediate |
|
@end example |
|
|
|
While this works if @code{foobar} is processed only by the text |
|
interpreter, it does not work in other contexts (like @code{'} or |
|
@code{POSTPONE}). E.g., @code{' foobar} will produce an execution token |
|
for a state-smart word, not for the interpretation semantics of the |
|
original @code{foobar}; when you execute this execution token (directly |
|
with @code{EXECUTE} or indirectly through @code{COMPILE,}) in compile |
|
state, the result will not be what you expected (i.e., it will not |
|
perform @code{foo bar}). State-smart words are a bad idea. Simply don't |
|
write them! |
|
|
|
@cindex defining words with arbitrary semantics combinations |
|
It is also possible to write defining words that define words with |
|
arbitrary combinations of interpretation and compilation semantics (or, |
|
preferably, arbitrary combinations of implementations of the default |
|
semantics). In general, this looks like: |
|
|
|
@example |
|
: def-word |
|
create-interpret/compile |
|
@var{code1} |
|
interpretation> |
|
@var{code2} |
|
<interpretation |
|
compilation> |
|
@var{code3} |
|
<compilation ; |
|
@end example |
|
|
|
For a @var{word} defined with @code{def-word}, the interpretation |
|
semantics are to push the address of the body of @var{word} and perform |
|
@var{code2}, and the compilation semantics are to push the address of |
|
the body of @var{word} and perform @var{code3}. E.g., @code{constant} |
|
can also be defined like this: |
|
|
|
@example |
|
: constant ( n "name" -- ) |
|
create-interpret/compile |
|
, |
|
interpretation> ( -- n ) |
|
@@ |
|
<interpretation |
|
compilation> ( compilation. -- ; run-time. -- n ) |
|
@@ postpone literal |
|
<compilation ; |
|
@end example |
|
|
|
doc-create-interpret/compile |
|
doc-interpretation> |
|
doc-<interpretation |
|
doc-compilation> |
|
doc-<compilation |
|
|
|
Note that words defined with @code{interpret/compile:} and |
|
@code{create-interpret/compile} have an extended header structure that |
|
differs from other words; however, unless you try to access them with |
|
plain address arithmetic, you should not notice this. Words for |
|
accessing the header structure usually know how to deal with this; e.g., |
|
@code{' word >body} also gives you the body of a word created with |
|
@code{create-interpret/compile}. |
|
|
|
@node Tokens for Words, Wordlists, Defining Words, Words |
|
@section Tokens for Words |
|
@cindex tokens for words |
|
|
|
This chapter describes the creation and use of tokens that represent |
|
words on the stack (and in data space). |
|
|
|
Named words have interpretation and compilation semantics. Unnamed words |
|
just have execution semantics. |
|
|
|
@cindex execution token |
|
An @dfn{execution token} represents the execution semantics of an |
|
unnamed word. An execution token occupies one cell. As explained in |
|
section @ref{Supplying names}, the execution token of the last words |
|
defined can be produced with |
|
|
|
short-lastxt |
|
|
|
You can perform the semantics represented by an execution token with |
|
doc-execute |
|
You can compile the word with |
|
doc-compile, |
|
|
|
@cindex code field address |
|
@cindex CFA |
|
In Gforth, the abstract data type @emph{execution token} is implemented |
|
as CFA (code field address). |
|
|
|
The interpretation semantics of a named word are also represented by an |
|
execution token. You can get it with |
|
|
|
doc-['] |
|
doc-' |
|
|
|
For literals, you use @code{'} in interpreted code and @code{[']} in |
|
compiled code. Gforth's @code{'} and @code{[']} behave somewhat unusual |
|
by complaining about compile-only words. To get an execution token for a |
|
compiling word @var{X}, use @code{COMP' @var{X} drop} or @code{[COMP'] |
|
@var{X} drop}. |
|
|
|
@cindex compilation token |
|
The compilation semantics are represented by a @dfn{compilation token} |
|
consisting of two cells: @var{w xt}. The top cell @var{xt} is an |
|
execution token. The compilation semantics represented by the |
|
compilation token can be performed with @code{execute}, which consumes |
|
the whole compilation token, with an additional stack effect determined |
|
by the represented compilation semantics. |
|
|
|
doc-[comp'] |
|
doc-comp' |
|
|
|
You can compile the compilation semantics with @code{postpone,}. I.e., |
|
@code{COMP' @var{word} POSTPONE,} is equivalent to @code{POSTPONE |
|
@var{word}}. |
|
|
|
doc-postpone, |
|
|
|
At present, the @var{w} part of a compilation token is an execution |
|
token, and the @var{xt} part represents either @code{execute} or |
|
@code{compile,}. However, don't rely on that knowledge, unless necessary; |
|
we may introduce unusual compilation tokens in the future (e.g., |
|
compilation tokens representing the compilation semantics of literals). |
|
|
|
@cindex name token |
|
@cindex name field address |
|
@cindex NFA |
|
Named words are also represented by the @dfn{name token}. The abstract |
|
data type @emph{name token} is implemented as NFA (name field address). |
|
|
|
doc-find-name |
|
doc-name>int |
|
doc-name?int |
|
doc-name>comp |
|
doc-name>string |
|
|
|
@node Wordlists, Files, Tokens for Words, Words |
@section Wordlists |
@section Wordlists |
|
|
@node Files, Blocks, Wordlists, Words |
@node Files, Blocks, Wordlists, Words |
Line 1983 locals wordset.
|
Line 2669 locals wordset.
|
|
|
@node Programming Tools, Assembler and Code words, Other I/O, Words |
@node Programming Tools, Assembler and Code words, Other I/O, Words |
@section Programming Tools |
@section Programming Tools |
|
@cindex programming tools |
|
|
@menu |
@menu |
* Debugging:: Simple and quick. |
* Debugging:: Simple and quick. |
Line 1991 locals wordset.
|
Line 2678 locals wordset.
|
|
|
@node Debugging, Assertions, Programming Tools, Programming Tools |
@node Debugging, Assertions, Programming Tools, Programming Tools |
@subsection Debugging |
@subsection Debugging |
|
@cindex debugging |
|
|
The simple debugging aids provided in @file{debugging.fs} |
The simple debugging aids provided in @file{debugging.fs} |
are meant to support a different style of debugging than the |
are meant to support a different style of debugging than the |
tracing/stepping debuggers used in languages with long turn-around |
tracing/stepping debuggers used in languages with long turn-around |
times. |
times. |
|
|
A much better (faster) way in fast-compilig languages is to add |
A much better (faster) way in fast-compiling languages is to add |
printing code at well-selected places, let the program run, look at |
printing code at well-selected places, let the program run, look at |
the output, see where things went wrong, add more printing code, etc., |
the output, see where things went wrong, add more printing code, etc., |
until the bug is found. |
until the bug is found. |
Line 2023 doc-printdebugline
|
Line 2711 doc-printdebugline
|
|
|
@node Assertions, , Debugging, Programming Tools |
@node Assertions, , Debugging, Programming Tools |
@subsection Assertions |
@subsection Assertions |
|
@cindex assertions |
|
|
It is a good idea to make your programs self-checking, in particular, if |
It is a good idea to make your programs self-checking, in particular, if |
you use an assumption (e.g., that a certain field of a data structure is |
you use an assumption (e.g., that a certain field of a data structure is |
Line 2082 probably more appropriate than an assert
|
Line 2771 probably more appropriate than an assert
|
|
|
@node Assembler and Code words, Threading Words, Programming Tools, Words |
@node Assembler and Code words, Threading Words, Programming Tools, Words |
@section Assembler and Code words |
@section Assembler and Code words |
|
@cindex assembler |
|
@cindex code words |
|
|
Gforth provides some words for defining primitives (words written in |
Gforth provides some words for defining primitives (words written in |
machine code), and for defining the the machine-code equivalent of |
machine code), and for defining the the machine-code equivalent of |
@code{DOES>}-based defining words. However, the machine-independent |
@code{DOES>}-based defining words. However, the machine-independent |
nature of Gforth poses a few problems: First of all. Gforth runs on |
nature of Gforth poses a few problems: First of all, Gforth runs on |
several architectures, so it can provide no standard assembler. What's |
several architectures, so it can provide no standard assembler. What's |
worse is that the register allocation not only depends on the processor, |
worse is that the register allocation not only depends on the processor, |
but also on the @code{gcc} version and options used. |
but also on the @code{gcc} version and options used. |
Line 2109 These words are rarely used. Therefore t
|
Line 2800 These words are rarely used. Therefore t
|
which is usually not loaded (except @code{flush-icache}, which is always |
which is usually not loaded (except @code{flush-icache}, which is always |
present). You can load them with @code{require code.fs}. |
present). You can load them with @code{require code.fs}. |
|
|
|
@cindex registers of the inner interpreter |
In the assembly code you will want to refer to the inner interpreter's |
In the assembly code you will want to refer to the inner interpreter's |
registers (e.g., the data stack pointer) and you may want to use other |
registers (e.g., the data stack pointer) and you may want to use other |
registers for temporary storage. Unfortunately, the register allocation |
registers for temporary storage. Unfortunately, the register allocation |
Line 2141 actual register allocation. E.g., if the
|
Line 2833 actual register allocation. E.g., if the
|
register @code{$17}, create an alias for this register called @code{sp}, |
register @code{$17}, create an alias for this register called @code{sp}, |
and use that in your assembly code. |
and use that in your assembly code. |
|
|
|
@cindex code words, portable |
Another option for implementing normal and defining words efficiently |
Another option for implementing normal and defining words efficiently |
is: adding the wanted functionality to the source of Gforth. For normal |
is: adding the wanted functionality to the source of Gforth. For normal |
words you just have to edit @file{primitives}, defining words (for fast |
words you just have to edit @file{primitives} (@pxref{Automatic |
defined words) may require changes in @file{engine.c}, |
Generation}), defining words (equivalent to @code{;CODE} words, for fast |
@file{kernal.fs}, @file{prims2x.fs}, and possibly @file{cross.fs}. |
defined words) may require changes in @file{engine.c}, @file{kernal.fs}, |
|
@file{prims2x.fs}, and possibly @file{cross.fs}. |
|
|
|
|
@node Threading Words, , Assembler and Code words, Words |
@node Threading Words, , Assembler and Code words, Words |
@section Threading Words |
@section Threading Words |
|
@cindex threading words |
|
|
|
@cindex code address |
These words provide access to code addresses and other threading stuff |
These words provide access to code addresses and other threading stuff |
in Gforth (and, possibly, other interpretive Forths). It more or less |
in Gforth (and, possibly, other interpretive Forths). It more or less |
abstracts away the differences between direct and indirect threading |
abstracts away the differences between direct and indirect threading |
(and, for direct threading, the machine dependences). However, at |
(and, for direct threading, the machine dependences). However, at |
present this wordset is still inclomplete. It is also pretty low-level; |
present this wordset is still incomplete. It is also pretty low-level; |
some day it will hopefully be made unnecessary by an internals words set |
some day it will hopefully be made unnecessary by an internals wordset |
that abstracts implementation details away completely. |
that abstracts implementation details away completely. |
|
|
doc->code-address |
doc->code-address |
Line 2176 doc-douser:
|
Line 2872 doc-douser:
|
doc-dodefer: |
doc-dodefer: |
doc-dofield: |
doc-dofield: |
|
|
Currently there is no installation-independent way for recogizing words |
You can recognize words defined by a @code{CREATE}...@code{DOES>} word |
defined by a @code{CREATE}...@code{DOES>} word; however, once you know |
with @code{>DOES-CODE}. If the word was defined in that way, the value |
that a word is defined by a @code{CREATE}...@code{DOES>} word, you can |
returned is different from 0 and identifies the @code{DOES>} used by the |
use @code{>DOES-CODE}. |
defining word. |
|
|
@node ANS conformance, Model, Words, Top |
@node Tools, ANS conformance, Words, Top |
|
@chapter Tools |
|
|
|
@menu |
|
* ANS Report:: Report the words used, sorted by wordset. |
|
@end menu |
|
|
|
See also @ref{Emacs and Gforth}. |
|
|
|
@node ANS Report, , Tools, Tools |
|
@section @file{ans-report.fs}: Report the words used, sorted by wordset |
|
@cindex @file{ans-report.fs} |
|
@cindex report the words used in your program |
|
@cindex words used in your program |
|
|
|
If you want to label a Forth program as ANS Forth Program, you must |
|
document which wordsets the program uses; for extension wordsets, it is |
|
helpful to list the words the program requires from these wordsets |
|
(because Forth systems are allowed to provide only some words of them). |
|
|
|
The @file{ans-report.fs} tool makes it easy for you to determine which |
|
words from which wordset and which non-ANS words your application |
|
uses. You simply have to include @file{ans-report.fs} before loading the |
|
program you want to check. After loading your program, you can get the |
|
report with @code{print-ans-report}. A typical use is to run this as |
|
batch job like this: |
|
@example |
|
gforth ans-report.fs myprog.fs -e "print-ans-report bye" |
|
@end example |
|
|
|
The output looks like this (for @file{compat/control.fs}): |
|
@example |
|
The program uses the following words |
|
from CORE : |
|
: POSTPONE THEN ; immediate ?dup IF 0= |
|
from BLOCK-EXT : |
|
\ |
|
from FILE : |
|
( |
|
@end example |
|
|
|
@subsection Caveats |
|
|
|
Note that @file{ans-report.fs} just checks which words are used, not whether |
|
they are used in an ANS Forth conforming way! |
|
|
|
Some words are defined in several wordsets in the |
|
standard. @file{ans-report.fs} reports them for only one of the |
|
wordsets, and not necessarily the one you expect. It depends on usage |
|
which wordset is the right one to specify. E.g., if you only use the |
|
compilation semantics of @code{S"}, it is a Core word; if you also use |
|
its interpretation semantics, it is a File word. |
|
|
|
@c ****************************************************************** |
|
@node ANS conformance, Model, Tools, Top |
@chapter ANS conformance |
@chapter ANS conformance |
|
@cindex ANS conformance of Gforth |
|
|
To the best of our knowledge, Gforth is an |
To the best of our knowledge, Gforth is an |
|
|
ANS Forth System |
ANS Forth System |
@itemize |
@itemize @bullet |
@item providing the Core Extensions word set |
@item providing the Core Extensions word set |
@item providing the Block word set |
@item providing the Block word set |
@item providing the Block Extensions word set |
@item providing the Block Extensions word set |
Line 2206 ANS Forth System
|
Line 2957 ANS Forth System
|
@item providing the Memory-Allocation word set |
@item providing the Memory-Allocation word set |
@item providing the Memory-Allocation Extensions word set (that one's easy) |
@item providing the Memory-Allocation Extensions word set (that one's easy) |
@item providing the Programming-Tools word set |
@item providing the Programming-Tools word set |
@item providing @code{;code}, @code{AHEAD}, @code{ASSEMBLER}, @code{BYE}, @code{CODE}, @code{CS-PICK}, @code{CS-ROLL}, @code{STATE}, @code{[ELSE]}, @code{[IF]}, @code{[THEN]} from the Programming-Tools Extensions word set |
@item providing @code{;CODE}, @code{AHEAD}, @code{ASSEMBLER}, @code{BYE}, @code{CODE}, @code{CS-PICK}, @code{CS-ROLL}, @code{STATE}, @code{[ELSE]}, @code{[IF]}, @code{[THEN]} from the Programming-Tools Extensions word set |
@item providing the Search-Order word set |
@item providing the Search-Order word set |
@item providing the Search-Order Extensions word set |
@item providing the Search-Order Extensions word set |
@item providing the String word set |
@item providing the String word set |
@item providing the String Extensions word set (another easy one) |
@item providing the String Extensions word set (another easy one) |
@end itemize |
@end itemize |
|
|
|
@cindex system documentation |
In addition, ANS Forth systems are required to document certain |
In addition, ANS Forth systems are required to document certain |
implementation choices. This chapter tries to meet these |
implementation choices. This chapter tries to meet these |
requirements. In many cases it gives a way to ask the system for the |
requirements. In many cases it gives a way to ask the system for the |
Line 2243 change during the maintenance of Gforth.
|
Line 2995 change during the maintenance of Gforth.
|
@comment node-name, next, previous, up |
@comment node-name, next, previous, up |
@section The Core Words |
@section The Core Words |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex core words, system documentation |
|
@cindex system documentation, core words |
|
|
@menu |
@menu |
* core-idef:: Implementation Defined Options |
* core-idef:: Implementation Defined Options |
Line 2254 change during the maintenance of Gforth.
|
Line 3008 change during the maintenance of Gforth.
|
@node core-idef, core-ambcond, The Core Words, The Core Words |
@node core-idef, core-ambcond, The Core Words, The Core Words |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex core words, implementation-defined options |
|
@cindex implementation-defined options, core words |
|
|
@table @i |
|
|
|
|
@table @i |
@item (Cell) aligned addresses: |
@item (Cell) aligned addresses: |
|
@cindex cell-aligned addresses |
|
@cindex aligned addresses |
processor-dependent. Gforth's alignment words perform natural alignment |
processor-dependent. Gforth's alignment words perform natural alignment |
(e.g., an address aligned for a datum of size 8 is divisible by |
(e.g., an address aligned for a datum of size 8 is divisible by |
8). Unaligned accesses usually result in a @code{-23 THROW}. |
8). Unaligned accesses usually result in a @code{-23 THROW}. |
|
|
@item @code{EMIT} and non-graphic characters: |
@item @code{EMIT} and non-graphic characters: |
|
@cindex @code{EMIT} and non-graphic characters |
|
@cindex non-graphic characters and @code{EMIT} |
The character is output using the C library function (actually, macro) |
The character is output using the C library function (actually, macro) |
@code{putchar}. |
@code{putc}. |
|
|
@item character editing of @code{ACCEPT} and @code{EXPECT}: |
@item character editing of @code{ACCEPT} and @code{EXPECT}: |
|
@cindex character editing of @code{ACCEPT} and @code{EXPECT} |
|
@cindex editing in @code{ACCEPT} and @code{EXPECT} |
|
@cindex @code{ACCEPT}, editing |
|
@cindex @code{EXPECT}, editing |
This is modeled on the GNU readline library (@pxref{Readline |
This is modeled on the GNU readline library (@pxref{Readline |
Interaction, , Command Line Editing, readline, The GNU Readline |
Interaction, , Command Line Editing, readline, The GNU Readline |
Library}) with Emacs-like key bindings. @kbd{Tab} deviates a little by |
Library}) with Emacs-like key bindings. @kbd{Tab} deviates a little by |
Line 2274 producing a full word completion every t
|
Line 3038 producing a full word completion every t
|
producing the common prefix of all completions). |
producing the common prefix of all completions). |
|
|
@item character set: |
@item character set: |
|
@cindex character set |
The character set of your computer and display device. Gforth is |
The character set of your computer and display device. Gforth is |
8-bit-clean (but some other component in your system may make trouble). |
8-bit-clean (but some other component in your system may make trouble). |
|
|
@item Character-aligned address requirements: |
@item Character-aligned address requirements: |
|
@cindex character-aligned address requirements |
installation-dependent. Currently a character is represented by a C |
installation-dependent. Currently a character is represented by a C |
@code{unsigned char}; in the future we might switch to @code{wchar_t} |
@code{unsigned char}; in the future we might switch to @code{wchar_t} |
(Comments on that requested). |
(Comments on that requested). |
|
|
@item character-set extensions and matching of names: |
@item character-set extensions and matching of names: |
|
@cindex character-set extensions and matching of names |
|
@cindex case sensitivity for name lookup |
|
@cindex name lookup, case sensitivity |
|
@cindex locale and case sensitivity |
Any character except the ASCII NUL charcter can be used in a |
Any character except the ASCII NUL charcter can be used in a |
name. Matching is case-insensitive. The matching is performed using the |
name. Matching is case-insensitive (except in @code{TABLE}s). The |
C function @code{strncasecmp}, whose function is probably influenced by |
matching is performed using the C function @code{strncasecmp}, whose |
the locale. E.g., the @code{C} locale does not know about accents and |
function is probably influenced by the locale. E.g., the @code{C} locale |
umlauts, so they are matched case-sensitively in that locale. For |
does not know about accents and umlauts, so they are matched |
portability reasons it is best to write programs such that they work in |
case-sensitively in that locale. For portability reasons it is best to |
the @code{C} locale. Then one can use libraries written by a Polish |
write programs such that they work in the @code{C} locale. Then one can |
programmer (who might use words containing ISO Latin-2 encoded |
use libraries written by a Polish programmer (who might use words |
characters) and by a French programmer (ISO Latin-1) in the same program |
containing ISO Latin-2 encoded characters) and by a French programmer |
(of course, @code{WORDS} will produce funny results for some of the |
(ISO Latin-1) in the same program (of course, @code{WORDS} will produce |
words (which ones, depends on the font you are using)). Also, the locale |
funny results for some of the words (which ones, depends on the font you |
you prefer may not be available in other operating systems. Hopefully, |
are using)). Also, the locale you prefer may not be available in other |
Unicode will solve these problems one day. |
operating systems. Hopefully, Unicode will solve these problems one day. |
|
|
@item conditions under which control characters match a space delimiter: |
@item conditions under which control characters match a space delimiter: |
|
@cindex space delimiters |
|
@cindex control characters as delimiters |
If @code{WORD} is called with the space character as a delimiter, all |
If @code{WORD} is called with the space character as a delimiter, all |
white-space characters (as identified by the C macro @code{isspace()}) |
white-space characters (as identified by the C macro @code{isspace()}) |
are delimiters. @code{PARSE}, on the other hand, treats space like other |
are delimiters. @code{PARSE}, on the other hand, treats space like other |
Line 2307 interpreter (aka text interpreter) by de
|
Line 3079 interpreter (aka text interpreter) by de
|
characters as delimiters. |
characters as delimiters. |
|
|
@item format of the control flow stack: |
@item format of the control flow stack: |
|
@cindex control flow stack, format |
The data stack is used as control flow stack. The size of a control flow |
The data stack is used as control flow stack. The size of a control flow |
stack item in cells is given by the constant @code{cs-item-size}. At the |
stack item in cells is given by the constant @code{cs-item-size}. At the |
time of this writing, an item consists of a (pointer to a) locals list |
time of this writing, an item consists of a (pointer to a) locals list |
Line 2316 item (TOS). The following tags are used:
|
Line 3089 item (TOS). The following tags are used:
|
@code{scopestart}. |
@code{scopestart}. |
|
|
@item conversion of digits > 35 |
@item conversion of digits > 35 |
|
@cindex digits > 35 |
The characters @code{[\]^_'} are the digits with the decimal value |
The characters @code{[\]^_'} are the digits with the decimal value |
36@minus{}41. There is no way to input many of the larger digits. |
36@minus{}41. There is no way to input many of the larger digits. |
|
|
@item display after input terminates in @code{ACCEPT} and @code{EXPECT}: |
@item display after input terminates in @code{ACCEPT} and @code{EXPECT}: |
|
@cindex @code{EXPECT}, display after end of input |
|
@cindex @code{ACCEPT}, display after end of input |
The cursor is moved to the end of the entered string. If the input is |
The cursor is moved to the end of the entered string. If the input is |
terminated using the @kbd{Return} key, a space is typed. |
terminated using the @kbd{Return} key, a space is typed. |
|
|
@item exception abort sequence of @code{ABORT"}: |
@item exception abort sequence of @code{ABORT"}: |
|
@cindex exception abort sequence of @code{ABORT"} |
|
@cindex @code{ABORT"}, exception abort sequence |
The error string is stored into the variable @code{"error} and a |
The error string is stored into the variable @code{"error} and a |
@code{-2 throw} is performed. |
@code{-2 throw} is performed. |
|
|
@item input line terminator: |
@item input line terminator: |
For interactive input, @kbd{C-m} and @kbd{C-j} terminate lines. One of |
@cindex input line terminator |
these characters is typically produced when you type the @kbd{Enter} or |
@cindex line terminator on input |
@kbd{Return} key. |
@cindex newline charcter on input |
|
For interactive input, @kbd{C-m} (CR) and @kbd{C-j} (LF) terminate |
|
lines. One of these characters is typically produced when you type the |
|
@kbd{Enter} or @kbd{Return} key. |
|
|
@item maximum size of a counted string: |
@item maximum size of a counted string: |
|
@cindex maximum size of a counted string |
|
@cindex counted string, maximum size |
@code{s" /counted-string" environment? drop .}. Currently 255 characters |
@code{s" /counted-string" environment? drop .}. Currently 255 characters |
on all ports, but this may change. |
on all ports, but this may change. |
|
|
@item maximum size of a parsed string: |
@item maximum size of a parsed string: |
|
@cindex maximum size of a parsed string |
|
@cindex parsed string, maximum size |
Given by the constant @code{/line}. Currently 255 characters. |
Given by the constant @code{/line}. Currently 255 characters. |
|
|
@item maximum size of a definition name, in characters: |
@item maximum size of a definition name, in characters: |
|
@cindex maximum size of a definition name, in characters |
|
@cindex name, maximum length |
31 |
31 |
|
|
@item maximum string length for @code{ENVIRONMENT?}, in characters: |
@item maximum string length for @code{ENVIRONMENT?}, in characters: |
|
@cindex maximum string length for @code{ENVIRONMENT?}, in characters |
|
@cindex @code{ENVIRONMENT?} string length, maximum |
31 |
31 |
|
|
@item method of selecting the user input device: |
@item method of selecting the user input device: |
|
@cindex user input device, method of selecting |
The user input device is the standard input. There is currently no way to |
The user input device is the standard input. There is currently no way to |
change it from within Gforth. However, the input can typically be |
change it from within Gforth. However, the input can typically be |
redirected in the command line that starts Gforth. |
redirected in the command line that starts Gforth. |
|
|
@item method of selecting the user output device: |
@item method of selecting the user output device: |
The user output device is the standard output. It cannot be redirected |
@cindex user output device, method of selecting |
from within Gforth, but typically from the command line that starts |
@code{EMIT} and @code{TYPE} output to the file-id stored in the value |
Gforth. Gforth uses buffered output, so output on a terminal does not |
@code{outfile-id} (@code{stdout} by default). Gforth uses buffered |
become visible before the next newline or buffer overflow. Output on |
output, so output on a terminal does not become visible before the next |
non-terminals is invisible until the buffer overflows. |
newline or buffer overflow. Output on non-terminals is invisible until |
|
the buffer overflows. |
|
|
@item methods of dictionary compilation: |
@item methods of dictionary compilation: |
What are we expected to document here? |
What are we expected to document here? |
|
|
@item number of bits in one address unit: |
@item number of bits in one address unit: |
|
@cindex number of bits in one address unit |
|
@cindex address unit, size in bits |
@code{s" address-units-bits" environment? drop .}. 8 in all current |
@code{s" address-units-bits" environment? drop .}. 8 in all current |
ports. |
ports. |
|
|
@item number representation and arithmetic: |
@item number representation and arithmetic: |
|
@cindex number representation and arithmetic |
Processor-dependent. Binary two's complement on all current ports. |
Processor-dependent. Binary two's complement on all current ports. |
|
|
@item ranges for integer types: |
@item ranges for integer types: |
|
@cindex ranges for integer types |
|
@cindex integer types, ranges |
Installation-dependent. Make environmental queries for @code{MAX-N}, |
Installation-dependent. Make environmental queries for @code{MAX-N}, |
@code{MAX-U}, @code{MAX-D} and @code{MAX-UD}. The lower bounds for |
@code{MAX-U}, @code{MAX-D} and @code{MAX-UD}. The lower bounds for |
unsigned (and positive) types is 0. The lower bound for signed types on |
unsigned (and positive) types is 0. The lower bound for signed types on |
Line 2375 two's complement and one's complement ma
|
Line 3171 two's complement and one's complement ma
|
by adding 1 to the upper bound. |
by adding 1 to the upper bound. |
|
|
@item read-only data space regions: |
@item read-only data space regions: |
|
@cindex read-only data space regions |
|
@cindex data-space, read-only regions |
The whole Forth data space is writable. |
The whole Forth data space is writable. |
|
|
@item size of buffer at @code{WORD}: |
@item size of buffer at @code{WORD}: |
|
@cindex size of buffer at @code{WORD} |
|
@cindex @code{WORD} buffer size |
@code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is |
@code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is |
shared with the pictured numeric output string. If overwriting |
shared with the pictured numeric output string. If overwriting |
@code{PAD} is acceptable, it is as large as the remaining dictionary |
@code{PAD} is acceptable, it is as large as the remaining dictionary |
Line 2385 space, although only as much can be sens
|
Line 3185 space, although only as much can be sens
|
string. |
string. |
|
|
@item size of one cell in address units: |
@item size of one cell in address units: |
|
@cindex cell size |
@code{1 cells .}. |
@code{1 cells .}. |
|
|
@item size of one character in address units: |
@item size of one character in address units: |
|
@cindex char size |
@code{1 chars .}. 1 on all current ports. |
@code{1 chars .}. 1 on all current ports. |
|
|
@item size of the keyboard terminal buffer: |
@item size of the keyboard terminal buffer: |
Varies. You can determine the size at a specific time using @code{lp@ |
@cindex size of the keyboard terminal buffer |
|
@cindex terminal buffer, size |
|
Varies. You can determine the size at a specific time using @code{lp@@ |
tib - .}. It is shared with the locals stack and TIBs of files that |
tib - .}. It is shared with the locals stack and TIBs of files that |
include the current file. You can change the amount of space for TIBs |
include the current file. You can change the amount of space for TIBs |
and locals stack at Gforth startup with the command line option |
and locals stack at Gforth startup with the command line option |
@code{-l}. |
@code{-l}. |
|
|
@item size of the pictured numeric output buffer: |
@item size of the pictured numeric output buffer: |
|
@cindex size of the pictured numeric output buffer |
|
@cindex pictured numeric output buffer, size |
@code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is |
@code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is |
shared with @code{WORD}. |
shared with @code{WORD}. |
|
|
@item size of the scratch area returned by @code{PAD}: |
@item size of the scratch area returned by @code{PAD}: |
The remainder of dictionary space. You can even use the unused part of |
@cindex size of the scratch area returned by @code{PAD} |
the data stack space. The current size can be computed with @code{sp@ |
@cindex @code{PAD} size |
pad - .}. |
The remainder of dictionary space. @code{unused pad here - - .}. |
|
|
@item system case-sensitivity characteristics: |
@item system case-sensitivity characteristics: |
Dictionary searches are case insensitive. However, as explained above |
@cindex case-sensitivity characteristics |
under @i{character-set extensions}, the matching for non-ASCII |
Dictionary searches are case insensitive (except in |
characters is determined by the locale you are using. In the default |
@code{TABLE}s). However, as explained above under @i{character-set |
@code{C} locale all non-ASCII characters are matched case-sensitively. |
extensions}, the matching for non-ASCII characters is determined by the |
|
locale you are using. In the default @code{C} locale all non-ASCII |
|
characters are matched case-sensitively. |
|
|
@item system prompt: |
@item system prompt: |
|
@cindex system prompt |
|
@cindex prompt |
@code{ ok} in interpret state, @code{ compiled} in compile state. |
@code{ ok} in interpret state, @code{ compiled} in compile state. |
|
|
@item division rounding: |
@item division rounding: |
|
@cindex division rounding |
installation dependent. @code{s" floored" environment? drop .}. We leave |
installation dependent. @code{s" floored" environment? drop .}. We leave |
the choice to @code{gcc} (what to use for @code{/}) and to you (whether to use |
the choice to @code{gcc} (what to use for @code{/}) and to you (whether |
@code{fm/mod}, @code{sm/rem} or simply @code{/}). |
to use @code{fm/mod}, @code{sm/rem} or simply @code{/}). |
|
|
@item values of @code{STATE} when true: |
@item values of @code{STATE} when true: |
|
@cindex @code{STATE} values |
-1. |
-1. |
|
|
@item values returned after arithmetic overflow: |
@item values returned after arithmetic overflow: |
On two's complement machines, arithmetic is performed modulo |
On two's complement machines, arithmetic is performed modulo |
2**bits-per-cell for single arithmetic and 4**bits-per-cell for double |
2**bits-per-cell for single arithmetic and 4**bits-per-cell for double |
arithmetic (with appropriate mapping for signed types). Division by zero |
arithmetic (with appropriate mapping for signed types). Division by zero |
typically results in a @code{-55 throw} (floatingpoint unidentified |
typically results in a @code{-55 throw} (Floating-point unidentified |
fault), although a @code{-10 throw} (divide by zero) would be more |
fault), although a @code{-10 throw} (divide by zero) would be more |
appropriate. |
appropriate. |
|
|
@item whether the current definition can be found after @t{DOES>}: |
@item whether the current definition can be found after @t{DOES>}: |
|
@cindex @t{DOES>}, visibility of current definition |
No. |
No. |
|
|
@end table |
@end table |
Line 2440 No.
|
Line 3253 No.
|
@node core-ambcond, core-other, core-idef, The Core Words |
@node core-ambcond, core-other, core-idef, The Core Words |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex core words, ambiguous conditions |
|
@cindex ambiguous conditions, core words |
|
|
@table @i |
@table @i |
|
|
@item a name is neither a word nor a number: |
@item a name is neither a word nor a number: |
@code{-13 throw} (Undefined word) |
@cindex name not found |
|
@cindex Undefined word |
|
@code{-13 throw} (Undefined word). Actually, @code{-13 bounce}, which |
|
preserves the data and FP stack, so you don't lose more work than |
|
necessary. |
|
|
@item a definition name exceeds the maximum length allowed: |
@item a definition name exceeds the maximum length allowed: |
|
@cindex Word name too long |
@code{-19 throw} (Word name too long) |
@code{-19 throw} (Word name too long) |
|
|
@item addressing a region not inside the various data spaces of the forth system: |
@item addressing a region not inside the various data spaces of the forth system: |
|
@cindex Invalid memory address |
The stacks, code space and name space are accessible. Machine code space is |
The stacks, code space and name space are accessible. Machine code space is |
typically readable. Accessing other addresses gives results dependent on |
typically readable. Accessing other addresses gives results dependent on |
the operating system. On decent systems: @code{-9 throw} (Invalid memory |
the operating system. On decent systems: @code{-9 throw} (Invalid memory |
address). |
address). |
|
|
@item argument type incompatible with parameter: |
@item argument type incompatible with parameter: |
|
@cindex Argument type mismatch |
This is usually not caught. Some words perform checks, e.g., the control |
This is usually not caught. Some words perform checks, e.g., the control |
flow words, and issue a @code{ABORT"} or @code{-12 THROW} (Argument type |
flow words, and issue a @code{ABORT"} or @code{-12 THROW} (Argument type |
mismatch). |
mismatch). |
|
|
@item attempting to obtain the execution token of a word with undefined execution semantics: |
@item attempting to obtain the execution token of a word with undefined execution semantics: |
You get an execution token representing the compilation semantics |
@cindex Interpreting a compile-only word, for @code{'} etc. |
instead. |
@cindex execution token of words with undefined execution semantics |
|
@code{-14 throw} (Interpreting a compile-only word). In some cases, you |
|
get an execution token for @code{compile-only-error} (which performs a |
|
@code{-14 throw} when executed). |
|
|
@item dividing by zero: |
@item dividing by zero: |
|
@cindex dividing by zero |
|
@cindex floating point unidentified fault, integer division |
|
@cindex divide by zero |
typically results in a @code{-55 throw} (floating point unidentified |
typically results in a @code{-55 throw} (floating point unidentified |
fault), although a @code{-10 throw} (divide by zero) would be more |
fault), although a @code{-10 throw} (divide by zero) would be more |
appropriate. |
appropriate. |
|
|
@item insufficient data stack or return stack space: |
@item insufficient data stack or return stack space: |
Not checked. This typically results in mysterious illegal memory |
@cindex insufficient data stack or return stack space |
accesses, producing @code{-9 throw} (Invalid memory address) or |
@cindex stack overflow |
@code{-23 throw} (Address alignment exception). |
@cindex Address alignment exception, stack overflow |
|
@cindex Invalid memory address, stack overflow |
|
Depending on the operating system, the installation, and the invocation |
|
of Gforth, this is either checked by the memory management hardware, or |
|
it is not checked. If it is checked, you typically get a @code{-9 throw} |
|
(Invalid memory address) as soon as the overflow happens. If it is not |
|
check, overflows typically result in mysterious illegal memory accesses, |
|
producing @code{-9 throw} (Invalid memory address) or @code{-23 throw} |
|
(Address alignment exception); they might also destroy the internal data |
|
structure of @code{ALLOCATE} and friends, resulting in various errors in |
|
these words. |
|
|
@item insufficient space for loop control parameters: |
@item insufficient space for loop control parameters: |
|
@cindex insufficient space for loop control parameters |
like other return stack overflows. |
like other return stack overflows. |
|
|
@item insufficient space in the dictionary: |
@item insufficient space in the dictionary: |
Not checked. Similar results as stack overflows. However, typically the |
@cindex insufficient space in the dictionary |
error appears at a different place when one inserts or removes code. |
@cindex dictionary overflow |
|
Depending on the operating system, the installation, and the invocation |
|
of Gforth, this is either checked by the memory management hardware, or |
|
it is not checked. Similar results as stack overflows. However, |
|
typically the error appears at a different place when one inserts or |
|
removes code. Also, the @code{THROW} does not relieve the situation (it |
|
does for stack overflows). |
|
|
@item interpreting a word with undefined interpretation semantics: |
@item interpreting a word with undefined interpretation semantics: |
For some words, we defined interpretation semantics. For the others: |
@cindex interpreting a word with undefined interpretation semantics |
@code{-14 throw} (Interpreting a compile-only word). Note that this is |
@cindex Interpreting a compile-only word |
checked only by the outer (aka text) interpreter; if the word is |
For some words, we have defined interpretation semantics. For the |
@code{execute}d in some other way, it will typically perform it's |
others: @code{-14 throw} (Interpreting a compile-only word). |
compilation semantics even in interpret state. (We could change @code{'} |
|
and relatives not to give the xt of such words, but we think that would |
|
be too restrictive). |
|
|
|
@item modifying the contents of the input buffer or a string literal: |
@item modifying the contents of the input buffer or a string literal: |
|
@cindex modifying the contents of the input buffer or a string literal |
These are located in writable memory and can be modified. |
These are located in writable memory and can be modified. |
|
|
@item overflow of the pictured numeric output string: |
@item overflow of the pictured numeric output string: |
Not checked. |
@cindex overflow of the pictured numeric output string |
|
@cindex pictured numeric output string, overflow |
|
Not checked. Runs into the dictionary and destroys it (at least, |
|
partially). |
|
|
@item parsed string overflow: |
@item parsed string overflow: |
|
@cindex parsed string overflow |
@code{PARSE} cannot overflow. @code{WORD} does not check for overflow. |
@code{PARSE} cannot overflow. @code{WORD} does not check for overflow. |
|
|
@item producing a result out of range: |
@item producing a result out of range: |
|
@cindex result out of range |
On two's complement machines, arithmetic is performed modulo |
On two's complement machines, arithmetic is performed modulo |
2**bits-per-cell for single arithmetic and 4**bits-per-cell for double |
2**bits-per-cell for single arithmetic and 4**bits-per-cell for double |
arithmetic (with appropriate mapping for signed types). Division by zero |
arithmetic (with appropriate mapping for signed types). Division by zero |
Line 2509 appropriate. @code{convert} and @code{>n
|
Line 3357 appropriate. @code{convert} and @code{>n
|
silently. |
silently. |
|
|
@item reading from an empty data or return stack: |
@item reading from an empty data or return stack: |
|
@cindex stack empty |
|
@cindex stack underflow |
The data stack is checked by the outer (aka text) interpreter after |
The data stack is checked by the outer (aka text) interpreter after |
every word executed. If it has underflowed, a @code{-4 throw} (Stack |
every word executed. If it has underflowed, a @code{-4 throw} (Stack |
underflow) is performed. Apart from that, the stacks are not checked and |
underflow) is performed. Apart from that, stacks may be checked or not, |
underflows can result in similar behaviour as overflows (of adjacent |
depending on operating system, installation, and invocation. The |
stacks). |
consequences of stack underflows are similar to the consequences of |
|
stack overflows. Note that even if the system uses checking (through the |
@item unexepected end of the input buffer, resulting in an attempt to use a zero-length string as a name: |
MMU), your program may have to underflow by a significant number of |
|
stack items to trigger the reaction (the reason for this is that the |
|
MMU, and therefore the checking, works with a page-size granularity). |
|
|
|
@item unexpected end of the input buffer, resulting in an attempt to use a zero-length string as a name: |
|
@cindex unexpected end of the input buffer |
|
@cindex zero-length string as a name |
|
@cindex Attempt to use zero-length string as a name |
@code{Create} and its descendants perform a @code{-16 throw} (Attempt to |
@code{Create} and its descendants perform a @code{-16 throw} (Attempt to |
use zero-length string as a name). Words like @code{'} probably will not |
use zero-length string as a name). Words like @code{'} probably will not |
find what they search. Note that it is possible to create zero-length |
find what they search. Note that it is possible to create zero-length |
names with @code{nextname} (should it not?). |
names with @code{nextname} (should it not?). |
|
|
@item @code{>IN} greater than input buffer: |
@item @code{>IN} greater than input buffer: |
The next invocation of a parsing word returns a string wih length 0. |
@cindex @code{>IN} greater than input buffer |
|
The next invocation of a parsing word returns a string with length 0. |
|
|
@item @code{RECURSE} appears after @code{DOES>}: |
@item @code{RECURSE} appears after @code{DOES>}: |
Compiles a recursive call to the defining word not to the defined word. |
@cindex @code{RECURSE} appears after @code{DOES>} |
|
Compiles a recursive call to the defining word, not to the defined word. |
|
|
@item argument input source different than current input source for @code{RESTORE-INPUT}: |
@item argument input source different than current input source for @code{RESTORE-INPUT}: |
!!???If the argument input source is a valid input source then it gets |
@cindex argument input source different than current input source for @code{RESTORE-INPUT} |
restored. Otherwise causes @code{-12 THROW}, which, unless caught, issues |
@cindex Argument type mismatch, @code{RESTORE-INPUT} |
the message "argument type mismatch" and aborts. |
@cindex @code{RESTORE-INPUT}, Argument type mismatch |
|
@code{-12 THROW}. Note that, once an input file is closed (e.g., because |
|
the end of the file was reached), its source-id may be |
|
reused. Therefore, restoring an input source specification referencing a |
|
closed file may lead to unpredictable results instead of a @code{-12 |
|
THROW}. |
|
|
|
In the future, Gforth may be able to restore input source specifications |
|
from other than the current input source. |
|
|
@item data space containing definitions gets de-allocated: |
@item data space containing definitions gets de-allocated: |
Deallocation with @code{allot} is not checked. This typically resuls in |
@cindex data space containing definitions gets de-allocated |
|
Deallocation with @code{allot} is not checked. This typically results in |
memory access faults or execution of illegal instructions. |
memory access faults or execution of illegal instructions. |
|
|
@item data space read/write with incorrect alignment: |
@item data space read/write with incorrect alignment: |
|
@cindex data space read/write with incorrect alignment |
|
@cindex alignment faults |
|
@cindex Address alignment exception |
Processor-dependent. Typically results in a @code{-23 throw} (Address |
Processor-dependent. Typically results in a @code{-23 throw} (Address |
alignment exception). Under Linux on a 486 or later processor with |
alignment exception). Under Linux on a 486 or later processor with |
alignment turned on, incorrect alignment results in a @code{-9 throw} |
alignment turned on, incorrect alignment results in a @code{-9 throw} |
Line 2544 alignment turned on, incorrect alignment
|
Line 3415 alignment turned on, incorrect alignment
|
alignment restrictions that do not report them. |
alignment restrictions that do not report them. |
|
|
@item data space pointer not properly aligned, @code{,}, @code{C,}: |
@item data space pointer not properly aligned, @code{,}, @code{C,}: |
|
@cindex data space pointer not properly aligned, @code{,}, @code{C,} |
Like other alignment errors. |
Like other alignment errors. |
|
|
@item less than u+2 stack items (@code{PICK} and @code{ROLL}): |
@item less than u+2 stack items (@code{PICK} and @code{ROLL}): |
Not checked. May cause an illegal memory access. |
Like other stack underflows. |
|
|
@item loop control parameters not available: |
@item loop control parameters not available: |
|
@cindex loop control parameters not available |
Not checked. The counted loop words simply assume that the top of return |
Not checked. The counted loop words simply assume that the top of return |
stack items are loop control parameters and behave accordingly. |
stack items are loop control parameters and behave accordingly. |
|
|
@item most recent definition does not have a name (@code{IMMEDIATE}): |
@item most recent definition does not have a name (@code{IMMEDIATE}): |
|
@cindex most recent definition does not have a name (@code{IMMEDIATE}) |
|
@cindex last word was headerless |
@code{abort" last word was headerless"}. |
@code{abort" last word was headerless"}. |
|
|
@item name not defined by @code{VALUE} used by @code{TO}: |
@item name not defined by @code{VALUE} used by @code{TO}: |
@code{-32 throw} (Invalid name argument) |
@cindex name not defined by @code{VALUE} used by @code{TO} |
|
@cindex @code{TO} on non-@code{VALUE}s |
|
@cindex Invalid name argument, @code{TO} |
|
@code{-32 throw} (Invalid name argument) (unless name is a local or was |
|
defined by @code{CONSTANT}; in the latter case it just changes the constant). |
|
|
@item name not found (@code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]}): |
@item name not found (@code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]}): |
|
@cindex name not found (@code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]}) |
|
@cindex Undefined word, @code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]} |
@code{-13 throw} (Undefined word) |
@code{-13 throw} (Undefined word) |
|
|
@item parameters are not of the same type (@code{DO}, @code{?DO}, @code{WITHIN}): |
@item parameters are not of the same type (@code{DO}, @code{?DO}, @code{WITHIN}): |
|
@cindex parameters are not of the same type (@code{DO}, @code{?DO}, @code{WITHIN}) |
Gforth behaves as if they were of the same type. I.e., you can predict |
Gforth behaves as if they were of the same type. I.e., you can predict |
the behaviour by interpreting all parameters as, e.g., signed. |
the behaviour by interpreting all parameters as, e.g., signed. |
|
|
@item @code{POSTPONE} or @code{[COMPILE]} applied to @code{TO}: |
@item @code{POSTPONE} or @code{[COMPILE]} applied to @code{TO}: |
Assume @code{: X POSTPONE TO ; IMMEDIATE}. @code{X} is equivalent to |
@cindex @code{POSTPONE} or @code{[COMPILE]} applied to @code{TO} |
@code{TO}. |
Assume @code{: X POSTPONE TO ; IMMEDIATE}. @code{X} performs the |
|
compilation semantics of @code{TO}. |
|
|
@item String longer than a counted string returned by @code{WORD}: |
@item String longer than a counted string returned by @code{WORD}: |
|
@cindex String longer than a counted string returned by @code{WORD} |
|
@cindex @code{WORD}, string overflow |
Not checked. The string will be ok, but the count will, of course, |
Not checked. The string will be ok, but the count will, of course, |
contain only the least significant bits of the length. |
contain only the least significant bits of the length. |
|
|
@item u greater than or equal to the number of bits in a cell (@code{LSHIFT}, @code{RSHIFT}): |
@item u greater than or equal to the number of bits in a cell (@code{LSHIFT}, @code{RSHIFT}): |
|
@cindex @code{LSHIFT}, large shift counts |
|
@cindex @code{RSHIFT}, large shift counts |
Processor-dependent. Typical behaviours are returning 0 and using only |
Processor-dependent. Typical behaviours are returning 0 and using only |
the low bits of the shift count. |
the low bits of the shift count. |
|
|
@item word not defined via @code{CREATE}: |
@item word not defined via @code{CREATE}: |
|
@cindex @code{>BODY} of non-@code{CREATE}d words |
@code{>BODY} produces the PFA of the word no matter how it was defined. |
@code{>BODY} produces the PFA of the word no matter how it was defined. |
|
|
|
@cindex @code{DOES>} of non-@code{CREATE}d words |
@code{DOES>} changes the execution semantics of the last defined word no |
@code{DOES>} changes the execution semantics of the last defined word no |
matter how it was defined. E.g., @code{CONSTANT DOES>} is equivalent to |
matter how it was defined. E.g., @code{CONSTANT DOES>} is equivalent to |
@code{CREATE , DOES>}. |
@code{CREATE , DOES>}. |
Line 2595 Not checked. As usual, you can expect me
|
Line 3484 Not checked. As usual, you can expect me
|
@node core-other, , core-ambcond, The Core Words |
@node core-other, , core-ambcond, The Core Words |
@subsection Other system documentation |
@subsection Other system documentation |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex other system documentation, core words |
|
@cindex core words, other system documentation |
|
|
@table @i |
@table @i |
|
|
@item nonstandard words using @code{PAD}: |
@item nonstandard words using @code{PAD}: |
|
@cindex @code{PAD} use by nonstandard words |
None. |
None. |
|
|
@item operator's terminal facilities available: |
@item operator's terminal facilities available: |
!!?? |
@cindex operator's terminal facilities available |
|
After processing the command line, Gforth goes into interactive mode, |
|
and you can give commands to Gforth interactively. The actual facilities |
|
available depend on how you invoke Gforth. |
|
|
@item program data space available: |
@item program data space available: |
@code{sp@ here - .} gives the space remaining for dictionary and data |
@cindex program data space available |
stack together. |
@cindex data space available |
|
@code{UNUSED .} gives the remaining dictionary space. The total |
|
dictionary space can be specified with the @code{-m} switch |
|
(@pxref{Invoking Gforth}) when Gforth starts up. |
|
|
@item return stack space available: |
@item return stack space available: |
!!?? |
@cindex return stack space available |
|
You can compute the total return stack space in cells with |
|
@code{s" RETURN-STACK-CELLS" environment? drop .}. You can specify it at |
|
startup time with the @code{-r} switch (@pxref{Invoking Gforth}). |
|
|
@item stack space available: |
@item stack space available: |
@code{sp@ here - .} gives the space remaining for dictionary and data |
@cindex stack space available |
stack together. |
You can compute the total data stack space in cells with |
|
@code{s" STACK-CELLS" environment? drop .}. You can specify it at |
|
startup time with the @code{-d} switch (@pxref{Invoking Gforth}). |
|
|
@item system dictionary space required, in address units: |
@item system dictionary space required, in address units: |
|
@cindex system dictionary space required, in address units |
Type @code{here forthstart - .} after startup. At the time of this |
Type @code{here forthstart - .} after startup. At the time of this |
writing, this gives 70108 (bytes) on a 32-bit system. |
writing, this gives 80080 (bytes) on a 32-bit system. |
@end table |
@end table |
|
|
|
|
Line 2625 writing, this gives 70108 (bytes) on a 3
|
Line 3528 writing, this gives 70108 (bytes) on a 3
|
@node The optional Block word set, The optional Double Number word set, The Core Words, ANS conformance |
@node The optional Block word set, The optional Double Number word set, The Core Words, ANS conformance |
@section The optional Block word set |
@section The optional Block word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, block words |
|
@cindex block words, system documentation |
|
|
@menu |
@menu |
* block-idef:: Implementation Defined Options |
* block-idef:: Implementation Defined Options |
* block-ambcond:: Ambiguous Conditions |
* block-ambcond:: Ambiguous Conditions |
* block-other:: Other System Documentation |
* block-other:: Other System Documentation |
@end menu |
@end menu |
Line 2637 writing, this gives 70108 (bytes) on a 3
|
Line 3542 writing, this gives 70108 (bytes) on a 3
|
@node block-idef, block-ambcond, The optional Block word set, The optional Block word set |
@node block-idef, block-ambcond, The optional Block word set, The optional Block word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, block words |
|
@cindex block words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item the format for display by @code{LIST}: |
@item the format for display by @code{LIST}: |
|
@cindex @code{LIST} display format |
First the screen number is displayed, then 16 lines of 64 characters, |
First the screen number is displayed, then 16 lines of 64 characters, |
each line preceded by the line number. |
each line preceded by the line number. |
|
|
@item the length of a line affected by @code{\}: |
@item the length of a line affected by @code{\}: |
|
@cindex length of a line affected by @code{\} |
|
@cindex @code{\}, line length in blocks |
64 characters. |
64 characters. |
@end table |
@end table |
|
|
Line 2653 each line preceded by the line number.
|
Line 3562 each line preceded by the line number.
|
@node block-ambcond, block-other, block-idef, The optional Block word set |
@node block-ambcond, block-other, block-idef, The optional Block word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex block words, ambiguous conditions |
|
@cindex ambiguous conditions, block words |
|
|
@table @i |
@table @i |
|
|
@item correct block read was not possible: |
@item correct block read was not possible: |
|
@cindex block read not possible |
Typically results in a @code{throw} of some OS-derived value (between |
Typically results in a @code{throw} of some OS-derived value (between |
-512 and -2048). If the blocks file was just not long enough, blanks are |
-512 and -2048). If the blocks file was just not long enough, blanks are |
supplied for the missing portion. |
supplied for the missing portion. |
|
|
@item I/O exception in block transfer: |
@item I/O exception in block transfer: |
|
@cindex I/O exception in block transfer |
|
@cindex block transfer, I/O exception |
Typically results in a @code{throw} of some OS-derived value (between |
Typically results in a @code{throw} of some OS-derived value (between |
-512 and -2048). |
-512 and -2048). |
|
|
@item invalid block number: |
@item invalid block number: |
|
@cindex invalid block number |
|
@cindex block number invalid |
@code{-35 throw} (Invalid block number) |
@code{-35 throw} (Invalid block number) |
|
|
@item a program directly alters the contents of @code{BLK}: |
@item a program directly alters the contents of @code{BLK}: |
|
@cindex @code{BLK}, altering @code{BLK} |
The input stream is switched to that other block, at the same |
The input stream is switched to that other block, at the same |
position. If the storing to @code{BLK} happens when interpreting |
position. If the storing to @code{BLK} happens when interpreting |
non-block input, the system will get quite confused when the block ends. |
non-block input, the system will get quite confused when the block ends. |
|
|
@item no current block buffer for @code{UPDATE}: |
@item no current block buffer for @code{UPDATE}: |
|
@cindex @code{UPDATE}, no current block buffer |
@code{UPDATE} has no effect. |
@code{UPDATE} has no effect. |
|
|
@end table |
@end table |
|
|
|
|
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
@node block-other, , block-ambcond, The optional Block word set |
@node block-other, , block-ambcond, The optional Block word set |
@subsection Other system documentation |
@subsection Other system documentation |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex other system documentation, block words |
|
@cindex block words, other system documentation |
|
|
@table @i |
@table @i |
|
|
@item any restrictions a multiprogramming system places on the use of buffer addresses: |
@item any restrictions a multiprogramming system places on the use of buffer addresses: |
No restrictions (yet). |
No restrictions (yet). |
|
|
Line 2699 depends on your disk space.
|
Line 3616 depends on your disk space.
|
@node The optional Double Number word set, The optional Exception word set, The optional Block word set, ANS conformance |
@node The optional Double Number word set, The optional Exception word set, The optional Block word set, ANS conformance |
@section The optional Double Number word set |
@section The optional Double Number word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, double words |
|
@cindex double words, system documentation |
|
|
@menu |
@menu |
* double-ambcond:: Ambiguous Conditions |
* double-ambcond:: Ambiguous Conditions |
Line 2709 depends on your disk space.
|
Line 3628 depends on your disk space.
|
@node double-ambcond, , The optional Double Number word set, The optional Double Number word set |
@node double-ambcond, , The optional Double Number word set, The optional Double Number word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex double words, ambiguous conditions |
|
@cindex ambiguous conditions, double words |
|
|
@table @i |
@table @i |
|
|
@item @var{d} outside of range of @var{n} in @code{D>S}: |
@item @var{d} outside of range of @var{n} in @code{D>S}: |
|
@cindex @code{D>S}, @var{d} out of range of @var{n} |
The least significant cell of @var{d} is produced. |
The least significant cell of @var{d} is produced. |
|
|
@end table |
@end table |
Line 2722 The least significant cell of @var{d} is
|
Line 3643 The least significant cell of @var{d} is
|
@node The optional Exception word set, The optional Facility word set, The optional Double Number word set, ANS conformance |
@node The optional Exception word set, The optional Facility word set, The optional Double Number word set, ANS conformance |
@section The optional Exception word set |
@section The optional Exception word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, exception words |
|
@cindex exception words, system documentation |
|
|
@menu |
@menu |
* exception-idef:: Implementation Defined Options |
* exception-idef:: Implementation Defined Options |
Line 2732 The least significant cell of @var{d} is
|
Line 3655 The least significant cell of @var{d} is
|
@node exception-idef, , The optional Exception word set, The optional Exception word set |
@node exception-idef, , The optional Exception word set, The optional Exception word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, exception words |
|
@cindex exception words, implementation-defined options |
|
|
@table @i |
@table @i |
@item @code{THROW}-codes used in the system: |
@item @code{THROW}-codes used in the system: |
The codes -256@minus{}-511 are used for reporting signals (see |
@cindex @code{THROW}-codes used in the system |
@file{errore.fs}). The codes -512@minus{}-2047 are used for OS errors |
The codes -256@minus{}-511 are used for reporting signals. The mapping |
(for file and memory allocation operations). The mapping from OS error |
from OS signal numbers to throw codes is -256@minus{}@var{signal}. The |
numbers to throw code is -512@minus{}@var{errno}. One side effect of |
codes -512@minus{}-2047 are used for OS errors (for file and memory |
this mapping is that undefined OS errors produce a message with a |
allocation operations). The mapping from OS error numbers to throw codes |
strange number; e.g., @code{-1000 THROW} results in @code{Unknown error |
is -512@minus{}@code{errno}. One side effect of this mapping is that |
488} on my system. |
undefined OS errors produce a message with a strange number; e.g., |
|
@code{-1000 THROW} results in @code{Unknown error 488} on my system. |
@end table |
@end table |
|
|
@c ===================================================================== |
@c ===================================================================== |
@node The optional Facility word set, The optional File-Access word set, The optional Exception word set, ANS conformance |
@node The optional Facility word set, The optional File-Access word set, The optional Exception word set, ANS conformance |
@section The optional Facility word set |
@section The optional Facility word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, facility words |
|
@cindex facility words, system documentation |
|
|
@menu |
@menu |
* facility-idef:: Implementation Defined Options |
* facility-idef:: Implementation Defined Options |
Line 2759 strange number; e.g., @code{-1000 THROW}
|
Line 3687 strange number; e.g., @code{-1000 THROW}
|
@node facility-idef, facility-ambcond, The optional Facility word set, The optional Facility word set |
@node facility-idef, facility-ambcond, The optional Facility word set, The optional Facility word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, facility words |
|
@cindex facility words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item encoding of keyboard events (@code{EKEY}): |
@item encoding of keyboard events (@code{EKEY}): |
Not yet implemeted. |
@cindex keyboard events, encoding in @code{EKEY} |
|
@cindex @code{EKEY}, encoding of keyboard events |
@item duration of a system clock tick |
Not yet implemented. |
|
|
|
@item duration of a system clock tick: |
|
@cindex duration of a system clock tick |
|
@cindex clock tick duration |
System dependent. With respect to @code{MS}, the time is specified in |
System dependent. With respect to @code{MS}, the time is specified in |
microseconds. How well the OS and the hardware implement this, is |
microseconds. How well the OS and the hardware implement this, is |
another question. |
another question. |
|
|
@item repeatability to be expected from the execution of @code{MS}: |
@item repeatability to be expected from the execution of @code{MS}: |
|
@cindex repeatability to be expected from the execution of @code{MS} |
|
@cindex @code{MS}, repeatability to be expected |
System dependent. On Unix, a lot depends on load. If the system is |
System dependent. On Unix, a lot depends on load. If the system is |
lightly loaded, and the delay is short enough that Gforth does not get |
lightly loaded, and the delay is short enough that Gforth does not get |
swapped out, the performance should be acceptable. Under MS-DOS and |
swapped out, the performance should be acceptable. Under MS-DOS and |
Line 2783 other single-tasking systems, it should
|
Line 3718 other single-tasking systems, it should
|
@node facility-ambcond, , facility-idef, The optional Facility word set |
@node facility-ambcond, , facility-idef, The optional Facility word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex facility words, ambiguous conditions |
|
@cindex ambiguous conditions, facility words |
|
|
@table @i |
@table @i |
|
|
@item @code{AT-XY} can't be performed on user output device: |
@item @code{AT-XY} can't be performed on user output device: |
Largely terminal dependant. No range checks are done on the arguments. |
@cindex @code{AT-XY} can't be performed on user output device |
|
Largely terminal dependent. No range checks are done on the arguments. |
No errors are reported. You may see some garbage appearing, you may see |
No errors are reported. You may see some garbage appearing, you may see |
simply nothing happen. |
simply nothing happen. |
|
|
Line 2798 simply nothing happen.
|
Line 3735 simply nothing happen.
|
@node The optional File-Access word set, The optional Floating-Point word set, The optional Facility word set, ANS conformance |
@node The optional File-Access word set, The optional Floating-Point word set, The optional Facility word set, ANS conformance |
@section The optional File-Access word set |
@section The optional File-Access word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, file words |
|
@cindex file words, system documentation |
|
|
@menu |
@menu |
* file-idef:: Implementation Defined Options |
* file-idef:: Implementation Defined Options |
* file-ambcond:: Ambiguous Conditions |
* file-ambcond:: Ambiguous Conditions |
@end menu |
@end menu |
|
|
|
|
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
@node file-idef, file-ambcond, The optional File-Access word set, The optional File-Access word set |
@node file-idef, file-ambcond, The optional File-Access word set, The optional File-Access word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, file words |
|
@cindex file words, implementation-defined options |
|
|
@table @i |
@table @i |
|
@item file access methods used: |
@item File access methods used: |
@cindex file access methods used |
@code{R/O}, @code{R/W} and @code{BIN} work as you would |
@code{R/O}, @code{R/W} and @code{BIN} work as you would |
expect. @code{W/O} translates into the C file opening mode @code{w} (or |
expect. @code{W/O} translates into the C file opening mode @code{w} (or |
@code{wb}): The file is cleared, if it exists, and created, if it does |
@code{wb}): The file is cleared, if it exists, and created, if it does |
not (both with @code{open-file} and @code{create-file}). Under Unix |
not (with both @code{open-file} and @code{create-file}). Under Unix |
@code{create-file} creates a file with 666 permissions modified by your |
@code{create-file} creates a file with 666 permissions modified by your |
umask. |
umask. |
|
|
@item file exceptions: |
@item file exceptions: |
|
@cindex file exceptions |
The file words do not raise exceptions (except, perhaps, memory access |
The file words do not raise exceptions (except, perhaps, memory access |
faults when you pass illegal addresses or file-ids). |
faults when you pass illegal addresses or file-ids). |
|
|
@item file line terminator: |
@item file line terminator: |
|
@cindex file line terminator |
System-dependent. Gforth uses C's newline character as line |
System-dependent. Gforth uses C's newline character as line |
terminator. What the actual character code(s) of this are is |
terminator. What the actual character code(s) of this are is |
system-dependent. |
system-dependent. |
|
|
@item file name format |
@item file name format: |
|
@cindex file name format |
System dependent. Gforth just uses the file name format of your OS. |
System dependent. Gforth just uses the file name format of your OS. |
|
|
@item information returned by @code{FILE-STATUS}: |
@item information returned by @code{FILE-STATUS}: |
|
@cindex @code{FILE-STATUS}, returned information |
@code{FILE-STATUS} returns the most powerful file access mode allowed |
@code{FILE-STATUS} returns the most powerful file access mode allowed |
for the file: Either @code{R/O}, @code{W/O} or @code{R/W}. If the file |
for the file: Either @code{R/O}, @code{W/O} or @code{R/W}. If the file |
cannot be accessed, @code{R/O BIN} is returned. @code{BIN} is applicable |
cannot be accessed, @code{R/O BIN} is returned. @code{BIN} is applicable |
along with the retured mode. |
along with the returned mode. |
|
|
@item input file state after an exception when including source: |
@item input file state after an exception when including source: |
|
@cindex exception when including source |
All files that are left via the exception are closed. |
All files that are left via the exception are closed. |
|
|
@item @var{ior} values and meaning: |
@item @var{ior} values and meaning: |
|
@cindex @var{ior} values and meaning |
The @var{ior}s returned by the file and memory allocation words are |
The @var{ior}s returned by the file and memory allocation words are |
intended as throw codes. They typically are in the range |
intended as throw codes. They typically are in the range |
-512@minus{}-2047 of OS errors. The mapping from OS error numbers to |
-512@minus{}-2047 of OS errors. The mapping from OS error numbers to |
@var{ior}s is -512@minus{}@var{errno}. |
@var{ior}s is -512@minus{}@var{errno}. |
|
|
@item maximum depth of file input nesting: |
@item maximum depth of file input nesting: |
|
@cindex maximum depth of file input nesting |
|
@cindex file input nesting, maximum depth |
limited by the amount of return stack, locals/TIB stack, and the number |
limited by the amount of return stack, locals/TIB stack, and the number |
of open files available. This should not give you troubles. |
of open files available. This should not give you troubles. |
|
|
@item maximum size of input line: |
@item maximum size of input line: |
|
@cindex maximum size of input line |
|
@cindex input line size, maximum |
@code{/line}. Currently 255. |
@code{/line}. Currently 255. |
|
|
@item methods of mapping block ranges to files: |
@item methods of mapping block ranges to files: |
Currently, the block words automatically access the file |
@cindex mapping block ranges to files |
@file{blocks.fb} in the currend working directory. More sophisticated |
@cindex files containing blocks |
methods could be implemented if there is demand (and a volunteer). |
@cindex blocks in files |
|
By default, blocks are accessed in the file @file{blocks.fb} in the |
|
current working directory. The file can be switched with @code{USE}. |
|
|
@item number of string buffers provided by @code{S"}: |
@item number of string buffers provided by @code{S"}: |
|
@cindex @code{S"}, number of string buffers |
1 |
1 |
|
|
@item size of string buffer used by @code{S"}: |
@item size of string buffer used by @code{S"}: |
|
@cindex @code{S"}, size of string buffer |
@code{/line}. currently 255. |
@code{/line}. currently 255. |
|
|
@end table |
@end table |
Line 2871 methods could be implemented if there is
|
Line 3825 methods could be implemented if there is
|
@node file-ambcond, , file-idef, The optional File-Access word set |
@node file-ambcond, , file-idef, The optional File-Access word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex file words, ambiguous conditions |
|
@cindex ambiguous conditions, file words |
|
|
@table @i |
@table @i |
|
@item attempting to position a file outside its boundaries: |
@item attempting to position a file outside it's boundaries: |
@cindex @code{REPOSITION-FILE}, outside the file's boundaries |
@code{REPOSITION-FILE} is performed as usual: Afterwards, |
@code{REPOSITION-FILE} is performed as usual: Afterwards, |
@code{FILE-POSITION} returns the value given to @code{REPOSITION-FILE}. |
@code{FILE-POSITION} returns the value given to @code{REPOSITION-FILE}. |
|
|
@item attempting to read from file positions not yet written: |
@item attempting to read from file positions not yet written: |
|
@cindex reading from file positions not yet written |
End-of-file, i.e., zero characters are read and no error is reported. |
End-of-file, i.e., zero characters are read and no error is reported. |
|
|
@item @var{file-id} is invalid (@code{INCLUDE-FILE}): |
@item @var{file-id} is invalid (@code{INCLUDE-FILE}): |
|
@cindex @code{INCLUDE-FILE}, @var{file-id} is invalid |
An appropriate exception may be thrown, but a memory fault or other |
An appropriate exception may be thrown, but a memory fault or other |
problem is more probable. |
problem is more probable. |
|
|
@item I/O exception reading or closing @var{file-id} (@code{include-file}, @code{included}): |
@item I/O exception reading or closing @var{file-id} (@code{INCLUDE-FILE}, @code{INCLUDED}): |
|
@cindex @code{INCLUDE-FILE}, I/O exception reading or closing @var{file-id} |
|
@cindex @code{INCLUDED}, I/O exception reading or closing @var{file-id} |
The @var{ior} produced by the operation, that discovered the problem, is |
The @var{ior} produced by the operation, that discovered the problem, is |
thrown. |
thrown. |
|
|
@item named file cannot be opened (@code{included}): |
@item named file cannot be opened (@code{INCLUDED}): |
|
@cindex @code{INCLUDED}, named file cannot be opened |
The @var{ior} produced by @code{open-file} is thrown. |
The @var{ior} produced by @code{open-file} is thrown. |
|
|
@item requesting an unmapped block number: |
@item requesting an unmapped block number: |
|
@cindex unmapped block numbers |
There are no unmapped legal block numbers. On some operating systems, |
There are no unmapped legal block numbers. On some operating systems, |
writing a block with a large number may overflow the file system and |
writing a block with a large number may overflow the file system and |
have an error message as consequence. |
have an error message as consequence. |
|
|
@item using @code{source-id} when @code{blk} is non-zero: |
@item using @code{source-id} when @code{blk} is non-zero: |
|
@cindex @code{SOURCE-ID}, behaviour when @code{BLK} is non-zero |
@code{source-id} performs its function. Typically it will give the id of |
@code{source-id} performs its function. Typically it will give the id of |
the source which loaded the block. (Better ideas?) |
the source which loaded the block. (Better ideas?) |
|
|
Line 2908 the source which loaded the block. (Bett
|
Line 3871 the source which loaded the block. (Bett
|
@node The optional Floating-Point word set, The optional Locals word set, The optional File-Access word set, ANS conformance |
@node The optional Floating-Point word set, The optional Locals word set, The optional File-Access word set, ANS conformance |
@section The optional Floating-Point word set |
@section The optional Floating-Point word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, floating-point words |
|
@cindex floating-point words, system documentation |
|
|
@menu |
@menu |
* floating-idef:: Implementation Defined Options |
* floating-idef:: Implementation Defined Options |
Line 2919 the source which loaded the block. (Bett
|
Line 3884 the source which loaded the block. (Bett
|
@node floating-idef, floating-ambcond, The optional Floating-Point word set, The optional Floating-Point word set |
@node floating-idef, floating-ambcond, The optional Floating-Point word set, The optional Floating-Point word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, floating-point words |
|
@cindex floating-point words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item format and range of floating point numbers: |
@item format and range of floating point numbers: |
|
@cindex format and range of floating point numbers |
|
@cindex floating point numbers, format and range |
System-dependent; the @code{double} type of C. |
System-dependent; the @code{double} type of C. |
|
|
@item results of @code{REPRESENT} when @var{float} is out of range: |
@item results of @code{REPRESENT} when @var{float} is out of range: |
|
@cindex @code{REPRESENT}, results when @var{float} is out of range |
System dependent; @code{REPRESENT} is implemented using the C library |
System dependent; @code{REPRESENT} is implemented using the C library |
function @code{ecvt()} and inherits its behaviour in this respect. |
function @code{ecvt()} and inherits its behaviour in this respect. |
|
|
@item rounding or truncation of floating-point numbers: |
@item rounding or truncation of floating-point numbers: |
What's the question?!! |
@cindex rounding of floating-point numbers |
|
@cindex truncation of floating-point numbers |
|
@cindex floating-point numbers, rounding or truncation |
|
System dependent; the rounding behaviour is inherited from the hosting C |
|
compiler. IEEE-FP-based (i.e., most) systems by default round to |
|
nearest, and break ties by rounding to even (i.e., such that the last |
|
bit of the mantissa is 0). |
|
|
@item size of floating-point stack: |
@item size of floating-point stack: |
@code{s" FLOATING-STACK" environment? drop .}. Can be changed at startup |
@cindex floating-point stack size |
with the command-line option @code{-f}. |
@code{s" FLOATING-STACK" environment? drop .} gives the total size of |
|
the floating-point stack (in floats). You can specify this on startup |
|
with the command-line option @code{-f} (@pxref{Invoking Gforth}). |
|
|
@item width of floating-point stack: |
@item width of floating-point stack: |
|
@cindex floating-point stack width |
@code{1 floats}. |
@code{1 floats}. |
|
|
@end table |
@end table |
Line 2946 with the command-line option @code{-f}.
|
Line 3924 with the command-line option @code{-f}.
|
@node floating-ambcond, , floating-idef, The optional Floating-Point word set |
@node floating-ambcond, , floating-idef, The optional Floating-Point word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex floating-point words, ambiguous conditions |
|
@cindex ambiguous conditions, floating-point words |
|
|
@table @i |
@table @i |
|
|
@item @code{df@@} or @code{df!} used with an address that is not double-float aligned: |
@item @code{df@@} or @code{df!} used with an address that is not double-float aligned: |
System-dependent. Typically results in an alignment fault like other |
@cindex @code{df@@} or @code{df!} used with an address that is not double-float aligned |
|
System-dependent. Typically results in a @code{-23 THROW} like other |
alignment violations. |
alignment violations. |
|
|
@item @code{f@@} or @code{f!} used with an address that is not float aligned: |
@item @code{f@@} or @code{f!} used with an address that is not float aligned: |
System-dependent. Typically results in an alignment fault like other |
@cindex @code{f@@} used with an address that is not float aligned |
|
@cindex @code{f!} used with an address that is not float aligned |
|
System-dependent. Typically results in a @code{-23 THROW} like other |
alignment violations. |
alignment violations. |
|
|
@item Floating-point result out of range: |
@item floating-point result out of range: |
|
@cindex floating-point result out of range |
System-dependent. Can result in a @code{-55 THROW} (Floating-point |
System-dependent. Can result in a @code{-55 THROW} (Floating-point |
unidentified fault), or can produce a special value representing, e.g., |
unidentified fault), or can produce a special value representing, e.g., |
Infinity. |
Infinity. |
|
|
@item @code{sf@@} or @code{sf!} used with an address that is not single-float aligned: |
@item @code{sf@@} or @code{sf!} used with an address that is not single-float aligned: |
|
@cindex @code{sf@@} or @code{sf!} used with an address that is not single-float aligned |
System-dependent. Typically results in an alignment fault like other |
System-dependent. Typically results in an alignment fault like other |
alignment violations. |
alignment violations. |
|
|
@item BASE is not decimal (@code{REPRESENT}, @code{F.}, @code{FE.}, @code{FS.}): |
@item @code{BASE} is not decimal (@code{REPRESENT}, @code{F.}, @code{FE.}, @code{FS.}): |
|
@cindex @code{BASE} is not decimal (@code{REPRESENT}, @code{F.}, @code{FE.}, @code{FS.}) |
The floating-point number is converted into decimal nonetheless. |
The floating-point number is converted into decimal nonetheless. |
|
|
@item Both arguments are equal to zero (@code{FATAN2}): |
@item Both arguments are equal to zero (@code{FATAN2}): |
|
@cindex @code{FATAN2}, both arguments are equal to zero |
System-dependent. @code{FATAN2} is implemented using the C library |
System-dependent. @code{FATAN2} is implemented using the C library |
function @code{atan2()}. |
function @code{atan2()}. |
|
|
@item Using ftan on an argument @var{r1} where cos(@var{r1}) is zero: |
@item Using @code{FTAN} on an argument @var{r1} where cos(@var{r1}) is zero: |
|
@cindex @code{FTAN} on an argument @var{r1} where cos(@var{r1}) is zero |
System-dependent. Anyway, typically the cos of @var{r1} will not be zero |
System-dependent. Anyway, typically the cos of @var{r1} will not be zero |
because of small errors and the tan will be a very large (or very small) |
because of small errors and the tan will be a very large (or very small) |
but finite number. |
but finite number. |
|
|
@item @var{d} cannot be presented precisely as a float in @code{D>F}: |
@item @var{d} cannot be presented precisely as a float in @code{D>F}: |
|
@cindex @code{D>F}, @var{d} cannot be presented precisely as a float |
The result is rounded to the nearest float. |
The result is rounded to the nearest float. |
|
|
@item dividing by zero: |
@item dividing by zero: |
|
@cindex dividing by zero, floating-point |
|
@cindex floating-point dividing by zero |
|
@cindex floating-point unidentified fault, FP divide-by-zero |
@code{-55 throw} (Floating-point unidentified fault) |
@code{-55 throw} (Floating-point unidentified fault) |
|
|
@item exponent too big for conversion (@code{DF!}, @code{DF@@}, @code{SF!}, @code{SF@@}): |
@item exponent too big for conversion (@code{DF!}, @code{DF@@}, @code{SF!}, @code{SF@@}): |
|
@cindex exponent too big for conversion (@code{DF!}, @code{DF@@}, @code{SF!}, @code{SF@@}) |
System dependent. On IEEE-FP based systems the number is converted into |
System dependent. On IEEE-FP based systems the number is converted into |
an infinity. |
an infinity. |
|
|
@item @var{float}<1 (@code{facosh}): |
@item @var{float}<1 (@code{FACOSH}): |
|
@cindex @code{FACOSH}, @var{float}<1 |
|
@cindex floating-point unidentified fault, @code{FACOSH} |
@code{-55 throw} (Floating-point unidentified fault) |
@code{-55 throw} (Floating-point unidentified fault) |
|
|
@item @var{float}=<-1 (@code{flnp1}): |
@item @var{float}=<-1 (@code{FLNP1}): |
|
@cindex @code{FLNP1}, @var{float}=<-1 |
|
@cindex floating-point unidentified fault, @code{FLNP1} |
@code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems |
@code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems |
negative infinity is typically produced for @var{float}=-1. |
negative infinity is typically produced for @var{float}=-1. |
|
|
@item @var{float}=<0 (@code{fln}, @code{flog}): |
@item @var{float}=<0 (@code{FLN}, @code{FLOG}): |
|
@cindex @code{FLN}, @var{float}=<0 |
|
@cindex @code{FLOG}, @var{float}=<0 |
|
@cindex floating-point unidentified fault, @code{FLN} or @code{FLOG} |
@code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems |
@code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems |
negative infinity is typically produced for @var{float}=0. |
negative infinity is typically produced for @var{float}=0. |
|
|
@item @var{float}<0 (@code{fasinh}, @code{fsqrt}): |
@item @var{float}<0 (@code{FASINH}, @code{FSQRT}): |
|
@cindex @code{FASINH}, @var{float}<0 |
|
@cindex @code{FSQRT}, @var{float}<0 |
|
@cindex floating-point unidentified fault, @code{FASINH} or @code{FSQRT} |
@code{-55 throw} (Floating-point unidentified fault). @code{fasinh} |
@code{-55 throw} (Floating-point unidentified fault). @code{fasinh} |
produces values for these inputs on my Linux box (Bug in the C library?) |
produces values for these inputs on my Linux box (Bug in the C library?) |
|
|
@item |@var{float}|>1 (@code{facos}, @code{fasin}, @code{fatanh}): |
@item |@var{float}|>1 (@code{FACOS}, @code{FASIN}, @code{FATANH}): |
|
@cindex @code{FACOS}, |@var{float}|>1 |
|
@cindex @code{FASIN}, |@var{float}|>1 |
|
@cindex @code{FATANH}, |@var{float}|>1 |
|
@cindex floating-point unidentified fault, @code{FACOS}, @code{FASIN} or @code{FATANH} |
@code{-55 throw} (Floating-point unidentified fault). |
@code{-55 throw} (Floating-point unidentified fault). |
|
|
@item integer part of float cannot be represented by @var{d} in @code{f>d}: |
@item integer part of float cannot be represented by @var{d} in @code{F>D}: |
|
@cindex @code{F>D}, integer part of float cannot be represented by @var{d} |
|
@cindex floating-point unidentified fault, @code{F>D} |
@code{-55 throw} (Floating-point unidentified fault). |
@code{-55 throw} (Floating-point unidentified fault). |
|
|
@item string larger than pictured numeric output area (@code{f.}, @code{fe.}, @code{fs.}): |
@item string larger than pictured numeric output area (@code{f.}, @code{fe.}, @code{fs.}): |
|
@cindex string larger than pictured numeric output area (@code{f.}, @code{fe.}, @code{fs.}) |
This does not happen. |
This does not happen. |
@end table |
@end table |
|
|
|
|
|
|
@c ===================================================================== |
@c ===================================================================== |
@node The optional Locals word set, The optional Memory-Allocation word set, The optional Floating-Point word set, ANS conformance |
@node The optional Locals word set, The optional Memory-Allocation word set, The optional Floating-Point word set, ANS conformance |
@section The optional Locals word set |
@section The optional Locals word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, locals words |
|
@cindex locals words, system documentation |
|
|
@menu |
@menu |
* locals-idef:: Implementation Defined Options |
* locals-idef:: Implementation Defined Options |
Line 3030 This does not happen.
|
Line 4039 This does not happen.
|
@node locals-idef, locals-ambcond, The optional Locals word set, The optional Locals word set |
@node locals-idef, locals-ambcond, The optional Locals word set, The optional Locals word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, locals words |
|
@cindex locals words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item maximum number of locals in a definition: |
@item maximum number of locals in a definition: |
|
@cindex maximum number of locals in a definition |
|
@cindex locals, maximum number in a definition |
@code{s" #locals" environment? drop .}. Currently 15. This is a lower |
@code{s" #locals" environment? drop .}. Currently 15. This is a lower |
bound, e.g., on a 32-bit machine there can be 41 locals of up to 8 |
bound, e.g., on a 32-bit machine there can be 41 locals of up to 8 |
characters. The number of locals in a definition is bounded by the size |
characters. The number of locals in a definition is bounded by the size |
Line 3046 of locals-buffer, which contains the nam
|
Line 4058 of locals-buffer, which contains the nam
|
@node locals-ambcond, , locals-idef, The optional Locals word set |
@node locals-ambcond, , locals-idef, The optional Locals word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex locals words, ambiguous conditions |
|
@cindex ambiguous conditions, locals words |
|
|
@table @i |
@table @i |
|
|
@item executing a named local in interpretation state: |
@item executing a named local in interpretation state: |
@code{-14 throw} (Interpreting a compile-only word). |
@cindex local in interpretation state |
|
@cindex Interpreting a compile-only word, for a local |
|
Locals have no interpretation semantics. If you try to perform the |
|
interpretation semantics, you will get a @code{-14 throw} somewhere |
|
(Interpreting a compile-only word). If you perform the compilation |
|
semantics, the locals access will be compiled (irrespective of state). |
|
|
@item @var{name} not defined by @code{VALUE} or @code{(LOCAL)} (@code{TO}): |
@item @var{name} not defined by @code{VALUE} or @code{(LOCAL)} (@code{TO}): |
|
@cindex name not defined by @code{VALUE} or @code{(LOCAL)} used by @code{TO} |
|
@cindex @code{TO} on non-@code{VALUE}s and non-locals |
|
@cindex Invalid name argument, @code{TO} |
@code{-32 throw} (Invalid name argument) |
@code{-32 throw} (Invalid name argument) |
|
|
@end table |
@end table |
Line 3062 of locals-buffer, which contains the nam
|
Line 4083 of locals-buffer, which contains the nam
|
@node The optional Memory-Allocation word set, The optional Programming-Tools word set, The optional Locals word set, ANS conformance |
@node The optional Memory-Allocation word set, The optional Programming-Tools word set, The optional Locals word set, ANS conformance |
@section The optional Memory-Allocation word set |
@section The optional Memory-Allocation word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, memory-allocation words |
|
@cindex memory-allocation words, system documentation |
|
|
@menu |
@menu |
* memory-idef:: Implementation Defined Options |
* memory-idef:: Implementation Defined Options |
Line 3072 of locals-buffer, which contains the nam
|
Line 4095 of locals-buffer, which contains the nam
|
@node memory-idef, , The optional Memory-Allocation word set, The optional Memory-Allocation word set |
@node memory-idef, , The optional Memory-Allocation word set, The optional Memory-Allocation word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, memory-allocation words |
|
@cindex memory-allocation words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item values and meaning of @var{ior}: |
@item values and meaning of @var{ior}: |
|
@cindex @var{ior} values and meaning |
The @var{ior}s returned by the file and memory allocation words are |
The @var{ior}s returned by the file and memory allocation words are |
intended as throw codes. They typically are in the range |
intended as throw codes. They typically are in the range |
-512@minus{}-2047 of OS errors. The mapping from OS error numbers to |
-512@minus{}-2047 of OS errors. The mapping from OS error numbers to |
Line 3087 intended as throw codes. They typically
|
Line 4112 intended as throw codes. They typically
|
@node The optional Programming-Tools word set, The optional Search-Order word set, The optional Memory-Allocation word set, ANS conformance |
@node The optional Programming-Tools word set, The optional Search-Order word set, The optional Memory-Allocation word set, ANS conformance |
@section The optional Programming-Tools word set |
@section The optional Programming-Tools word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, programming-tools words |
|
@cindex programming-tools words, system documentation |
|
|
@menu |
@menu |
* programming-idef:: Implementation Defined Options |
* programming-idef:: Implementation Defined Options |
Line 3098 intended as throw codes. They typically
|
Line 4125 intended as throw codes. They typically
|
@node programming-idef, programming-ambcond, The optional Programming-Tools word set, The optional Programming-Tools word set |
@node programming-idef, programming-ambcond, The optional Programming-Tools word set, The optional Programming-Tools word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, programming-tools words |
|
@cindex programming-tools words, implementation-defined options |
|
|
@table @i |
@table @i |
|
@item ending sequence for input following @code{;CODE} and @code{CODE}: |
@item ending sequence for input following @code{;code} and @code{code}: |
@cindex @code{;CODE} ending sequence |
Not implemented (yet). |
@cindex @code{CODE} ending sequence |
|
@code{END-CODE} |
@item manner of processing input following @code{;code} and @code{code}: |
|
Not implemented (yet). |
@item manner of processing input following @code{;CODE} and @code{CODE}: |
|
@cindex @code{;CODE}, processing input |
|
@cindex @code{CODE}, processing input |
|
The @code{ASSEMBLER} vocabulary is pushed on the search order stack, and |
|
the input is processed by the text interpreter, (starting) in interpret |
|
state. |
|
|
@item search order capability for @code{EDITOR} and @code{ASSEMBLER}: |
@item search order capability for @code{EDITOR} and @code{ASSEMBLER}: |
Not implemented (yet). If they were implemented, they would use the |
@cindex @code{ASSEMBLER}, search order capability |
search order wordset. |
The ANS Forth search order word set. |
|
|
@item source and format of display by @code{SEE}: |
@item source and format of display by @code{SEE}: |
|
@cindex @code{SEE}, source and format of output |
The source for @code{see} is the intermediate code used by the inner |
The source for @code{see} is the intermediate code used by the inner |
interpreter. The current @code{see} tries to output Forth source code |
interpreter. The current @code{see} tries to output Forth source code |
as well as possible. |
as well as possible. |
Line 3122 as well as possible.
|
Line 4157 as well as possible.
|
@node programming-ambcond, , programming-idef, The optional Programming-Tools word set |
@node programming-ambcond, , programming-idef, The optional Programming-Tools word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex programming-tools words, ambiguous conditions |
|
@cindex ambiguous conditions, programming-tools words |
|
|
@table @i |
@table @i |
|
|
@item deleting the compilation wordlist (@code{FORGET}): |
@item deleting the compilation wordlist (@code{FORGET}): |
|
@cindex @code{FORGET}, deleting the compilation wordlist |
Not implemented (yet). |
Not implemented (yet). |
|
|
@item fewer than @var{u}+1 items on the control flow stack (@code{CS-PICK}, @code{CS-ROLL}): |
@item fewer than @var{u}+1 items on the control flow stack (@code{CS-PICK}, @code{CS-ROLL}): |
|
@cindex @code{CS-PICK}, fewer than @var{u}+1 items on the control flow stack |
|
@cindex @code{CS-ROLL}, fewer than @var{u}+1 items on the control flow stack |
|
@cindex control-flow stack underflow |
This typically results in an @code{abort"} with a descriptive error |
This typically results in an @code{abort"} with a descriptive error |
message (may change into a @code{-22 throw} (Control structure mismatch) |
message (may change into a @code{-22 throw} (Control structure mismatch) |
in the future). You may also get a memory access error. If you are |
in the future). You may also get a memory access error. If you are |
unlucky, this ambiguous condition is not caught. |
unlucky, this ambiguous condition is not caught. |
|
|
@item @var{name} can't be found (@code{forget}): |
@item @var{name} can't be found (@code{FORGET}): |
|
@cindex @code{FORGET}, @var{name} can't be found |
Not implemented (yet). |
Not implemented (yet). |
|
|
@item @var{name} not defined via @code{CREATE}: |
@item @var{name} not defined via @code{CREATE}: |
@code{;code} is not implemented (yet). If it were, it would behave like |
@cindex @code{;CODE}, @var{name} not defined via @code{CREATE} |
@code{DOES>} in this respect, i.e., change the execution semantics of |
@code{;CODE} behaves like @code{DOES>} in this respect, i.e., it changes |
the last defined word no matter how it was defined. |
the execution semantics of the last defined word no matter how it was |
|
defined. |
|
|
@item @code{POSTPONE} applied to @code{[IF]}: |
@item @code{POSTPONE} applied to @code{[IF]}: |
|
@cindex @code{POSTPONE} applied to @code{[IF]} |
|
@cindex @code{[IF]} and @code{POSTPONE} |
After defining @code{: X POSTPONE [IF] ; IMMEDIATE}. @code{X} is |
After defining @code{: X POSTPONE [IF] ; IMMEDIATE}. @code{X} is |
equivalent to @code{[IF]}. |
equivalent to @code{[IF]}. |
|
|
@item reaching the end of the input source before matching @code{[ELSE]} or @code{[THEN]}: |
@item reaching the end of the input source before matching @code{[ELSE]} or @code{[THEN]}: |
|
@cindex @code{[IF]}, end of the input source before matching @code{[ELSE]} or @code{[THEN]} |
Continue in the same state of conditional compilation in the next outer |
Continue in the same state of conditional compilation in the next outer |
input source. Currently there is no warning to the user about this. |
input source. Currently there is no warning to the user about this. |
|
|
@item removing a needed definition (@code{FORGET}): |
@item removing a needed definition (@code{FORGET}): |
|
@cindex @code{FORGET}, removing a needed definition |
Not implemented (yet). |
Not implemented (yet). |
|
|
@end table |
@end table |
Line 3160 Not implemented (yet).
|
Line 4207 Not implemented (yet).
|
@node The optional Search-Order word set, , The optional Programming-Tools word set, ANS conformance |
@node The optional Search-Order word set, , The optional Programming-Tools word set, ANS conformance |
@section The optional Search-Order word set |
@section The optional Search-Order word set |
@c ===================================================================== |
@c ===================================================================== |
|
@cindex system documentation, search-order words |
|
@cindex search-order words, system documentation |
|
|
@menu |
@menu |
* search-idef:: Implementation Defined Options |
* search-idef:: Implementation Defined Options |
Line 3171 Not implemented (yet).
|
Line 4220 Not implemented (yet).
|
@node search-idef, search-ambcond, The optional Search-Order word set, The optional Search-Order word set |
@node search-idef, search-ambcond, The optional Search-Order word set, The optional Search-Order word set |
@subsection Implementation Defined Options |
@subsection Implementation Defined Options |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex implementation-defined options, search-order words |
|
@cindex search-order words, implementation-defined options |
|
|
@table @i |
@table @i |
|
|
@item maximum number of word lists in search order: |
@item maximum number of word lists in search order: |
|
@cindex maximum number of word lists in search order |
|
@cindex search order, maximum depth |
@code{s" wordlists" environment? drop .}. Currently 16. |
@code{s" wordlists" environment? drop .}. Currently 16. |
|
|
@item minimum search order: |
@item minimum search order: |
|
@cindex minimum search order |
|
@cindex search order, minimum |
@code{root root}. |
@code{root root}. |
|
|
@end table |
@end table |
Line 3186 Not implemented (yet).
|
Line 4240 Not implemented (yet).
|
@node search-ambcond, , search-idef, The optional Search-Order word set |
@node search-ambcond, , search-idef, The optional Search-Order word set |
@subsection Ambiguous conditions |
@subsection Ambiguous conditions |
@c --------------------------------------------------------------------- |
@c --------------------------------------------------------------------- |
|
@cindex search-order words, ambiguous conditions |
|
@cindex ambiguous conditions, search-order words |
|
|
@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 |
@cindex changing the compilation wordlist (during compilation) |
when @code{REVEAL} is executed (by @code{;}, @code{DOES>}, |
@cindex compilation wordlist, change before definition ends |
@code{RECURSIVE}, etc.). |
The word is entered into the wordlist that was the compilation wordlist |
|
at the start of the definition. Any changes to the name field (e.g., |
|
@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}): |
|
@cindex @code{previous}, search order empty |
|
@cindex Vocstack empty, @code{previous} |
@code{abort" Vocstack empty"}. |
@code{abort" Vocstack empty"}. |
|
|
@item too many word lists in search order (@code{also}): |
@item too many word lists in search order (@code{also}): |
|
@cindex @code{also}, too many word lists in search order |
|
@cindex Vocstack full, @code{also} |
@code{abort" Vocstack full"}. |
@code{abort" Vocstack full"}. |
|
|
@end table |
@end table |
|
|
|
@c *************************************************************** |
@node Model, Emacs and Gforth, ANS conformance, Top |
@node Model, Integrating Gforth, ANS conformance, Top |
@chapter Model |
@chapter Model |
|
|
@node Emacs and Gforth, Internals, Model, Top |
This chapter has yet to be written. It will contain information, on |
|
which internal structures you can rely. |
|
|
|
@c *************************************************************** |
|
@node Integrating Gforth, Emacs and Gforth, Model, Top |
|
@chapter Integrating Gforth into C programs |
|
|
|
This is not yet implemented. |
|
|
|
Several people like to use Forth as scripting language for applications |
|
that are otherwise written in C, C++, or some other language. |
|
|
|
The Forth system ATLAST provides facilities for embedding it into |
|
applications; unfortunately it has several disadvantages: most |
|
importantly, it is not based on ANS Forth, and it is apparently dead |
|
(i.e., not developed further and not supported). The facilities |
|
provided by Gforth in this area are inspired by ATLASTs facilities, so |
|
making the switch should not be hard. |
|
|
|
We also tried to design the interface such that it can easily be |
|
implemented by other Forth systems, so that we may one day arrive at a |
|
standardized interface. Such a standard interface would allow you to |
|
replace the Forth system without having to rewrite C code. |
|
|
|
You embed the Gforth interpreter by linking with the library |
|
@code{libgforth.a} (give the compiler the option @code{-lgforth}). All |
|
global symbols in this library that belong to the interface, have the |
|
prefix @code{forth_}. (Global symbols that are used internally have the |
|
prefix @code{gforth_}). |
|
|
|
You can include the declarations of Forth types and the functions and |
|
variables of the interface with @code{#include <forth.h>}. |
|
|
|
Types. |
|
|
|
Variables. |
|
|
|
Data and FP Stack pointer. Area sizes. |
|
|
|
functions. |
|
|
|
forth_init(imagefile) |
|
forth_evaluate(string) exceptions? |
|
forth_goto(address) (or forth_execute(xt)?) |
|
forth_continue() (a corountining mechanism) |
|
|
|
Adding primitives. |
|
|
|
No checking. |
|
|
|
Signals? |
|
|
|
Accessing the Stacks |
|
|
|
@node Emacs and Gforth, Image Files, Integrating Gforth, Top |
@chapter Emacs and Gforth |
@chapter Emacs and Gforth |
|
@cindex Emacs and Gforth |
|
|
|
@cindex @file{gforth.el} |
|
@cindex @file{forth.el} |
|
@cindex Rydqvist, Goran |
|
@cindex comment editing commands |
|
@cindex @code{\}, editing with Emacs |
|
@cindex debug tracer editing commands |
|
@cindex @code{~~}, removal with Emacs |
|
@cindex Forth mode in Emacs |
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 3219 stuff I do not use alone, even though so
|
Line 4345 stuff I do not use alone, even though so
|
TILE. To get a description of these features, enter Forth mode and type |
TILE. To get a description of these features, enter Forth mode and type |
@kbd{C-h m}. |
@kbd{C-h m}. |
|
|
|
@cindex source location of error or debugging output in Emacs |
|
@cindex error output, finding the source location in Emacs |
|
@cindex debugging output, finding the source location in Emacs |
In addition, Gforth supports Emacs quite well: The source code locations |
In addition, Gforth supports Emacs quite well: The source code locations |
given in error messages, debugging output (from @code{~~}) and failed |
given in error messages, debugging output (from @code{~~}) and failed |
assertion messages are in the right format for Emacs' compilation mode |
assertion messages are in the right format for Emacs' compilation mode |
Line 3227 Manual}) so the source location correspo
|
Line 4356 Manual}) so the source location correspo
|
message is only a few keystrokes away (@kbd{C-x `} for the next error, |
message is only a few keystrokes away (@kbd{C-x `} for the next error, |
@kbd{C-c C-c} for the error under the cursor). |
@kbd{C-c C-c} for the error under the cursor). |
|
|
|
@cindex @file{TAGS} file |
|
@cindex @file{etags.fs} |
|
@cindex viewing the source of a word in Emacs |
Also, if you @code{include} @file{etags.fs}, a new @file{TAGS} file |
Also, if you @code{include} @file{etags.fs}, a new @file{TAGS} file |
(@pxref{Tags, , Tags Tables, emacs, Emacs Manual}) will be produced that |
(@pxref{Tags, , Tags Tables, emacs, Emacs Manual}) will be produced that |
contains the definitions of all words defined afterwards. You can then |
contains the definitions of all words defined afterwards. You can then |
find the source for a word using @kbd{M-.}. Note that emacs can use |
find the source for a word using @kbd{M-.}. Note that emacs can use |
several tags files at the same time (e.g., one for the Gforth sources |
several tags files at the same time (e.g., one for the Gforth sources |
and one for your program). |
and one for your program, @pxref{Select Tags Table,,Selecting a Tags |
|
Table,emacs, Emacs Manual}). The TAGS file for the preloaded words is |
|
@file{$(datadir)/gforth/$(VERSION)/TAGS} (e.g., |
|
@file{/usr/local/share/gforth/0.2.0/TAGS}). |
|
|
|
@cindex @file{.emacs} |
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 3242 file:
|
Line 4378 file:
|
(setq auto-mode-alist (cons '("\\.fs\\'" . forth-mode) auto-mode-alist)) |
(setq auto-mode-alist (cons '("\\.fs\\'" . forth-mode) auto-mode-alist)) |
@end example |
@end example |
|
|
@node Internals, Bugs, Emacs and Gforth, Top |
@node Image Files, Engine, Emacs and Gforth, Top |
@chapter Internals |
@chapter Image Files |
|
@cindex image files |
|
@cindex @code{.fi} files |
|
@cindex precompiled Forth code |
|
@cindex dictionary in persistent form |
|
@cindex persistent form of dictionary |
|
|
|
An image file is a file containing an image of the Forth dictionary, |
|
i.e., compiled Forth code and data residing in the dictionary. By |
|
convention, we use the extension @code{.fi} for image files. |
|
|
|
@menu |
|
* Image File Background:: Why have image files? |
|
* Non-Relocatable Image Files:: don't always work. |
|
* Data-Relocatable Image Files:: are better. |
|
* Fully Relocatable Image Files:: better yet. |
|
* Stack and Dictionary Sizes:: Setting the default sizes for an image. |
|
* Running Image Files:: @code{gforth -i @var{file}} or @var{file}. |
|
* Modifying the Startup Sequence:: and turnkey applications. |
|
@end menu |
|
|
|
@node Image File Background, Non-Relocatable Image Files, Image Files, Image Files |
|
@section Image File Background |
|
@cindex image file background |
|
|
|
Our Forth system consists not only of primitives, but also of |
|
definitions written in Forth. Since the Forth compiler itself belongs to |
|
those definitions, it is not possible to start the system with the |
|
primitives and the Forth source alone. Therefore we provide the Forth |
|
code as an image file in nearly executable form. At the start of the |
|
system a C routine loads the image file into memory, optionally |
|
relocates the addresses, then sets up the memory (stacks etc.) according |
|
to information in the image file, and starts executing Forth code. |
|
|
|
The image file variants represent different compromises between the |
|
goals of making it easy to generate image files and making them |
|
portable. |
|
|
|
@cindex relocation at run-time |
|
Win32Forth 3.4 and Mitch Bradleys @code{cforth} use relocation at |
|
run-time. This avoids many of the complications discussed below (image |
|
files are data relocatable without further ado), but costs performance |
|
(one addition per memory access). |
|
|
|
@cindex relocation at load-time |
|
By contrast, our loader performs relocation at image load time. The |
|
loader also has to replace tokens standing for primitive calls with the |
|
appropriate code-field addresses (or code addresses in the case of |
|
direct threading). |
|
|
|
There are three kinds of image files, with different degrees of |
|
relocatability: non-relocatable, data-relocatable, and fully relocatable |
|
image files. |
|
|
|
@cindex image file loader |
|
@cindex relocating loader |
|
@cindex loader for image files |
|
These image file variants have several restrictions in common; they are |
|
caused by the design of the image file loader: |
|
|
|
@itemize @bullet |
|
@item |
|
There is only one segment; in particular, this means, that an image file |
|
cannot represent @code{ALLOCATE}d memory chunks (and pointers to |
|
them). And the contents of the stacks are not represented, either. |
|
|
|
@item |
|
The only kinds of relocation supported are: adding the same offset to |
|
all cells that represent data addresses; and replacing special tokens |
|
with code addresses or with pieces of machine code. |
|
|
|
If any complex computations involving addresses are performed, the |
|
results cannot be represented in the image file. Several applications that |
|
use such computations come to mind: |
|
@itemize @minus |
|
@item |
|
Hashing addresses (or data structures which contain addresses) for table |
|
lookup. If you use Gforth's @code{table}s or @code{wordlist}s for this |
|
purpose, you will have no problem, because the hash tables are |
|
recomputed automatically when the system is started. If you use your own |
|
hash tables, you will have to do something similar. |
|
|
|
@item |
|
There's a cute implementation of doubly-linked lists that uses |
|
@code{XOR}ed addresses. You could represent such lists as singly-linked |
|
in the image file, and restore the doubly-linked representation on |
|
startup.@footnote{In my opinion, though, you should think thrice before |
|
using a doubly-linked list (whatever implementation).} |
|
|
|
@item |
|
The code addresses of run-time routines like @code{docol:} cannot be |
|
represented in the image file (because their tokens would be replaced by |
|
machine code in direct threaded implementations). As a workaround, |
|
compute these addresses at run-time with @code{>code-address} from the |
|
executions tokens of appropriate words (see the definitions of |
|
@code{docol:} and friends in @file{kernel.fs}). |
|
|
|
@item |
|
On many architectures addresses are represented in machine code in some |
|
shifted or mangled form. You cannot put @code{CODE} words that contain |
|
absolute addresses in this form in a relocatable image file. Workarounds |
|
are representing the address in some relative form (e.g., relative to |
|
the CFA, which is present in some register), or loading the address from |
|
a place where it is stored in a non-mangled form. |
|
@end itemize |
|
@end itemize |
|
|
|
@node Non-Relocatable Image Files, Data-Relocatable Image Files, Image File Background, Image Files |
|
@section Non-Relocatable Image Files |
|
@cindex non-relocatable image files |
|
@cindex image files, non-relocatable |
|
|
|
These files are simple memory dumps of the dictionary. They are specific |
|
to the executable (i.e., @file{gforth} file) they were created |
|
with. What's worse, they are specific to the place on which the |
|
dictionary resided when the image was created. Now, there is no |
|
guarantee that the dictionary will reside at the same place the next |
|
time you start Gforth, so there's no guarantee that a non-relocatable |
|
image will work the next time (Gforth will complain instead of crashing, |
|
though). |
|
|
|
You can create a non-relocatable image file with |
|
|
|
doc-savesystem |
|
|
|
@node Data-Relocatable Image Files, Fully Relocatable Image Files, Non-Relocatable Image Files, Image Files |
|
@section Data-Relocatable Image Files |
|
@cindex data-relocatable image files |
|
@cindex image files, data-relocatable |
|
|
|
These files contain relocatable data addresses, but fixed code addresses |
|
(instead of tokens). They are specific to the executable (i.e., |
|
@file{gforth} file) they were created with. For direct threading on some |
|
architectures (e.g., the i386), data-relocatable images do not work. You |
|
get a data-relocatable image, if you use @file{gforth-makeimage} with a |
|
Gforth binary that is not doubly indirect threaded (@pxref{Fully |
|
Relocatable Image Files}). |
|
|
|
@node Fully Relocatable Image Files, Stack and Dictionary Sizes, Data-Relocatable Image Files, Image Files |
|
@section Fully Relocatable Image Files |
|
@cindex fully relocatable image files |
|
@cindex image files, fully relocatable |
|
|
|
@cindex @file{kern*.fi}, relocatability |
|
@cindex @file{gforth.fi}, relocatability |
|
These image files have relocatable data addresses, and tokens for code |
|
addresses. They can be used with different binaries (e.g., with and |
|
without debugging) on the same machine, and even across machines with |
|
the same data formats (byte order, cell size, floating point |
|
format). However, they are usually specific to the version of Gforth |
|
they were created with. The files @file{gforth.fi} and @file{kernl*.fi} |
|
are fully relocatable. |
|
|
|
There are two ways to create a fully relocatable image file: |
|
|
|
@menu |
|
* gforth-makeimage:: The normal way |
|
* cross.fs:: The hard way |
|
@end menu |
|
|
|
@node gforth-makeimage, cross.fs, Fully Relocatable Image Files, Fully Relocatable Image Files |
|
@subsection @file{gforth-makeimage} |
|
@cindex @file{comp-image.fs} |
|
@cindex @file{gforth-makeimage} |
|
|
|
You will usually use @file{gforth-makeimage}. If you want to create an |
|
image @var{file} that contains everything you would load by invoking |
|
Gforth with @code{gforth @var{options}}, you simply say |
|
@example |
|
gforth-makeimage @var{file} @var{options} |
|
@end example |
|
|
|
E.g., if you want to create an image @file{asm.fi} that has the file |
|
@file{asm.fs} loaded in addition to the usual stuff, you could do it |
|
like this: |
|
|
|
@example |
|
gforth-makeimage asm.fi asm.fs |
|
@end example |
|
|
|
@file{gforth-makeimage} works like this: It produces two non-relocatable |
|
images for different addresses and then compares them. Its output |
|
reflects this: first you see the output (if any) of the two Gforth |
|
invocations that produce the nonrelocatable image files, then you see |
|
the output of the comparing program: It displays the offset used for |
|
data addresses and the offset used for code addresses; |
|
moreover, for each cell that cannot be represented correctly in the |
|
image files, it displays a line like the following one: |
|
|
|
@example |
|
78DC BFFFFA50 BFFFFA40 |
|
@end example |
|
|
|
This means that at offset $78dc from @code{forthstart}, one input image |
|
contains $bffffa50, and the other contains $bffffa40. Since these cells |
|
cannot be represented correctly in the output image, you should examine |
|
these places in the dictionary and verify that these cells are dead |
|
(i.e., not read before they are written). |
|
|
|
\cindex @code{savesystem} during @file{gforth-makeimage} |
|
\cindex @code{bye} during @file{gforth-makeimage} |
|
\cindex doubly indirect threaded code |
|
\cindex environment variable @code{GFORTHD} |
|
\cindex @code{GFORTHD} environment variable |
|
\cindex @code{gforth-ditc} |
|
There are a few wrinkles: After processing the passed @var{options}, the |
|
words @code{savesystem} and @code{bye} must be visible. A special doubly |
|
indirect threaded version of the @file{gforth} executable is used for |
|
creating the nonrelocatable images; you can pass the exact filename of |
|
this executable through the environment variable @code{GFORTHD} |
|
(default: @file{gforth-ditc}); if you pass a version that is not doubly |
|
indirect threaded, you will not get a fully relocatable image, but a |
|
data-relocatable image (because there is no code address offset). |
|
|
|
@node cross.fs, , gforth-makeimage, Fully Relocatable Image Files |
|
@subsection @file{cross.fs} |
|
@cindex @file{cross.fs} |
|
@cindex cross-compiler |
|
@cindex metacompiler |
|
|
|
You can also use @code{cross}, a batch compiler that accepts a Forth-like |
|
programming language. This @code{cross} language has to be documented |
|
yet. |
|
|
|
@cindex target compiler |
|
@code{cross} also allows you to create image files for machines with |
|
different data sizes and data formats than the one used for generating |
|
the image file. You can also use it to create an application image that |
|
does not contain a Forth compiler. These features are bought with |
|
restrictions and inconveniences in programming. E.g., addresses have to |
|
be stored in memory with special words (@code{A!}, @code{A,}, etc.) in |
|
order to make the code relocatable. |
|
|
|
|
|
@node Stack and Dictionary Sizes, Running Image Files, Fully Relocatable Image Files, Image Files |
|
@section Stack and Dictionary Sizes |
|
@cindex image file, stack and dictionary sizes |
|
@cindex dictionary size default |
|
@cindex stack size default |
|
|
|
If you invoke Gforth with a command line flag for the size |
|
(@pxref{Invoking Gforth}), the size you specify is stored in the |
|
dictionary. If you save the dictionary with @code{savesystem} or create |
|
an image with @file{gforth-makeimage}, this size will become the default |
|
for the resulting image file. E.g., the following will create a |
|
fully relocatable version of gforth.fi with a 1MB dictionary: |
|
|
|
@example |
|
gforth-makeimage gforth.fi -m 1M |
|
@end example |
|
|
|
In other words, if you want to set the default size for the dictionary |
|
and the stacks of an image, just invoke @file{gforth-makeimage} with the |
|
appropriate options when creating the image. |
|
|
|
@cindex stack size, cache-friendly |
|
Note: For cache-friendly behaviour (i.e., good performance), you should |
|
make the sizes of the stacks modulo, say, 2K, somewhat different. E.g., |
|
the default stack sizes are: data: 16k (mod 2k=0); fp: 15.5k (mod |
|
2k=1.5k); return: 15k(mod 2k=1k); locals: 14.5k (mod 2k=0.5k). |
|
|
|
@node Running Image Files, Modifying the Startup Sequence, Stack and Dictionary Sizes, Image Files |
|
@section Running Image Files |
|
@cindex running image files |
|
@cindex invoking image files |
|
@cindex image file invocation |
|
|
|
@cindex -i, invoke image file |
|
@cindex --image file, invoke image file |
|
You can invoke Gforth with an image file @var{image} instead of the |
|
default @file{gforth.fi} with the @code{-i} flag (@pxref{Invoking Gforth}): |
|
@example |
|
gforth -i @var{image} |
|
@end example |
|
|
|
@cindex executable image file |
|
@cindex image files, executable |
|
If your operating system supports starting scripts with a line of the |
|
form @code{#! ...}, you can make your image file executable, and you'll |
|
just have to type the image file name to start Gforth with this image |
|
file (note that the file extension @code{.fi} is just a convention). |
|
|
|
I.e., in most Unix systems, you just have to make the image file |
|
@var{image} executable with |
|
|
|
@example |
|
chmod +x @var{image} |
|
@end example |
|
|
|
and then you can invoke it by simply typing @var{image} instead of |
|
@code{gforth -i @var{image}}. |
|
|
|
@node Modifying the Startup Sequence, , Running Image Files, Image Files |
|
@section Modifying the Startup Sequence |
|
@cindex startup sequence for image file |
|
@cindex image file initialization sequence |
|
@cindex initialization sequence of image file |
|
|
|
You can add your own initialization to the startup sequence through the |
|
deferred word |
|
|
|
doc-'cold |
|
|
|
@code{'cold} is invoked just before the image-specific command line |
|
processing (by default, loading files and evaluating (@code{-e}) strings) |
|
starts. |
|
|
|
A sequence for adding your initialization usually looks like this: |
|
|
|
@example |
|
:noname |
|
Defers 'cold \ do other initialization stuff (e.g., rehashing wordlists) |
|
... \ your stuff |
|
; IS 'cold |
|
@end example |
|
|
|
@cindex turnkey image files |
|
@cindex image files, turnkey applications |
|
You can make a turnkey image by letting @code{'cold} execute a word |
|
(your turnkey application) that never returns; instead, it exits Gforth |
|
via @code{bye} or @code{throw}. |
|
|
|
@c ****************************************************************** |
|
@node Engine, Bugs, Image Files, Top |
|
@chapter Engine |
|
@cindex engine |
|
@cindex virtual machine |
|
|
Reading this section is not necessary for programming with Gforth. It |
Reading this section is not necessary for programming with Gforth. It |
should be helpful for finding your way in the Gforth sources. |
may be helpful for finding your way in the Gforth sources. |
|
|
The ideas in this section have also been published in the papers |
The ideas in this section have also been published in the papers |
@cite{ANS fig/GNU/??? Forth} (in German) by Bernd Paysan, presented at |
@cite{ANS fig/GNU/??? Forth} (in German) by Bernd Paysan, presented at |
Line 3258 Ertl, presented at EuroForth '93; the la
|
Line 4720 Ertl, presented at EuroForth '93; the la
|
* Portability:: |
* Portability:: |
* Threading:: |
* Threading:: |
* Primitives:: |
* Primitives:: |
* System Architecture:: |
|
* Performance:: |
* Performance:: |
@end menu |
@end menu |
|
|
@node Portability, Threading, Internals, Internals |
@node Portability, Threading, Engine, Engine |
@section Portability |
@section Portability |
|
@cindex engine portability |
|
|
One of the main goals of the effort is availability across a wide range |
One of the main goals of the effort is availability across a wide range |
of personal machines. fig-Forth, and, to a lesser extent, F83, achieved |
of personal machines. fig-Forth, and, to a lesser extent, F83, achieved |
Line 3271 this goal by manually coding the engine
|
Line 4733 this goal by manually coding the engine
|
then-popular processors. This approach is very labor-intensive and the |
then-popular processors. This approach is very labor-intensive and the |
results are short-lived due to progress in computer architecture. |
results are short-lived due to progress in computer architecture. |
|
|
|
@cindex C, using C for the engine |
Others have avoided this problem by coding in C, e.g., Mitch Bradley |
Others have avoided this problem by coding in C, e.g., Mitch Bradley |
(cforth), Mikael Patel (TILE) and Dirk Zoller (pfe). This approach is |
(cforth), Mikael Patel (TILE) and Dirk Zoller (pfe). This approach is |
particularly popular for UNIX-based Forths due to the large variety of |
particularly popular for UNIX-based Forths due to the large variety of |
Line 3278 architectures of UNIX machines. Unfortun
|
Line 4741 architectures of UNIX machines. Unfortun
|
does not mix well with the goals of efficiency and with using |
does not mix well with the goals of efficiency and with using |
traditional techniques: Indirect or direct threading cannot be expressed |
traditional techniques: Indirect or direct threading cannot be expressed |
in C, and switch threading, the fastest technique available in C, is |
in C, and switch threading, the fastest technique available in C, is |
significantly slower. Another problem with C is that it's very |
significantly slower. Another problem with C is that it is very |
cumbersome to express double integer arithmetic. |
cumbersome to express double integer arithmetic. |
|
|
|
@cindex GNU C for the engine |
|
@cindex long long |
Fortunately, there is a portable language that does not have these |
Fortunately, there is a portable language that does not have these |
limitations: GNU C, the version of C processed by the GNU C compiler |
limitations: GNU C, the version of C processed by the GNU C compiler |
(@pxref{C Extensions, , Extensions to the C Language Family, gcc.info, |
(@pxref{C Extensions, , Extensions to the C Language Family, gcc.info, |
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 |
the code produced by the compiler and eliminated most compiler-induced |
the code produced by the compiler and eliminated most compiler-induced |
inefficiencies by appropriate changes in the source-code. |
inefficiencies by appropriate changes in the source code. |
|
|
|
@cindex explicit register declarations |
|
@cindex --enable-force-reg, configuration flag |
|
@cindex -DFORCE_REG |
However, register allocation cannot be portably influenced by the |
However, register allocation cannot be portably influenced by the |
programmer, leading to some inefficiencies on register-starved |
programmer, leading to some inefficiencies on register-starved |
machines. We use explicit register declarations (@pxref{Explicit Reg |
machines. We use explicit register declarations (@pxref{Explicit Reg |
Vars, , Variables in Specified Registers, gcc.info, GNU C Manual}) to |
Vars, , Variables in Specified Registers, gcc.info, GNU C Manual}) to |
improve the speed on some machines. They are turned on by using the |
improve the speed on some machines. They are turned on by using the |
@code{gcc} switch @code{-DFORCE_REG}. Unfortunately, this feature not |
configuration flag @code{--enable-force-reg} (@code{gcc} switch |
only depends on the machine, but also on the compiler version: On some |
@code{-DFORCE_REG}). Unfortunately, this feature not only depends on the |
machines some compiler versions produce incorrect code when certain |
machine, but also on the compiler version: On some machines some |
explicit register declarations are used. So by default |
compiler versions produce incorrect code when certain explicit register |
@code{-DFORCE_REG} is not used. |
declarations are used. So by default @code{-DFORCE_REG} is not used. |
|
|
@node Threading, Primitives, Portability, Internals |
@node Threading, Primitives, Portability, Engine |
@section Threading |
@section Threading |
|
@cindex inner interpreter implementation |
|
@cindex threaded code implementation |
|
|
|
@cindex labels as values |
GNU C's labels as values extension (available since @code{gcc-2.0}, |
GNU C's labels as values extension (available since @code{gcc-2.0}, |
@pxref{Labels as Values, , Labels as Values, gcc.info, GNU C Manual}) |
@pxref{Labels as Values, , Labels as Values, gcc.info, GNU C Manual}) |
makes it possible to take the address of @var{label} by writing |
makes it possible to take the address of @var{label} by writing |
Line 3319 makes it possible to take the address of
|
Line 4796 makes it possible to take the address of
|
@code{goto *@var{address}}. I.e., @code{goto *&&x} is the same as |
@code{goto *@var{address}}. I.e., @code{goto *&&x} is the same as |
@code{goto x}. |
@code{goto x}. |
|
|
|
@cindex NEXT, indirect threaded |
|
@cindex indirect threaded inner interpreter |
|
@cindex inner interpreter, indirect threaded |
With this feature an indirect threaded NEXT looks like: |
With this feature an indirect threaded NEXT looks like: |
@example |
@example |
cfa = *ip++; |
cfa = *ip++; |
ca = *cfa; |
ca = *cfa; |
goto *ca; |
goto *ca; |
@end example |
@end example |
|
@cindex instruction pointer |
For those unfamiliar with the names: @code{ip} is the Forth instruction |
For those unfamiliar with the names: @code{ip} is the Forth instruction |
pointer; the @code{cfa} (code-field address) corresponds to ANS Forths |
pointer; the @code{cfa} (code-field address) corresponds to ANS Forths |
execution token and points to the code field of the next word to be |
execution token and points to the code field of the next word to be |
Line 3332 executed; The @code{ca} (code address) f
|
Line 4813 executed; The @code{ca} (code address) f
|
executable code, e.g., a primitive or the colon definition handler |
executable code, e.g., a primitive or the colon definition handler |
@code{docol}. |
@code{docol}. |
|
|
|
@cindex NEXT, direct threaded |
|
@cindex direct threaded inner interpreter |
|
@cindex inner interpreter, direct threaded |
Direct threading is even simpler: |
Direct threading is even simpler: |
@example |
@example |
ca = *ip++; |
ca = *ip++; |
Line 3349 Of course we have packaged the whole thi
|
Line 4833 Of course we have packaged the whole thi
|
|
|
@node Scheduling, Direct or Indirect Threaded?, Threading, Threading |
@node Scheduling, Direct or Indirect Threaded?, Threading, Threading |
@subsection Scheduling |
@subsection Scheduling |
|
@cindex inner interpreter optimization |
|
|
There is a little complication: Pipelined and superscalar processors, |
There is a little complication: Pipelined and superscalar processors, |
i.e., RISC and some modern CISC machines can process independent |
i.e., RISC and some modern CISC machines can process independent |
Line 3388 switch is on by default on machines that
|
Line 4873 switch is on by default on machines that
|
|
|
@node Direct or Indirect Threaded?, DOES>, Scheduling, Threading |
@node Direct or Indirect Threaded?, DOES>, Scheduling, Threading |
@subsection Direct or Indirect Threaded? |
@subsection Direct or Indirect Threaded? |
|
@cindex threading, direct or indirect? |
|
|
|
@cindex -DDIRECT_THREADED |
Both! After packaging the nasty details in macro definitions we |
Both! After packaging the nasty details in macro definitions we |
realized that we could switch between direct and indirect threading by |
realized that we could switch between direct and indirect threading by |
simply setting a compilation flag (@code{-DDIRECT_THREADED}) and |
simply setting a compilation flag (@code{-DDIRECT_THREADED}) and |
Line 3396 defining a few machine-specific macros f
|
Line 4883 defining a few machine-specific macros f
|
On the Forth level we also offer access words that hide the |
On the Forth level we also offer access words that hide the |
differences between the threading methods (@pxref{Threading Words}). |
differences between the threading methods (@pxref{Threading Words}). |
|
|
Indirect threading is implemented completely |
Indirect threading is implemented completely machine-independently. |
machine-independently. Direct threading needs routines for creating |
Direct threading needs routines for creating jumps to the executable |
jumps to the executable code (e.g. to docol or dodoes). These routines |
code (e.g. to docol or dodoes). These routines are inherently |
are inherently machine-dependent, but they do not amount to many source |
machine-dependent, but they do not amount to many source lines. I.e., |
lines. I.e., even porting direct threading to a new machine is a small |
even porting direct threading to a new machine is a small effort. |
effort. |
|
|
@cindex --enable-indirect-threaded, configuration flag |
|
@cindex --enable-direct-threaded, configuration flag |
|
The default threading method is machine-dependent. You can enforce a |
|
specific threading method when building Gforth with the configuration |
|
flag @code{--enable-direct-threaded} or |
|
@code{--enable-indirect-threaded}. Note that direct threading is not |
|
supported on all machines. |
|
|
@node DOES>, , Direct or Indirect Threaded?, Threading |
@node DOES>, , Direct or Indirect Threaded?, Threading |
@subsection DOES> |
@subsection DOES> |
|
@cindex @code{DOES>} implementation |
|
|
|
@cindex dodoes routine |
|
@cindex DOES-code |
One of the most complex parts of a Forth engine is @code{dodoes}, i.e., |
One of the most complex parts of a Forth engine is @code{dodoes}, i.e., |
the chunk of code executed by every word defined by a |
the chunk of code executed by every word defined by a |
@code{CREATE}...@code{DOES>} pair. The main problem here is: How to find |
@code{CREATE}...@code{DOES>} pair. The main problem here is: How to find |
the Forth code to be executed, i.e. the code after the @code{DOES>} (the |
the Forth code to be executed, i.e. the code after the |
DOES-code)? There are two solutions: |
@code{DOES>} (the DOES-code)? There are two solutions: |
|
|
In fig-Forth the code field points directly to the dodoes and the |
In fig-Forth the code field points directly to the dodoes and the |
DOES-code address is stored in the cell after the code address |
DOES-code address is stored in the cell after the code address (i.e. at |
(i.e. at cfa cell+). It may seem that this solution is illegal in the |
@code{@var{cfa} cell+}). It may seem that this solution is illegal in |
Forth-79 and all later standards, because in fig-Forth this address |
the Forth-79 and all later standards, because in fig-Forth this address |
lies in the body (which is illegal in these standards). However, by |
lies in the body (which is illegal in these standards). However, by |
making the code field larger for all words this solution becomes legal |
making the code field larger for all words this solution becomes legal |
again. We use this approach for the indirect threaded version. Leaving |
again. We use this approach for the indirect threaded version and for |
a cell unused in most words is a bit wasteful, but on the machines we |
direct threading on some machines. Leaving a cell unused in most words |
are targetting this is hardly a problem. The other reason for having a |
is a bit wasteful, but on the machines we are targeting this is hardly a |
code field size of two cells is to avoid having different image files |
problem. The other reason for having a code field size of two cells is |
for direct and indirect threaded systems (@pxref{System Architecture}). |
to avoid having different image files for direct and indirect threaded |
|
systems (direct threaded systems require two-cell code fields on many |
|
machines). |
|
|
|
@cindex DOES-handler |
The other approach is that the code field points or jumps to the cell |
The other approach is that the code field points or jumps to the cell |
after @code{DOES}. In this variant there is a jump to @code{dodoes} at |
after @code{DOES}. In this variant there is a jump to @code{dodoes} at |
this address. @code{dodoes} can then get the DOES-code address by |
this address (the DOES-handler). @code{dodoes} can then get the |
computing the code address, i.e., the address of the jump to dodoes, |
DOES-code address by computing the code address, i.e., the address of |
and add the length of that jump field. A variant of this is to have a |
the jump to dodoes, and add the length of that jump field. A variant of |
call to @code{dodoes} after the @code{DOES>}; then the return address |
this is to have a call to @code{dodoes} after the @code{DOES>}; then the |
(which can be found in the return register on RISCs) is the DOES-code |
return address (which can be found in the return register on RISCs) is |
address. Since the two cells available in the code field are usually |
the DOES-code address. Since the two cells available in the code field |
used up by the jump to the code address in direct threading, we use |
are used up by the jump to the code address in direct threading on many |
this approach for direct threading. We did not want to add another |
architectures, we use this approach for direct threading on these |
cell to the code field. |
architectures. We did not want to add another cell to the code field. |
|
|
@node Primitives, System Architecture, Threading, Internals |
@node Primitives, Performance, Threading, Engine |
@section Primitives |
@section Primitives |
|
@cindex primitives, implementation |
|
@cindex virtual machine instructions, implementation |
|
|
@menu |
@menu |
* Automatic Generation:: |
* Automatic Generation:: |
Line 3446 cell to the code field.
|
Line 4949 cell to the code field.
|
|
|
@node Automatic Generation, TOS Optimization, Primitives, Primitives |
@node Automatic Generation, TOS Optimization, Primitives, Primitives |
@subsection Automatic Generation |
@subsection Automatic Generation |
|
@cindex primitives, automatic generation |
|
|
|
@cindex @file{prims2x.fs} |
Since the primitives are implemented in a portable language, there is no |
Since the primitives are implemented in a portable language, there is no |
longer any need to minimize the number of primitives. On the contrary, |
longer any need to minimize the number of primitives. On the contrary, |
having many primitives is an advantage: speed. In order to reduce the |
having many primitives has an advantage: speed. In order to reduce the |
number of errors in primitives and to make programming them easier, we |
number of errors in primitives and to make programming them easier, we |
provide a tool, the primitive generator (@file{prims2x.fs}), that |
provide a tool, the primitive generator (@file{prims2x.fs}), that |
automatically generates most (and sometimes all) of the C code for a |
automatically generates most (and sometimes all) of the C code for a |
primitive from the stack effect notation. The source for a primitive |
primitive from the stack effect notation. The source for a primitive |
has the following form: |
has the following form: |
|
|
|
@cindex primitive source format |
@format |
@format |
@var{Forth-name} @var{stack-effect} @var{category} [@var{pronounc.}] |
@var{Forth-name} @var{stack-effect} @var{category} [@var{pronounc.}] |
[@code{""}@var{glossary entry}@code{""}] |
[@code{""}@var{glossary entry}@code{""}] |
Line 3525 fall through to NEXT.
|
Line 5031 fall through to NEXT.
|
|
|
@node TOS Optimization, Produced code, Automatic Generation, Primitives |
@node TOS Optimization, Produced code, Automatic Generation, Primitives |
@subsection TOS Optimization |
@subsection TOS Optimization |
|
@cindex TOS optimization for primitives |
|
@cindex primitives, keeping the TOS in a register |
|
|
An important optimization for stack machine emulators, e.g., Forth |
An important optimization for stack machine emulators, e.g., Forth |
engines, is keeping one or more of the top stack items in |
engines, is keeping one or more of the top stack items in |
registers. If a word has the stack effect @var{in1}...@var{inx} @code{--} |
registers. If a word has the stack effect @var{in1}...@var{inx} @code{--} |
@var{out1}...@var{outy}, keeping the top @var{n} items in registers |
@var{out1}...@var{outy}, keeping the top @var{n} items in registers |
@itemize |
@itemize @bullet |
@item |
@item |
is better than keeping @var{n-1} items, if @var{x>=n} and @var{y>=n}, |
is better than keeping @var{n-1} items, if @var{x>=n} and @var{y>=n}, |
due to fewer loads from and stores to the stack. |
due to fewer loads from and stores to the stack. |
Line 3538 due to fewer loads from and stores to th
|
Line 5046 due to fewer loads from and stores to th
|
@var{y<n}, due to additional moves between registers. |
@var{y<n}, due to additional moves between registers. |
@end itemize |
@end itemize |
|
|
|
@cindex -DUSE_TOS |
|
@cindex -DUSE_NO_TOS |
In particular, keeping one item in a register is never a disadvantage, |
In particular, keeping one item in a register is never a disadvantage, |
if there are enough registers. Keeping two items in registers is a |
if there are enough registers. Keeping two items in registers is a |
disadvantage for frequent words like @code{?branch}, constants, |
disadvantage for frequent words like @code{?branch}, constants, |
Line 3550 otherwise it is a macro that expands int
|
Line 5060 otherwise it is a macro that expands int
|
GNU C compiler tries to keep simple variables like @code{TOS} in |
GNU C compiler tries to keep simple variables like @code{TOS} in |
registers, and it usually succeeds, if there are enough registers. |
registers, and it usually succeeds, if there are enough registers. |
|
|
|
@cindex -DUSE_FTOS |
|
@cindex -DUSE_NO_FTOS |
The primitive generator performs the TOS optimization for the |
The primitive generator performs the TOS optimization for the |
floating-point stack, too (@code{-DUSE_FTOS}). For floating-point |
floating-point stack, too (@code{-DUSE_FTOS}). For floating-point |
operations the benefit of this optimization is even larger: |
operations the benefit of this optimization is even larger: |
Line 3564 The TOS optimization makes the automatic
|
Line 5076 The TOS optimization makes the automatic
|
bit more complicated. Just replacing all occurrences of @code{sp[0]} by |
bit more complicated. Just replacing all occurrences of @code{sp[0]} by |
@code{TOS} is not sufficient. There are some special cases to |
@code{TOS} is not sufficient. There are some special cases to |
consider: |
consider: |
@itemize |
@itemize @bullet |
@item In the case of @code{dup ( w -- w w )} the generator must not |
@item In the case of @code{dup ( w -- w w )} the generator must not |
eliminate the store to the original location of the item on the stack, |
eliminate the store to the original location of the item on the stack, |
if the TOS optimization is turned on. |
if the TOS optimization is turned on. |
Line 3577 effect @code{--} no stores or loads shou
|
Line 5089 effect @code{--} no stores or loads shou
|
|
|
@node Produced code, , TOS Optimization, Primitives |
@node Produced code, , TOS Optimization, Primitives |
@subsection Produced code |
@subsection Produced code |
|
@cindex primitives, assembly code listing |
|
|
|
@cindex @file{engine.s} |
To see what assembly code is produced for the primitives on your machine |
To see what assembly code is produced for the primitives on your machine |
with your compiler and your flag settings, type @code{make engine.s} and |
with your compiler and your flag settings, type @code{make engine.s} and |
look at the resulting file @file{engine.s}. |
look at the resulting file @file{engine.s}. |
|
|
@node System Architecture, Performance, Primitives, Internals |
@node Performance, , Primitives, Engine |
@section System Architecture |
|
|
|
Our Forth system consists not only of primitives, but also of |
|
definitions written in Forth. Since the Forth compiler itself belongs |
|
to those definitions, it is not possible to start the system with the |
|
primitives and the Forth source alone. Therefore we provide the Forth |
|
code as an image file in nearly executable form. At the start of the |
|
system a C routine loads the image file into memory, sets up the |
|
memory (stacks etc.) according to information in the image file, and |
|
starts executing Forth code. |
|
|
|
The image file format is a compromise between the goals of making it |
|
easy to generate image files and making them portable. The easiest way |
|
to generate an image file is to just generate a memory dump. However, |
|
this kind of image file cannot be used on a different machine, or on |
|
the next version of the engine on the same machine, it even might not |
|
work with the same engine compiled by a different version of the C |
|
compiler. We would like to have as few versions of the image file as |
|
possible, because we do not want to distribute many versions of the |
|
same image file, and to make it easy for the users to use their image |
|
files on many machines. We currently need to create a different image |
|
file for machines with different cell sizes and different byte order |
|
(little- or big-endian)@footnote{We are considering adding information to the |
|
image file that enables the loader to change the byte order.}. |
|
|
|
Forth code that is going to end up in a portable image file has to |
|
comply to some restrictions: addresses have to be stored in memory with |
|
special words (@code{A!}, @code{A,}, etc.) in order to make the code |
|
relocatable. Cells, floats, etc., have to be stored at the natural |
|
alignment boundaries@footnote{E.g., store floats (8 bytes) at an address |
|
dividable by~8. This happens automatically in our system when you use |
|
the ANS Forth alignment words.}, in order to avoid alignment faults on |
|
machines with stricter alignment. The image file is produced by a |
|
metacompiler (@file{cross.fs}). |
|
|
|
So, unlike the image file of Mitch Bradleys @code{cforth}, our image |
|
file is not directly executable, but has to undergo some manipulations |
|
during loading. Address relocation is performed at image load-time, not |
|
at run-time. The loader also has to replace tokens standing for |
|
primitive calls with the appropriate code-field addresses (or code |
|
addresses in the case of direct threading). |
|
|
|
@node Performance, , System Architecture, Internals |
|
@section Performance |
@section Performance |
|
@cindex performance of some Forth interpreters |
|
@cindex engine performance |
|
@cindex benchmarking Forth systems |
|
@cindex Gforth performance |
|
|
On RISCs the Gforth engine is very close to optimal; i.e., it is usually |
On RISCs the Gforth engine is very close to optimal; i.e., it is usually |
impossible to write a significantly faster engine. |
impossible to write a significantly faster engine. |
Line 3639 and hand-tuned it for the 486; this syst
|
Line 5114 and hand-tuned it for the 486; this syst
|
Sieve benchmark on a 486DX2/66 than Gforth compiled with |
Sieve benchmark on a 486DX2/66 than Gforth compiled with |
@code{gcc-2.6.3} with @code{-DFORCE_REG}. |
@code{gcc-2.6.3} with @code{-DFORCE_REG}. |
|
|
|
@cindex Win32Forth performance |
|
@cindex NT Forth performance |
|
@cindex eforth performance |
|
@cindex ThisForth performance |
|
@cindex PFE performance |
|
@cindex TILE performance |
However, this potential advantage of assembly language implementations |
However, this potential advantage of assembly language implementations |
is not necessarily realized in complete Forth systems: We compared |
is not necessarily realized in complete Forth systems: We compared |
Gforth (compiled with @code{gcc-2.6.3} and @code{-DFORCE_REG}) with |
Gforth (direct threaded, compiled with @code{gcc-2.6.3} and |
Win32Forth 1.2093 and LMI's NT Forth (Beta, May 1994), two systems |
@code{-DFORCE_REG}) with Win32Forth 1.2093, LMI's NT Forth (Beta, May |
written in assembly, and with two systems written in C: PFE-0.9.11 |
1994) and Eforth (with and without peephole (aka pinhole) optimization |
(compiled with @code{gcc-2.6.3} with the default configuration for |
of the threaded code); all these systems were written in assembly |
Linux: @code{-O2 -fomit-frame-pointer -DUSE_REGS}) and ThisForth Beta |
language. We also compared Gforth with three systems written in C: |
(compiled with gcc-2.6.3 -O3 -fomit-frame-pointer). We benchmarked |
PFE-0.9.14 (compiled with @code{gcc-2.6.3} with the default |
Gforth, PFE and ThisForth on a 486DX2/66 under Linux. Kenneth O'Heskin |
configuration for Linux: @code{-O2 -fomit-frame-pointer -DUSE_REGS |
kindly provided the results for Win32Forth and NT Forth on a 486DX2/66 |
-DUNROLL_NEXT}), ThisForth Beta (compiled with gcc-2.6.3 -O3 |
with similar memory performance under Windows NT. |
-fomit-frame-pointer; ThisForth employs peephole optimization of the |
|
threaded code) and TILE (compiled with @code{make opt}). We benchmarked |
|
Gforth, PFE, ThisForth and TILE on a 486DX2/66 under Linux. Kenneth |
|
O'Heskin kindly provided the results for Win32Forth and NT Forth on a |
|
486DX2/66 with similar memory performance under Windows NT. Marcel |
|
Hendrix ported Eforth to Linux, then extended it to run the benchmarks, |
|
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 |
been translated into Forth by Martin Fraeman; we used the versions |
been translated into Forth by Martin Fraeman; we used the versions |
included in the TILE Forth package; and a recursive Fibonacci number |
included in the TILE Forth package, but with bigger data set sizes; and |
computation for benchmarking calling performance. The following table shows |
a recursive Fibonacci number computation for benchmarking calling |
the time taken for the benchmarks scaled by the time taken by Gforth (in |
performance. The following table shows the time taken for the benchmarks |
other words, it shows the speedup factor that Gforth achieved over the |
scaled by the time taken by Gforth (in other words, it shows the speedup |
other systems). |
factor that Gforth achieved over the other systems). |
|
|
@example |
@example |
relative Win32- NT This- |
relative Win32- NT eforth This- |
time Gforth Forth Forth PFE Forth |
time Gforth Forth Forth eforth +opt PFE Forth TILE |
sieve 1.00 1.30 1.07 1.67 2.98 |
sieve 1.00 1.39 1.14 1.39 0.85 1.58 3.18 8.58 |
bubble 1.00 1.30 1.40 1.66 |
bubble 1.00 1.31 1.41 1.48 0.88 1.50 3.88 |
matmul 1.00 1.40 1.29 2.24 |
matmul 1.00 1.47 1.35 1.46 0.74 1.58 4.09 |
fib 1.00 1.44 1.26 1.82 2.82 |
fib 1.00 1.52 1.34 1.22 0.86 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 3676 not written optimally for the 486 (e.g.,
|
Line 5164 not written optimally for the 486 (e.g.,
|
instruction). In addition, Win32Forth uses a comfortable, but costly |
instruction). In addition, Win32Forth uses a comfortable, but costly |
method for relocating the Forth image: like @code{cforth}, it computes |
method for relocating the Forth image: like @code{cforth}, it computes |
the actual addresses at run time, resulting in two address computations |
the actual addresses at run time, resulting in two address computations |
per NEXT (@pxref{System Architecture}). |
per NEXT (@pxref{Image File Background}). |
|
|
The speedup of Gforth over PFE and ThisForth can be easily explained |
Only Eforth with the peephole optimizer performs comparable to |
with the self-imposed restriction to standard C (although the measured |
Gforth. The speedups achieved with peephole optimization of threaded |
implementation of PFE uses a GNU C extension: global register |
code are quite remarkable. Adding a peephole optimizer to Gforth should |
variables), which makes efficient threading impossible. Moreover, |
cause similar speedups. |
current C compilers have a hard time optimizing other aspects of the |
|
ThisForth source. |
The speedup of Gforth over PFE, ThisForth and TILE can be easily |
|
explained with the self-imposed restriction of the latter systems to |
|
standard C, which makes efficient threading impossible (however, the |
|
measured implementation of PFE uses a GNU C extension: @ref{Global Reg |
|
Vars, , Defining Global Register Variables, gcc.info, GNU C Manual}). |
|
Moreover, current C compilers have a hard time optimizing other aspects |
|
of the ThisForth and the TILE source. |
|
|
Note that the performance of Gforth on 386 architecture processors |
Note that the performance of Gforth on 386 architecture processors |
varies widely with the version of @code{gcc} used. E.g., @code{gcc-2.5.8} |
varies widely with the version of @code{gcc} used. E.g., @code{gcc-2.5.8} |
Line 3692 machine registers by itself and would no
|
Line 5186 machine registers by itself and would no
|
register declarations, giving a 1.3 times slower engine (on a 486DX2/66 |
register declarations, giving a 1.3 times slower engine (on a 486DX2/66 |
running the Sieve) than the one measured above. |
running the Sieve) than the one measured above. |
|
|
The numbers in this section have also been published in the paper |
Note also that there have been several releases of Win32Forth since the |
@cite{Translating Forth to Efficient C} by M. Anton Ertl and Martin |
release presented here, so the results presented here may have little |
Maierhofer, presented at EuroForth '95. It is available at |
predictive value for the performance of Win32Forth today. |
|
|
|
@cindex @file{Benchres} |
|
In @cite{Translating Forth to Efficient C} by M. Anton Ertl and Martin |
|
Maierhofer (presented at EuroForth '95), an indirect threaded version of |
|
Gforth is compared with Win32Forth, NT Forth, PFE, and ThisForth; that |
|
version of Gforth is 2%@minus{}8% slower on a 486 than the direct |
|
threaded version used here. The paper available at |
@*@file{http://www.complang.tuwien.ac.at/papers/ertl&maierhofer95.ps.gz}; |
@*@file{http://www.complang.tuwien.ac.at/papers/ertl&maierhofer95.ps.gz}; |
it also contains numbers for some native code systems. You can find |
it also contains numbers for some native code systems. You can find a |
numbers for Gforth on various machines in @file{Benchres}. |
newer version of these measurements at |
|
@file{http://www.complang.tuwien.ac.at/forth/performance.html}. You can |
|
find numbers for Gforth on various machines in @file{Benchres}. |
|
|
@node Bugs, Pedigree, Internals, Top |
@node Bugs, Origin, Engine, Top |
@chapter Bugs |
@chapter Bugs |
|
@cindex bug reporting |
|
|
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 |
installation options (send the @code{config.status} file), and a |
installation options (send the @file{config.status} file), and a |
complete list of changes you (or your installer) have made to the Gforth |
complete list of changes you (or your installer) have made to the Gforth |
sources (if any); it should contain a program (or a sequence of keyboard |
sources (if any); it should contain a program (or a sequence of keyboard |
commands) that reproduces the bug and a description of what you think |
commands) that reproduces the bug and a description of what you think |
Line 3719 For a thorough guide on reporting bugs r
|
Line 5223 For a thorough guide on reporting bugs r
|
to Report Bugs, gcc.info, GNU C Manual}. |
to Report Bugs, gcc.info, GNU C Manual}. |
|
|
|
|
@node Pedigree, Word Index, Bugs, Top |
@node Origin, Word Index, Bugs, Top |
@chapter Pedigree |
@chapter Authors and Ancestors of Gforth |
|
|
|
@section Authors and Contributors |
|
@cindex authors of Gforth |
|
@cindex contributors to Gforth |
|
|
|
The Gforth project was started in mid-1992 by Bernd Paysan and Anton |
|
Ertl. The third major author was Jens Wilke. Lennart Benschop (who was |
|
one of Gforth's first users, in mid-1993) and Stuart Ramsden inspired us |
|
with their continuous feedback. Lennart Benshop contributed |
|
@file{glosgen.fs}, while Stuart Ramsden has been working on automatic |
|
support for calling C libraries. Helpful comments also came from Paul |
|
Kleinrubatscher, Christian Pirker, Dirk Zoller, Marcel Hendrix, John |
|
Wavrik, Barrie Stott and Marc de Groot. |
|
|
|
Gforth also owes a lot to the authors of the tools we used (GCC, CVS, |
|
and autoconf, among others), and to the creators of the Internet: Gforth |
|
was developed across the Internet, and its authors have not met |
|
physically yet. |
|
|
|
@section Pedigree |
|
@cindex Pedigree of Gforth |
|
|
Gforth descends from BigForth (1993) and fig-Forth. Gforth and PFE (by |
Gforth descends from BigForth (1993) and fig-Forth. Gforth and PFE (by |
Dirk Zoller) will cross-fertilize each other. Of course, a significant |
Dirk Zoller) will cross-fertilize each other. Of course, a significant |
Line 3734 VolksForth descends from F83. It was wri
|
Line 5259 VolksForth descends from F83. It was wri
|
Pennemann, Georg Rehfeld and Dietrich Weineck for the C64 (called |
Pennemann, Georg Rehfeld and Dietrich Weineck for the C64 (called |
UltraForth there) in the mid-80s and ported to the Atari ST in 1986. |
UltraForth there) in the mid-80s and ported to the Atari ST in 1986. |
|
|
Hennry Laxen and Mike Perry wrote F83 as a model implementation of the |
Henry Laxen and Mike Perry wrote F83 as a model implementation of the |
Forth-83 standard. !! Pedigree? When? |
Forth-83 standard. !! Pedigree? When? |
|
|
A team led by Bill Ragsdale implemented fig-Forth on many processors in |
A team led by Bill Ragsdale implemented fig-Forth on many processors in |
Line 3742 A team led by Bill Ragsdale implemented
|
Line 5267 A team led by Bill Ragsdale implemented
|
implementation of fig-Forth for the 6502 based on microForth. |
implementation of fig-Forth for the 6502 based on microForth. |
|
|
The principal architect of microForth was Dean Sanderson. microForth was |
The principal architect of microForth was Dean Sanderson. microForth was |
FORTH, Inc.'s first off-the-shelf product. It was developped in 1976 for |
FORTH, Inc.'s first off-the-shelf product. It was developed in 1976 for |
the 1802, and subsequently implemented on the 8080, the 6800 and the |
the 1802, and subsequently implemented on the 8080, the 6800 and the |
Z80. |
Z80. |
|
|
All earlier Forth systems were custom-made, usually by Charles Moore, |
All earlier Forth systems were custom-made, usually by Charles Moore, |
who discovered (as he puts it) Forth in the late 60s. |
who discovered (as he puts it) Forth during the late 60s. The first full |
|
Forth existed in 1971. |
|
|
A part of the information in this section comes from @cite{The Evolution |
A part of the information in this section comes from @cite{The Evolution |
of Forth} by Elizabeth D. Rather, Donald R. Colburn and Charles |
of Forth} by Elizabeth D. Rather, Donald R. Colburn and Charles |
Line 3755 H. Moore, presented at the HOPL-II confe
|
Line 5281 H. Moore, presented at the HOPL-II confe
|
Notices 28(3), 1993. You can find more historical and genealogical |
Notices 28(3), 1993. You can find more historical and genealogical |
information about Forth there. |
information about Forth there. |
|
|
@node Word Index, Node Index, Pedigree, Top |
@node Word Index, Concept Index, Origin, Top |
@chapter Word Index |
@unnumbered Word Index |
|
|
This index is as incomplete as the manual. Each word is listed with |
This index is as incomplete as the manual. Each word is listed with |
stack effect and wordset. |
stack effect and wordset. |
|
|
@printindex fn |
@printindex fn |
|
|
@node Node Index, , Word Index, Top |
@node Concept Index, , Word Index, Top |
@chapter Node Index |
@unnumbered Concept and Word Index |
|
|
|
This index is as incomplete as the manual. Not all entries listed are |
|
present verbatim in the text. Only the names are listed for the words |
|
here. |
|
|
This index is even less complete than the manual. |
@printindex cp |
|
|
@contents |
@contents |
@bye |
@bye |