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

 

 

 

Forth Programmer’s Handbook

 

 

 

 

Glossary

 

 

 

AHEAD

( — orig )

Tools Ext

 

 

At compile time, begin an unconditional forward branch by placing orig on the

 

 

control-flow stack. The behavior is incomplete until the orig is resolved, e.g.,

 

 

by THEN. At run time, resume execution at the location provided by the reso-

 

 

lution of this orig.

 

CS-PICK

( i*x u — i*x xu )

Tools Ext

 

 

Place a copy of the uth control-stack entry on the top of the control stack. The

 

 

zeroth item is on top of the control stack; i.e., 0 CS-PICK is equivalent to DUP

 

 

and 1 CS-PICK is equivalent to OVER. “C-S-pick”

 

CS-ROLL

( i*x u — (i-1)*x xu )

Tools Ext

 

 

Move the nth control-stack entry to the top of the stack, pushing down all the

 

 

control-stack entries in between. The zeroth item is on top of the stack; i.e., 0

 

 

CS-ROLL does nothing, 1 CS-ROLL is equivalent to SWAP, and 2 CS-ROLL is

 

 

equivalent to ROT. “C-S-roll”

 

 

 

Indefinite loops, Section 2.5.1

 

References

 

 

 

DO LOOPs, Section 2.5.2

 

 

 

IF ELSE THEN, Section 2.5.3

 

4.5 OVERLAYS

Because of Forth’s compilation speed, there is rarely need for a dynamic runtime overlay capability. Many resident applications have several functionally independent subsets, however, and it is conventional to organize these as mutually exclusive overlays, any one of which may be loaded into each terminal’s private dictionary. This is done by explicit command. Once loaded, such an overlay will remain resident until replaced by another.

Examples of such overlay categories in a business environment might include order entry, payroll, and general ledger. In a scientific laboratory system, there may be several different data acquisition and analysis modes.

Overlays are enabled with MARKER. The phrase MARKER <name> creates a dictionary entry for name. When name is executed, it will discard the definition

The Forth Interpreter and Compiler 163

Forth Programmer’s Handbook

name and all words defined after name in a user’s partition. The user’s dictionary pointer will be reset to the last definition in the vocabulary before name. Because the dictionary pointer is reset, the dictionary is truncated spatially as well as logically. Other system-dependent actions may be taken as well, such as restoration of interrupt vectors (see your product documentation).

MARKER has two uses:

!To discard only part of your definitions. For example, when testing, you may wish to reload only the last block, not your entire application.

!To create additional levels of overlays.

Suppose your application includes an overlay called GRAPHICS. After GRAPHICS is loaded, you want to be able to load one of two additional overlays, called COLOR and B&W, thus creating a second level of overlay. Here is the procedure to follow:

1.Define a marker as the final definition of GRAPHICS, using any word you want as a dictionary marker. For example:

MARKER OVERLAY

Preferably, such a definition would be placed at the bottom of the GRAPHICS load block.

2.Execute OVERLAY and then redefine it (since it forgets itself) on the first line of the load block of each level-two overlay. For instance,

( COLOR) OVERLAY MARKER OVERLAY

Thus, when you execute the phrase:

COLOR LOAD

the system will forget any definitions which may have been compiled after GRAPHICS and will restore the marker definition of OVERLAY in the event you want to load an alternate level-two definition, such as B&W.

By using different names for your markers, you may create any number of overlay levels.

164 The Forth Interpreter and Compiler

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