Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Conklin E.K.Forth programmer's handbook.2000.pdf
Скачиваний:
321
Добавлен:
23.08.2013
Размер:
2.04 Mб
Скачать

 

Forth Programmer’s Handbook

whitespace

A blank or non-graphic character encountered by the Forth inter-

character

preter while processing source in a text file.

word

The name of a Forth definition. In the text interpreter, word can also

 

refer to a sequence of non-space characters to be processed.

word list

A list of related Forth definition names that may be examined during a

 

dictionary search. A word list is a subset of the entire Forth dictionary.

B.3 DATA TYPES IN STACK NOTATION

Table 11 gives a description of the Standard Forth notation used to refer to the different data types that may appear in stack notation or descriptions in this manual. Additional tables in this section describe other notational conventions.

Table 11: Notation for the data type of stack arguments

Symbol

Data type

Size on stack

a-addr

A byte address that is cell-aligned (the address is evenly

1 cell

 

divisible by the cell size in bytes).

 

addr

Address.

1 cell

b

A byte, stored as the least-significant eight bits of a stack

1 cell

 

entry. The remaining bits of the stack entry are zero in

 

 

results, and are ignored in arguments.

 

c or char

An ASCII character, stored as a byte (see above) with the

1 cell

 

parity bit reset to zero.

 

c-addr

A byte address that is character-aligned (on current systems

1 cell

 

a character is always one byte, so this amounts to an arbi-

 

 

trary byte address).

 

d

A double-precision, signed, two’s complement integer,

2 cells

 

stored as two stack entries (least-significant cell underneath

 

 

the most-significant cell). On 16-bit machines the range is

 

 

from -2**31 through +2**31-1. On 32-bit machines, the

 

 

range is from -2**63 through +2**63-1.

 

dest

Control-flow destination.

Implementation

 

 

dependent

Glossary & Notation 207

Forth Programmer’s Handbook

Table 11:

Notation for the data type of stack arguments (continued)

 

 

 

Symbol

Data type

Size on stack

echar

Extended character (occupying the two low-order bytes of a

1 cell

 

stack item).

 

flag

A single-precision, Boolean truth flag (zero means false,

1 cell

 

non-zero means true). See Section B.4 for details.

 

i*x, j*x, etc.

Zero or more cells of unspecified data type; normally used

Varies

 

to indicate that the state of the stack is preserved during, or

 

 

is restored after, an operation.

 

ior

Result of an I/O operation. See Section 3.5.1 for use of iors

1 cell

 

in the file access words.

 

len

Length of a string (0–65535). A counted string may not

1 cell

 

contain more than 255 characters plus count.

 

loop-sys

Loop-control parameters. These include implementation-

Implementation

 

dependent representations of the current value of the loop

dependent

 

index, its upper limit, and a pointer to a termination location

 

 

where execution continues following an exit from the loop.

 

nest-sys

Implementation-dependent information for procedure

Implementation

 

calls. It may be kept on the return stack.

dependent

n

A signed, single-precision, two’s complement number.

1 cell

 

On 16-bit machines, the range is -2**15 through +2**15-1.

 

 

On 32-bit machines, the range is -2**31 through +2**31-1.

 

 

If a stack comment is shown as n, u is implied, unless spe-

 

 

cifically stated otherwise (e.g., + may be used to add signed

 

 

or unsigned numbers). If there is more than one input

 

 

argument, signed and unsigned types may not be mixed.

 

+n

A single-precision number that may not be negative and

1 cell

 

has the same positive upper limit as n, above. An input

 

 

stack argument shown as +n must not be negative.

 

orig

Control-flow origin.

Implementation

 

 

dependent

u

An unsigned, single-precision integer, with the range

1 cell

 

0 to 2**16 on 16-bit machines, or 0 through 2**32 on 32-bit

 

 

machines.

 

208 Glossary & Notation

Forth Programmer’s Handbook

Table 11:

Notation for the data type of stack arguments (continued)

 

 

 

Symbol

Data type

Size on stack

ud

An unsigned, double-precision integer, with the range

2 cells

 

0 to 2**32 on 16-bit machines, or 0 through 2**64 on

 

 

32-bit machines.

 

x

A cell (single stack item), otherwise unspecified.

1 cell

xt

Execution token. This is a value that identifies the execu-

1 cell

 

tion behavior of a definition. When this value is passed to

 

 

EXECUTE, the definition’s execution behavior is performed.

 

Some data types are sub-types of other data types. Figure 16 shows the hierarchy for sin- gle-cell and double-cell types. Any Forth definition that accepts an argument of a type shown in the figure must also accept all the subtypes below it. For example, a word with an input stack argument of type n also accepts arguments of type +n and char.

 

xd

 

 

x

 

d

ud

flag

xt

n

u

 

+d

 

 

+n

addr

 

 

 

 

char

c-addr

 

 

 

 

 

a-addr

Figure 16. Hierarchy of data types

Standard Forth does not require data-type checking, and most implementations do not include it among their standard functions. Also, most implementations do not include arithmetic error checking on standard math functions (such as overflow on a multiply operation). The reason for both of these restrictions is that error checking and data-type checking on low-level functions could be prohibitively costly in execution time. Most Forth implementations do support whatever hardware error-detection functions exist, such as a trap for divide by zero, or the various exceptions signaled by the 80387/80486 floating-point processor. An application may, of course, build in error checking and/or type checking at any level deemed necessary, simply by redefining the words in question and adding an outer layer of protection.

Glossary & Notation 209

Forth Programmer’s Handbook

B.4 FLAGS AND IOR CODES

Procedures that accept flags as input arguments shall treat zero as false, and any non-zero value as true. A flag returned as an argument is a well-formed flag with all bits zero (false), or all bits one (true).

Certain device control and other functions return an ior (I/O Result) to report the results of an operation. An ior may be treated as a flag, in the sense that a non-zero value is true; however, it is not necessarily a well-formed flag, because its specific value often is used to convey additional information. A returned value of zero for an ior shall mean successful completion (i.e., no error); non-zero values may indicate an error condition or other abnormal status, and are device dependent.

B.5 FORTH GLOSSARY NOTATION

Words described in this manual are grouped functionally. An alphabetical list of all words is given in Appendix C.

Each entry consists of two parts: an index line and a semantic (behavioral) description of the word. The index line is a single-line entry containing, from left to right:

!Definition name, in upper-case, monospaced, boldface letters;

!Stack behavior (the notation follows the conventions described in Sections B.3 and B.4, above).

The first paragraph of the behavioral description concludes with the natural-language pronunciation of the word (shown in distinctive type), if it is not obvious.

A word’s behavior may be context dependent. The behavior(s) for each such word are described, as applicable, for:

Compiling An action taken by the system when adding to the Forth dictionary.

name Execution The behavior of name when executed, where name is an instance of a class of words created by a defining word (see Section 4.2).

Interpreting An action taken by the system when the name of a word is encountered by the text interpreter in interpretation state.

Run-time The behavior executed by the system.

210 Glossary & Notation

Forth Programmer’s Handbook

While many words (such as defining words and compiler directives) possess specific compiling behaviors, the default compilation behavior of a word is to append its execution behavior to the current definition. Separate behaviors in different modes will be shown, where they differ.

Some words will be executed (i.e., will perform their behavior) when encountered in compiling mode. In Forth, these are known as immediate words. If execution of such a word will cause some run-time action in the word being compiled, this is shown as a separate run-time behavior.

Glossary & Notation 211

Forth Programmer’s Handbook

212 Glossary & Notation

Соседние файлы в предмете Электротехника