version 1.66, 2000/08/04 17:14:52
|
version 1.67, 2000/08/09 20:04:06
|
Line 221 Forth Tutorial
|
Line 221 Forth Tutorial
|
|
|
An Introduction to ANS Forth |
An Introduction to ANS Forth |
|
|
* Introducing the Text Interpreter:: |
* Introducing the Text Interpreter:: |
* Stacks and Postfix notation:: |
* Stacks and Postfix notation:: |
* Your first definition:: |
* Your first definition:: |
* How does that work?:: |
* How does that work?:: |
* Forth is written in Forth:: |
* Forth is written in Forth:: |
* Review - elements of a Forth system:: |
* Review - elements of a Forth system:: |
* Where to go next:: |
* Where to go next:: |
* Exercises:: |
* Exercises:: |
|
|
Forth Words |
Forth Words |
|
|
Line 262 Forth Words
|
Line 262 Forth Words
|
Arithmetic |
Arithmetic |
|
|
* Single precision:: |
* Single precision:: |
* Bitwise operations:: |
|
* Double precision:: Double-cell integer arithmetic |
* Double precision:: Double-cell integer arithmetic |
* Numeric comparison:: |
* Bitwise operations:: |
|
* Numeric comparison:: |
* Mixed precision:: Operations with single and double-cell integers |
* Mixed precision:: Operations with single and double-cell integers |
* Floating Point:: |
* Floating Point:: |
|
|
Line 290 Control Structures
|
Line 290 Control Structures
|
* Selection:: IF ... ELSE ... ENDIF |
* Selection:: IF ... ELSE ... ENDIF |
* Simple Loops:: BEGIN ... |
* Simple Loops:: BEGIN ... |
* Counted Loops:: DO |
* Counted Loops:: DO |
* Arbitrary control structures:: |
* Arbitrary control structures:: |
* Calls and returns:: |
* Calls and returns:: |
* Exception Handling:: |
* Exception Handling:: |
|
|
Defining Words |
Defining Words |
|
|
* CREATE:: |
* CREATE:: |
* Variables:: Variables and user variables |
* Variables:: Variables and user variables |
* Constants:: |
* Constants:: |
* Values:: Initialised variables |
* Values:: Initialised variables |
* Colon Definitions:: |
* Colon Definitions:: |
* Anonymous Definitions:: Definitions without names |
* Anonymous Definitions:: Definitions without names |
* User-defined Defining Words:: |
* User-defined Defining Words:: |
* Deferred words:: Allow forward references |
* Deferred words:: Allow forward references |
* Aliases:: |
* Aliases:: |
* Supplying names:: |
* Supplying names:: |
|
|
User-defined Defining Words |
User-defined Defining Words |
|
|
Line 315 User-defined Defining Words
|
Line 315 User-defined Defining Words
|
|
|
Interpretation and Compilation Semantics |
Interpretation and Compilation Semantics |
|
|
* Combined words:: |
* Combined words:: |
|
|
The Text Interpreter |
The Text Interpreter |
|
|
* Input Sources:: |
* Input Sources:: |
* Number Conversion:: |
* Number Conversion:: |
* Interpret/Compile states:: |
* Interpret/Compile states:: |
* Literals:: |
* Literals:: |
* Interpreter Directives:: |
* Interpreter Directives:: |
|
|
Word Lists |
Word Lists |
|
|
* Why use word lists?:: |
* Why use word lists?:: |
* Word list examples:: |
* Word list examples:: |
|
|
Files |
Files |
|
|
Line 346 Other I/O
|
Line 346 Other I/O
|
* Simple numeric output:: Predefined formats |
* Simple numeric output:: Predefined formats |
* Formatted numeric output:: Formatted (pictured) output |
* Formatted numeric output:: Formatted (pictured) output |
* String Formats:: How Forth stores strings in memory |
* String Formats:: How Forth stores strings in memory |
* Displaying characters and strings:: Other stuff |
* Displaying characters and strings:: Other stuff |
* Input:: Input |
* Input:: Input |
|
|
Programming Tools |
Programming Tools |
Line 411 The @file{objects.fs} model
|
Line 411 The @file{objects.fs} model
|
|
|
The @file{oof.fs} model |
The @file{oof.fs} model |
|
|
* Properties of the OOF model:: |
* Properties of the OOF model:: |
* Basic OOF Usage:: |
* Basic OOF Usage:: |
* The OOF base class:: |
* The OOF base class:: |
* Class Declaration:: |
* Class Declaration:: |
* Class Implementation:: |
* Class Implementation:: |
|
|
The @file{mini-oof.fs} model |
The @file{mini-oof.fs} model |
|
|
* Basic Mini-OOF Usage:: |
* Basic Mini-OOF Usage:: |
* Mini-OOF Example:: |
* Mini-OOF Example:: |
* Mini-OOF Implementation:: |
* Mini-OOF Implementation:: |
* Comparison with other object models:: |
|
|
|
Tools |
Tools |
|
|
Line 500 Image Files
|
Line 499 Image Files
|
|
|
* Image Licensing Issues:: Distribution terms for images. |
* Image Licensing Issues:: Distribution terms for images. |
* Image File Background:: Why have image files? |
* Image File Background:: Why have image files? |
* Non-Relocatable Image Files:: don't always work. |
* Non-Relocatable Image Files:: don't always work. |
* Data-Relocatable Image Files:: are better. |
* Data-Relocatable Image Files:: are better. |
* Fully Relocatable Image Files:: better yet. |
* Fully Relocatable Image Files:: better yet. |
* Stack and Dictionary Sizes:: Setting the default sizes for an image. |
* Stack and Dictionary Sizes:: Setting the default sizes for an image. |
* Running Image Files:: @code{gforth -i @i{file}} or @i{file}. |
* Running Image Files:: @code{gforth -i @i{file}} or @i{file}. |
* Modifying the Startup Sequence:: and turnkey applications. |
* Modifying the Startup Sequence:: and turnkey applications. |
Line 533 Primitives
|
Line 532 Primitives
|
|
|
Cross Compiler |
Cross Compiler |
|
|
* Using the Cross Compiler:: |
* Using the Cross Compiler:: |
* How the Cross Compiler Works:: |
* How the Cross Compiler Works:: |
|
|
Other Forth-related information |
Other Forth-related information |
|
|
* Internet resources:: |
* Internet resources:: |
* Books:: |
* Books:: |
* The Forth Interest Group:: |
* The Forth Interest Group:: |
* Conferences:: |
* Conferences:: |
|
|
@end detailmenu |
@end detailmenu |
@end menu |
@end menu |
Line 1398 gforthnrnh.fi -e bye} takes about 2.1ms
|
Line 1397 gforthnrnh.fi -e bye} takes about 2.1ms
|
@cindex Tutorial |
@cindex Tutorial |
@cindex Forth Tutorial |
@cindex Forth Tutorial |
|
|
|
@c Topics from nac's Introduction that could be mentioned: |
|
@c press <ret> after each line |
|
@c Prompt |
|
@c numbers vs. words in dictionary on text interpretation |
|
@c what happens on redefinition |
|
@c parsing words (in particular, defining words) |
|
|
This tutorial can be used with any ANS-compliant Forth; any |
This tutorial can be used with any ANS-compliant Forth; any |
Gforth-specific features are marked as such and you can skip them if you |
Gforth-specific features are marked as such and you can skip them if you |
work with another Forth. This tutorial does not explain all features of |
work with another Forth. This tutorial does not explain all features of |
Line 1558 The words @code{+}, @code{-}, @code{*},
|
Line 1564 The words @code{+}, @code{-}, @code{*},
|
operate on the top two stack items: |
operate on the top two stack items: |
|
|
@example |
@example |
2 2 + . |
2 2 .s |
|
+ .s |
|
. |
2 1 - . |
2 1 - . |
7 3 mod . |
7 3 mod . |
@end example |
@end example |
Line 3452 edit-compile-test cycle used by conventi
|
Line 3460 edit-compile-test cycle used by conventi
|
lead to great productivity improvements. |
lead to great productivity improvements. |
|
|
@menu |
@menu |
* Introducing the Text Interpreter:: |
* Introducing the Text Interpreter:: |
* Stacks and Postfix notation:: |
* Stacks and Postfix notation:: |
* Your first definition:: |
* Your first definition:: |
* How does that work?:: |
* How does that work?:: |
* Forth is written in Forth:: |
* Forth is written in Forth:: |
* Review - elements of a Forth system:: |
* Review - elements of a Forth system:: |
* Where to go next:: |
* Where to go next:: |
* Exercises:: |
* Exercises:: |
@end menu |
@end menu |
|
|
@comment ---------------------------------------------- |
@comment ---------------------------------------------- |
Line 4351 the exercises in a .fs file in the distr
|
Line 4359 the exercises in a .fs file in the distr
|
@cindex word glossary entry 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: |
|
|
@format |
@format |
@i{word} @i{Stack effect} @i{wordset} @i{pronunciation} |
@i{word} @i{Stack effect} @i{wordset} @i{pronunciation} |
Line 4387 stack effect is shown.
|
Line 4395 stack effect is shown.
|
How the word is pronounced. |
How the word is pronounced. |
|
|
@cindex wordset |
@cindex wordset |
|
@cindex environment wordset |
@item wordset |
@item wordset |
The ANS Forth standard is divided into several word sets. A standard |
The ANS Forth standard is divided into several word sets. A standard |
system need not support all of them. Therefore, in theory, the fewer |
system need not support all of them. Therefore, in theory, the fewer |
Line 4519 A Boolean flag is cell-sized. A cell wit
|
Line 4528 A Boolean flag is cell-sized. A cell wit
|
flag @code{false} and a flag with all bits set represents the flag |
flag @code{false} and a flag with all bits set represents the flag |
@code{true}. Words that check a flag (for example, @code{IF}) will treat |
@code{true}. Words that check a flag (for example, @code{IF}) will treat |
a cell that has @i{any} bit set as @code{true}. |
a cell that has @i{any} bit set as @code{true}. |
|
@c on and off to Memory? |
|
@c true and false to "Bitwise operations" or "Numeric comparison"? |
|
|
doc-true |
doc-true |
doc-false |
doc-false |
Line 4545 former, @pxref{Mixed precision}).
|
Line 4555 former, @pxref{Mixed precision}).
|
|
|
@menu |
@menu |
* Single precision:: |
* Single precision:: |
* Bitwise operations:: |
|
* Double precision:: Double-cell integer arithmetic |
* Double precision:: Double-cell integer arithmetic |
* Numeric comparison:: |
* Bitwise operations:: |
|
* Numeric comparison:: |
* Mixed precision:: Operations with single and double-cell integers |
* Mixed precision:: Operations with single and double-cell integers |
* Floating Point:: |
* Floating Point:: |
@end menu |
@end menu |
|
|
@node Single precision, Bitwise operations, Arithmetic, Arithmetic |
@node Single precision, Double precision, Arithmetic, Arithmetic |
@subsection Single precision |
@subsection Single precision |
@cindex single precision arithmetic words |
@cindex single precision arithmetic words |
|
|
By default, numbers in Forth are single-precision integers that are 1 |
@c !! cell undefined |
|
|
|
By default, numbers in Forth are single-precision integers that are one |
cell in size. They can be signed or unsigned, depending upon how you |
cell in size. They can be signed or unsigned, depending upon how you |
treat them. For the rules used by the text interpreter for recognising |
treat them. For the rules used by the text interpreter for recognising |
single-precision integers see @ref{Number Conversion}. |
single-precision integers see @ref{Number Conversion}. |
|
|
|
These words are all defined for signed operands, but some of them also |
|
work for unsigned numbers: @code{+}, @code{1+}, @code{-}, @code{1-}, |
|
@code{*}. |
|
|
doc-+ |
doc-+ |
doc-1+ |
doc-1+ |
Line 4574 doc-negate
|
Line 4589 doc-negate
|
doc-abs |
doc-abs |
doc-min |
doc-min |
doc-max |
doc-max |
doc-d>s |
|
doc-floored |
doc-floored |
|
|
|
|
@node Bitwise operations, Double precision, Single precision, Arithmetic |
@node Double precision, Bitwise operations, Single precision, Arithmetic |
@subsection Bitwise operations |
|
@cindex bitwise operation words |
|
|
|
|
|
doc-and |
|
doc-or |
|
doc-xor |
|
doc-invert |
|
doc-lshift |
|
doc-rshift |
|
doc-2* |
|
doc-d2* |
|
doc-2/ |
|
doc-d2/ |
|
|
|
|
|
@node Double precision, Numeric comparison, Bitwise operations, Arithmetic |
|
@subsection Double precision |
@subsection Double precision |
@cindex double precision arithmetic words |
@cindex double precision arithmetic words |
|
|
Line 4603 For the rules used by the text interpret
|
Line 4600 For the rules used by the text interpret
|
recognising double-precision integers, see @ref{Number Conversion}. |
recognising double-precision integers, see @ref{Number Conversion}. |
|
|
A double precision number is represented by a cell pair, with the most |
A double precision number is represented by a cell pair, with the most |
significant cell at the TOS. It is trivial to convert an unsigned |
significant cell at the TOS. It is trivial to convert an unsigned single |
single to an (unsigned) double; simply push a @code{0} onto the |
to a double: simply push a @code{0} onto the TOS. Since numbers are |
TOS. Since numbers are represented by Gforth using 2's complement |
represented by Gforth using 2's complement arithmetic, converting a |
arithmetic, converting a signed single to a (signed) double requires |
signed single to a (signed) double requires sign-extension across the |
sign-extension across the most significant cell. This can be achieved |
most significant cell. This can be achieved using @code{s>d}. The moral |
using @code{s>d}. The moral of the story is that you cannot convert a |
of the story is that you cannot convert a number without knowing whether |
number without knowing whether it represents an unsigned or a |
it represents an unsigned or a signed number. |
signed number. |
|
|
|
|
These words are all defined for signed operands, but some of them also |
|
work for unsigned numbers: @code{d+}, @code{d-}. |
|
|
doc-s>d |
doc-s>d |
|
doc-d>s |
doc-d+ |
doc-d+ |
doc-d- |
doc-d- |
doc-dnegate |
doc-dnegate |
Line 4622 doc-dmin
|
Line 4621 doc-dmin
|
doc-dmax |
doc-dmax |
|
|
|
|
@node Numeric comparison, Mixed precision, Double precision, Arithmetic |
@node Bitwise operations, Numeric comparison, Double precision, Arithmetic |
|
@subsection Bitwise operations |
|
@cindex bitwise operation words |
|
|
|
|
|
doc-and |
|
doc-or |
|
doc-xor |
|
doc-invert |
|
doc-lshift |
|
doc-rshift |
|
doc-2* |
|
doc-d2* |
|
doc-2/ |
|
doc-d2/ |
|
|
|
|
|
@node Numeric comparison, Mixed precision, Bitwise operations, Arithmetic |
@subsection Numeric comparison |
@subsection Numeric comparison |
@cindex numeric comparison words |
@cindex numeric comparison words |
|
|
|
Note that the words that compare for equality (@code{= <> 0= 0<> d= d<> |
|
d0= d0<>}) work for for both signed and unsigned numbers. |
|
|
doc-< |
doc-< |
doc-<= |
doc-<= |
Line 4697 doc-sm/rem
|
Line 4715 doc-sm/rem
|
For the rules used by the text interpreter for |
For the rules used by the text interpreter for |
recognising floating-point numbers see @ref{Number Conversion}. |
recognising floating-point numbers see @ref{Number Conversion}. |
|
|
Gforth has a separate floating point |
Gforth has a separate floating point stack, but the documentation uses |
stack, but the documentation uses the unified notation. |
the unified notation.@footnote{It's easy to generate the separate |
|
notation from that by just separating the floating-point numbers out: |
|
e.g. @code{( n r1 u r2 -- r3 )} becomes @code{( n u -- ) ( F: r1 r2 -- |
|
r3 )}.} |
|
|
@cindex floating-point arithmetic, pitfalls |
@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 |
Line 4764 doc-pi
|
Line 4785 doc-pi
|
One particular problem with floating-point arithmetic is that comparison |
One particular problem with floating-point arithmetic is that comparison |
for equality often fails when you would expect it to succeed. For this |
for equality often fails when you would expect it to succeed. For this |
reason approximate equality is often preferred (but you still have to |
reason approximate equality is often preferred (but you still have to |
know what you are doing). The comparison words are: |
know what you are doing). Also note that IEEE NaNs may compare |
|
differently from you might expect. The comparison words are: |
|
|
doc-f~rel |
doc-f~rel |
doc-f~abs |
doc-f~abs |
Line 4935 doc-lp!
|
Line 4957 doc-lp!
|
* Memory Blocks:: |
* Memory Blocks:: |
@end menu |
@end menu |
|
|
|
In addition to the standard Forth memory allocation words, there is also |
|
a @uref{http://www.complang.tuwien.ac.at/forth/garbage-collection.zip, |
|
garbage collector}. |
|
|
@node Memory model, Dictionary allocation, Memory, Memory |
@node Memory model, Dictionary allocation, Memory, Memory |
@subsection ANS Forth and Gforth memory models |
@subsection ANS Forth and Gforth memory models |
|
|
@c The ANS Forth description is a mess (e.g., is the heap part of |
@c The ANS Forth description is a mess (e.g., is the heap part of |
@c the dictionary?), so let's not stick to closely with it. |
@c the dictionary?), so let's not stick to closely with it. |
|
|
ANS Forth considers a Forth system as consisting of several memories, of |
ANS Forth considers a Forth system as consisting of several address |
which only @dfn{data space} is managed and accessible with the memory |
spaces, of which only @dfn{data space} is managed and accessible with |
words. Memory not necessarily in data space includes the stacks, the |
the memory words. Memory not necessarily in data space includes the |
code (called code space) and the headers (called name space). In Gforth |
stacks, the code (called code space) and the headers (called name |
everything is in data space, but the code for the primitives is usually |
space). In Gforth everything is in data space, but the code for the |
read-only. |
primitives is usually read-only. |
|
|
Data space is divided into a number of areas: The (data space portion of |
Data space is divided into a number of areas: The (data space portion of |
the) dictionary@footnote{Sometimes, the term @dfn{dictionary} is used to |
the) dictionary@footnote{Sometimes, the term @dfn{dictionary} is used to |
Line 4970 addresses even between contiguous region
|
Line 4996 addresses even between contiguous region
|
allocations in the heap is platform-dependent (and possibly different |
allocations in the heap is platform-dependent (and possibly different |
from one run to the next). |
from one run to the next). |
|
|
@subsubsection ANS Forth dictionary details |
|
|
|
This section is just informative, you can skip it if you are in a hurry. |
|
|
|
When you create a colon definition, the text interpreter compiles the |
|
code for the definition into the code space and compiles the name |
|
of the definition into the header space, together with other |
|
information about the definition (such as its execution token). |
|
|
|
When you create a variable, the execution of @code{Variable} will |
|
compile some code, assign one cell in data space, and compile the name |
|
of the variable into the header space. |
|
|
|
@cindex memory regions - relationship between them |
|
ANS Forth does not specify the relationship between the three memory |
|
regions, and specifies that a Standard program must not access code or |
|
data space directly -- it may only access data space directly. In |
|
addition, the Standard defines what relationships you may and may not |
|
rely on when allocating regions in data space. These constraints are |
|
simply a reflection of the many diverse techniques that are used to |
|
implement Forth systems; understanding and following the requirements of |
|
the Standard allows you to write portable programs -- programs that run |
|
in the same way on any of these diverse systems. Another way of looking |
|
at this is to say that ANS Forth was designed to permit compliant Forth |
|
systems to be implemented in many diverse ways. |
|
|
|
@cindex memory regions - how they are assigned |
|
Here are some examples of ways in which name, code and data spaces |
|
might be assigned in different Forth implementations: |
|
|
|
@itemize @bullet |
|
@item |
|
For a Forth system that runs from RAM under a general-purpose operating |
|
system, it can be convenient to interleave name, code and data spaces in |
|
a single contiguous memory region. This organisation can be |
|
memory-efficient (for example, because the relationship between the name |
|
dictionary entry and the associated code space entry can be |
|
implicit, rather than requiring an explicit memory pointer to reference |
|
from the header space and the code space). This is the |
|
organisation used by Gforth, as this example@footnote{The addresses |
|
in the example have been truncated to fit it onto the page, and the |
|
addresses and data shown will not match the output from your system} shows: |
|
@example |
|
hex |
|
variable fred 123456 fred ! |
|
variable jim abcd jim ! |
|
: foo + / - ; |
|
' fred 10 - 50 dump |
|
..80: 5C 46 0E 40 84 66 72 65 - 64 20 20 20 20 20 20 20 \F.@.fred |
|
..90: D0 9B 04 08 00 00 00 00 - 56 34 12 00 80 46 0E 40 ........V4...F.@@ |
|
..A0: 83 6A 69 6D 20 20 20 20 - D0 9B 04 08 00 00 00 00 .jim ........ |
|
..B0: CD AB 00 00 9C 46 0E 40 - 83 66 6F 6F 20 20 20 20 .....F.@.foo |
|
..C0: 80 9B 04 08 00 00 00 00 - E4 2E 05 08 0C 2F 05 08 ............./.. |
|
@end example |
|
|
|
@item |
|
For a high-performance system running on a modern RISC processor with a |
|
modified Harvard architecture (one that has a unified main memory but |
|
separate instruction and data caches), it is desirable to separate |
|
processor instructions from processor data. This encourages a high cache |
|
density and therefore a high cache hit rate. The Forth code space |
|
is not necessarily made up entirely of processor instructions; its |
|
nature is dependent upon the Forth implementation. |
|
|
|
@item |
|
A Forth compiler that runs on a segmented 8086 processor could be |
|
designed to interleave the name, code and data spaces within a single |
|
64Kbyte segment. A more common implementation choice is to use a |
|
separate 64Kbyte segment for each region, which provides more memory |
|
overall but provides an address map in which only the data space is |
|
accessible. |
|
|
|
@item |
|
Microprocessors exist that run Forth (or many of the primitives required |
|
to implement the Forth virtual machine efficiently) directly. On these |
|
processors, the relationship between name, code and data spaces may be |
|
imposed as a side-effect of the architecture of the processor. |
|
|
|
@item |
|
A Forth compiler that executes from ROM on an embedded system needs its |
|
data space separated from the name and code spaces so that the data |
|
space can be mapped to a RAM area. |
|
|
|
@item |
|
A Forth compiler that runs on an embedded system may have a requirement |
|
for a small memory footprint. On such a system it can be useful to |
|
separate the header space from the data and code spaces; once the |
|
application has been compiled, the header space is no longer |
|
required@footnote{more strictly speaking, most applications can be |
|
designed so that this is the case}. The header space can be deleted |
|
entirely, or could be stored in memory on a remote @i{host} system for |
|
debug and development purposes. In the latter case, the compiler running |
|
on the @i{target} system could implement a protocol across a |
|
communication link that would allow it to interrogate the header space. |
|
@end itemize |
|
|
|
@node Dictionary allocation, Heap Allocation, Memory model, Memory |
@node Dictionary allocation, Heap Allocation, Memory model, Memory |
@subsection Dictionary allocation |
@subsection Dictionary allocation |
Line 5097 doc-c,
|
Line 5028 doc-c,
|
doc-f, |
doc-f, |
doc-, |
doc-, |
doc-2, |
doc-2, |
@cindex user space |
|
doc-udp |
|
doc-uallot |
|
|
|
Memory accesses have to be aligned (@pxref{Address arithmetic}). So of |
Memory accesses have to be aligned (@pxref{Address arithmetic}). So of |
course you should allocate memory in an aligned way, too. I.e., before |
course you should allocate memory in an aligned way, too. I.e., before |
Line 5159 doc-df!
|
Line 5087 doc-df!
|
@subsection Address arithmetic |
@subsection Address arithmetic |
@cindex address arithmetic words |
@cindex address arithmetic words |
|
|
Address arithmetic is the foundation on which data structures like |
Address arithmetic is the foundation on which you can build data |
arrays, records (@pxref{Structures}) and objects (@pxref{Object-oriented |
structures like arrays, records (@pxref{Structures}) and objects |
Forth}) are built. |
(@pxref{Object-oriented Forth}). |
|
|
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 5170 arithmetic. Address arithmetic is perfor
|
Line 5098 arithmetic. Address arithmetic is perfor
|
character may have more than one au, so @code{chars} is no noop (on |
character may have more than one au, so @code{chars} is no noop (on |
systems where it is a noop, it compiles to nothing). |
systems where it is a noop, it compiles to nothing). |
|
|
|
The basic address arithmetic words are @code{+} and @code{-}. E.g., if |
|
you have the address of a cell, perform @code{1 cells +}, and you will |
|
have the address of the next cell. |
|
|
|
In ANS Forth you can perform address arithmetic only within a contiguous |
|
region, i.e., if you have an address into one region, you can only add |
|
and subtract such that the result is still within the region; you can |
|
only subtract or compare addresses from within the same contiguous |
|
region. Reasons: several contiguous regions can be arranged in memory |
|
in any way; on segmented systems addresses may have unusual |
|
representations, such that address arithmetic only works within a |
|
region. Gforth provides a few more guarantees (linear address space, |
|
dictionary grows upwards), but in general I have found it easy to stay |
|
within contiguous regions (exception: computing and comparing to the |
|
address just beyond the end of an array). |
|
|
@cindex alignment of addresses for types |
@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 |
types. Many computers require that accesses to specific data types |
types. Many computers require that accesses to specific data types |
Line 5225 Memory blocks often represent character
|
Line 5169 Memory blocks often represent character
|
character strings in memory see @ref{String Formats}. For other |
character strings in memory see @ref{String Formats}. For other |
string-processing words see @ref{Displaying characters and strings}. |
string-processing words see @ref{Displaying characters and strings}. |
|
|
Some of these words work on address units. Others work on character |
A few of these words work on address unit blocks. In that case, you |
units (increments of @code{CHAR}), and expect a @code{CHAR}-aligned |
usually have to insert @code{CHARS} before the word when working on |
address. Choose the correct operation depending upon your data type. |
character strings. Most words work on character blocks, and expect a |
|
char-aligned address. |
When copying characters between overlapping memory regions, choose |
|
carefully between @code{cmove} and @code{cmove>}. |
When copying characters between overlapping memory regions, use |
|
@code{chars move} or choose carefully between @code{cmove} and |
You can only use any of these words @i{portably} to access data space. |
@code{cmove>}. |
|
|
@comment TODO - think the naming of the arguments is wrong for move |
|
@comment well, really it seems to be the Standard that's wrong; it |
|
@comment describes MOVE as a word that requires a CELL-aligned source |
|
@comment and destination address but a xtranfer count that need not |
|
@comment be a multiple of CELL. |
|
|
|
doc-move |
doc-move |
doc-erase |
doc-erase |
Line 5269 yet, although many schemes have been pro
|
Line 5207 yet, although many schemes have been pro
|
* Selection:: IF ... ELSE ... ENDIF |
* Selection:: IF ... ELSE ... ENDIF |
* Simple Loops:: BEGIN ... |
* Simple Loops:: BEGIN ... |
* Counted Loops:: DO |
* Counted Loops:: DO |
* Arbitrary control structures:: |
* Arbitrary control structures:: |
* Calls and returns:: |
* Calls and returns:: |
* Exception Handling:: |
* Exception Handling:: |
@end menu |
@end menu |
|
|
Line 5894 doc---exception-exception
|
Line 5832 doc---exception-exception
|
Defining words are used to extend Forth by creating new entries in the dictionary. |
Defining words are used to extend Forth by creating new entries in the dictionary. |
|
|
@menu |
@menu |
* CREATE:: |
* CREATE:: |
* Variables:: Variables and user variables |
* Variables:: Variables and user variables |
* Constants:: |
* Constants:: |
* Values:: Initialised variables |
* Values:: Initialised variables |
* Colon Definitions:: |
* Colon Definitions:: |
* Anonymous Definitions:: Definitions without names |
* Anonymous Definitions:: Definitions without names |
* User-defined Defining Words:: |
* User-defined Defining Words:: |
* Deferred words:: Allow forward references |
* Deferred words:: Allow forward references |
* Aliases:: |
* Aliases:: |
* Supplying names:: |
* Supplying names:: |
@end menu |
@end menu |
|
|
@node CREATE, Variables, Defining Words, Defining Words |
@node CREATE, Variables, Defining Words, Defining Words |
Line 6005 than normal data space. In a Forth syste
|
Line 5943 than normal data space. In a Forth syste
|
task has its own set of user variables. |
task has its own set of user variables. |
|
|
doc-user |
doc-user |
|
@c doc-udp |
|
@c doc-uallot |
|
|
@comment TODO is that stuff about user variables strictly correct? Is it |
@comment TODO is that stuff about user variables strictly correct? Is it |
@comment just terminal tasks that have user variables? |
@comment just terminal tasks that have user variables? |
@comment should document tasker.fs (with some examples) elsewhere |
@comment should document tasker.fs (with some examples) elsewhere |
@comment in this manual, then expand on user space and user variables. |
@comment in this manual, then expand on user space and user variables. |
|
|
|
|
@node Constants, Values, Variables, Defining Words |
@node Constants, Values, Variables, Defining Words |
@subsection Constants |
@subsection Constants |
@cindex constants |
@cindex constants |
Line 6838 Note that ticking (@code{'}) a compile-o
|
Line 6777 Note that ticking (@code{'}) a compile-o
|
(``Interpreting a compile-only word''). |
(``Interpreting a compile-only word''). |
|
|
@menu |
@menu |
* Combined words:: |
* Combined words:: |
@end menu |
@end menu |
|
|
@node Combined words, , Interpretation and Compilation Semantics, Interpretation and Compilation Semantics |
@node Combined words, , Interpretation and Compilation Semantics, Interpretation and Compilation Semantics |
Line 7261 doc-#tib
|
Line 7200 doc-#tib
|
|
|
|
|
@menu |
@menu |
* Input Sources:: |
* Input Sources:: |
* Number Conversion:: |
* Number Conversion:: |
* Interpret/Compile states:: |
* Interpret/Compile states:: |
* Literals:: |
* Literals:: |
* Interpreter Directives:: |
* Interpreter Directives:: |
@end menu |
@end menu |
|
|
@node Input Sources, Number Conversion, The Text Interpreter, The Text Interpreter |
@node Input Sources, Number Conversion, The Text Interpreter, The Text Interpreter |
Line 7698 doc-context
|
Line 7637 doc-context
|
|
|
|
|
@menu |
@menu |
* Why use word lists?:: |
* Why use word lists?:: |
* Word list examples:: |
* Word list examples:: |
@end menu |
@end menu |
|
|
@node Why use word lists?, Word list examples, Word Lists, Word Lists |
@node Why use word lists?, Word list examples, Word Lists, Word Lists |
Line 8238 doc-block-included
|
Line 8177 doc-block-included
|
* Simple numeric output:: Predefined formats |
* Simple numeric output:: Predefined formats |
* Formatted numeric output:: Formatted (pictured) output |
* Formatted numeric output:: Formatted (pictured) output |
* String Formats:: How Forth stores strings in memory |
* String Formats:: How Forth stores strings in memory |
* Displaying characters and strings:: Other stuff |
* Displaying characters and strings:: Other stuff |
* Input:: Input |
* Input:: Input |
@end menu |
@end menu |
|
|
Line 10932 oriented bigFORTH} by Bernd Paysan, publ
|
Line 10871 oriented bigFORTH} by Bernd Paysan, publ
|
10(2), 1994. |
10(2), 1994. |
|
|
@menu |
@menu |
* Properties of the OOF model:: |
* Properties of the OOF model:: |
* Basic OOF Usage:: |
* Basic OOF Usage:: |
* The OOF base class:: |
* The OOF base class:: |
* Class Declaration:: |
* Class Declaration:: |
* Class Implementation:: |
* Class Implementation:: |
@end menu |
@end menu |
|
|
@node Properties of the OOF model, Basic OOF Usage, OOF, OOF |
@node Properties of the OOF model, Basic OOF Usage, OOF, OOF |
Line 11214 of Bernd Paysan in comp.arch.
|
Line 11153 of Bernd Paysan in comp.arch.
|
* Basic Mini-OOF Usage:: |
* Basic Mini-OOF Usage:: |
* Mini-OOF Example:: |
* Mini-OOF Example:: |
* Mini-OOF Implementation:: |
* Mini-OOF Implementation:: |
* Comparison with other object models:: |
|
@end menu |
@end menu |
|
|
@c ------------------------------------------------------------- |
@c ------------------------------------------------------------- |
Line 13287 convention, we use the extension @code{.
|
Line 13225 convention, we use the extension @code{.
|
@menu |
@menu |
* Image Licensing Issues:: Distribution terms for images. |
* Image Licensing Issues:: Distribution terms for images. |
* Image File Background:: Why have image files? |
* Image File Background:: Why have image files? |
* Non-Relocatable Image Files:: don't always work. |
* Non-Relocatable Image Files:: don't always work. |
* Data-Relocatable Image Files:: are better. |
* Data-Relocatable Image Files:: are better. |
* Fully Relocatable Image Files:: better yet. |
* Fully Relocatable Image Files:: better yet. |
* Stack and Dictionary Sizes:: Setting the default sizes for an image. |
* Stack and Dictionary Sizes:: Setting the default sizes for an image. |
* Running Image Files:: @code{gforth -i @i{file}} or @i{file}. |
* Running Image Files:: @code{gforth -i @i{file}} or @i{file}. |
* Modifying the Startup Sequence:: and turnkey applications. |
* Modifying the Startup Sequence:: and turnkey applications. |
Line 14209 started. The cross compiler allows to cr
|
Line 14147 started. The cross compiler allows to cr
|
architectures, even running under another Forth system. |
architectures, even running under another Forth system. |
|
|
@menu |
@menu |
* Using the Cross Compiler:: |
* Using the Cross Compiler:: |
* How the Cross Compiler Works:: |
* How the Cross Compiler Works:: |
@end menu |
@end menu |
|
|
@node Using the Cross Compiler, How the Cross Compiler Works, Cross Compiler, Cross Compiler |
@node Using the Cross Compiler, How the Cross Compiler Works, Cross Compiler, Cross Compiler |
Line 14432 information about Forth there.
|
Line 14370 information about Forth there.
|
@cindex Forth-related information |
@cindex Forth-related information |
|
|
@menu |
@menu |
* Internet resources:: |
* Internet resources:: |
* Books:: |
* Books:: |
* The Forth Interest Group:: |
* The Forth Interest Group:: |
* Conferences:: |
* Conferences:: |
@end menu |
@end menu |
|
|
|
|