16.1.
When the interpreter
translates
The word
introducing the colon
word
definitions
: creates the name, code and chain fields
of the new word, then so-called.
translates the interpreter
into a translation state. This
means that the interpreter does not execute the terms of his or her influence,
but searches for their code address and stores them in the HERE address (in
the parser of the word that is being created).
Whether
the words found in my influence are performed or translated by the interpreter
depends on the value of the system variable USATE (USER variable).
If the value of the STATE is
not 0, the words of my influence are translated.
|
Accordingly,
if STATE 0 is an execution, if not, translation state.
The value of the STATE (including) the definitions: and the finishing;
word says.
16.2.
When the interpreter does not
translate
Let's look at a fairly common definition:
: COUNT DUP 1+ SWAP C @;
With the above and 14.1. section , the COUNT parter looks like this:
DUP field address 1+ code domain name SWAP code field C @ code field address ; S code field address
Now add the same definition to a comment:
: COUNT (ff-cim --- length length) DUP 1+ SWAP C @;
From the above, it will appear in the second COUNT parse of the (word code field name (since the word STATE is not 0, the system is in translation state.) Common sense, however, suggests that the results of the two definitions should be the same if they only differ in a single comment, the common sense is correct: not all words are translated in the translation state, but exceptions to the rule are instant (immediate, immediate) words.
Immediate
words are not even translated when the interpreter is in translation;
every time the interpreter
finds them, they are executed immediately.
|
A (an instant word, we can write words immediately; we just have to add the word fresh after word definition
IMMEDIATE
so make it straightforward:
: JELENT (---)
CR LATEST ID. "defines started"
; IMMEDIATE
If JELENT is used in a colon word definition, the meaning is written during the definition, but the whole thing has no effect on the resulting new word. Here is the third definition that creates exactly the same parsing as the previous two:
: COUNT3 JELENT DUP 1+ SWAP C @;
The instantaneous or non-immediate word of a word is the second bit of the length field of the name field, so-called. precedence bit. IMMEDIATE simply sets the last bit of the last word defined to 1.
16.3.
When we pay instead of the
interpreter (Compile)
How Does
.
"
Word when used definition? Taking the value to be printed by definition,
so immediately it has to be (so you can text only to read the definition
at compile time). Should , but to have a word that is actually translated
into the parsing of the word that is being generated, otherwise there is
no one who writes the text during the run time.
(. ")
"Compiling
word" is the name of the immediate words that make the code field for another
word (the "running word") and the data for the running word work (field
parameters) in the parser.
|
In
our case
.
"
The word translator, the
(.
')
Running words, the text is kiíratandó edge of the field parameters.
If there is a definition in which the
word
"." Was used:
: RENDBEN. "OK";
then its paramount:
The word "." Does make sure that the FORTH hanger on it goes to the device and that the title interpreter does not attempt to interpret the byte of the hanger as a code address to use it for its operation the virgin finds his / her own return address, which is exactly the title of the font that you want to point out: from here, type the text and then manipulate the virus to point the return address after the string.
: (. ")
R COUNT
DUP 1+
R> +> R
TYPE
;
(the length and the title of the string in
the worm)
( add the total length to a) (return address)
If you want an instant word to translate another (running) word, then a
COMPILE
we have to use word. For example, "
COMPILE (. ")
cheating
in the series
(
".)
kódmezõcímét the paramzõbe.
The word translates the word COMPILE behind it, that places the
kódmezõcímét at HERE.
A. " Checks for a translation state:
:. "
34 (the" delimiter character code ")
STATE @ IF
COMPILE (.)
WORD
HERE C @ (the dictionary pointer is the string)
1+ ALLOT (behind it)
ELSE (no translation, execution)
WORD HERE COUNT TYPE
ENDIF
;
16.4.
Literals
Literals are the numbers that are given in the definition;
these interpreters enter the
parser. The running word handling
the literals a
LIT
For example the
: .HAT 6. ;
literally the 6 is a literal. The parable of the word looks like this:
LIT code field address 6 . kódmezõcíme ; S code field address
LIT
makes sure that when running .HAT, you get 6 on the stack and also that the
address interpreter does not look at the 6 as the execution address.
The value to be used in the word definition may be the result of an operation;
say, we want to use the number
of minutes per day 60 * 24.
This can be anticipated, but
you do not see what this was and how it was calculated;
the multiplication can be written
in the definition text, but it is executed at each run, which is a waste
of time. Instead, we can also
make the translation state a
[
so we eliminate it, produce the desired value in the vermin and a
]
so we return to the translation state. The value on the bug will be translated into the parser by literal literal LITERAL:
: PERCEK [60 24 *] LITERAL. "one minute a day";
The
word LITERAL is, of course, immediate.
If used in the definition,
the LIT running word translates, behind, the value in the box as the field
parameter. If not used in a
definition, LITERAL does not do anything.
The source of the last three words learned:
HEX : [0 STATE! ; IMMEDIATE
:] 192 STATE! ; IMMEDIATE
; LITERAL
STATE @ IF COMPILE LIT, ENDIF
; IMMEDIATE
16.5.
Postpone Instant Words (on
[COMPILE])
How does 'word' work? It should
be an instant word, as it searches for the word behind the word in the dictionary
when translating. The title
then (if used in 'definition') appears as literal in the parsing.
There is nothing in it that we can not write:
: '
-FIND
0 = 0? ERROR (if there is no such thing,
flush) DROP (Parameter Address on the Vermont)
STATE @ IF
COMPILE LIT,
ENDIF
; IMMEDIATE
If someone compares the end of the program with the LITERAL source text, you see that they are completely identical. However, LITERAL can not be included in the 'text: LITERAL is immediate and we do not want it to be' under the definition. Instead, we want you to use all 'immediate' activities when you use it. This is made possible by
[COMPILE]
, which eliminates the immediate behavior of the word behind it for this one occasion. The word 'original' is FIG:
: '
-FIND
0 = 0? ERROR (if there is no word left)
DROP
[COMPILE] LITERAL
ENDIF
; IMMEDIATE
Now let's get acquainted with the LITERAL double-word version of DLITERAL:
: DLITERAL
STATE @ IF (translation status)
SWAP (the bottom element must be placed on the stack first)
[COMPILE] LITERAL [COMPILE] LITERAL
ENDIF
; IMMEDIATE
What was that about?
Summary
of Chapter 16
The words learned:
STATEMENT | ( --- title ) |
USER
variable. If it is 0, the
interpreter will execute it if not, then translate the words to be interpreted
(execution and translation status).
|
IMMEDIATE |
The
last word defined is immediate (sets the so-called precedent bit to 1).
This means that the word is
not translated even in translation;
if you want to translate it,
you should use the word [COMPILE].
|
|
[COMPILE] | For a single occasion it eliminates the immediate behavior of the word behind it. This way you can translate the words immediately. | |
COMPILE | Use it in immediate words. Translates the word behind it. | |
[ | Turns the system into a translation state. | |
] | Enables the system to take effect. | |
LIT | (--- n) | A running word that makes the one-word field parameter behind it on the stack. |
liter | (n
---) during the translated word: (--- n) when executing: (n --- n) In translation state translates the value found in the vermont literal, ie: translates the running word LIT into a single word field parameter n et. Thus, at run time, n is on the stack. In execution state no effect. |
|
DLITERAL | when
translating: (d ---) during the translated word: (d) when executing: (d --- d) In translation state translates the double word value found in the vermont literally, which is translated into the stack when the compiled word runs. In execution state no effect. |
|
(. ") | A. " Translated Run Word Prints to the outboard for FORTH that is behind the parade. |
Examples
16.1. Make a list of the immediate words of the dictionary!
The second bits of the length words of the immediate words 1. Thus, if this longitude bent is placed on the stack and the logical AND result of binary
0000 0000 0100 0000
ie hexadecimal 40, we get the corresponding flag:
: AZONNALIAK (pmmark --- flag)
NFA C @
[HEX 40 DECIMAL] LITERAL AND
;Using the word EZEK-A known in Chapter 14, it is easy to finish:
THESE ARE THE IMMEDIATE
16.2. Write a KNYO (---) word, which if used in the definition, the word defined defines how the definition is in a quake. So if, for example, the
: HOL-VAN KNYO;
HOL-VAN is in operation, it says: "I was 12 months old"
: KNYO
[BLK @ B / SCR /] LITERAL
. "I was in a hurry";
;
16.3. Write a "" word that can be used in the same definition as the "" word, but the translated word begins before the text is written.
:. ""
COMPILE CR [COMPILE] "
; IMMEDIATE
16.4. Define such a; word to indicate the termination of the definition with text.
:;
LATEST ID. (the name of the last word defined)
. "definicio vege"
[COMPILE]; (normal finish)
; IMMEDIATE
16.5. What can be the source of [COMPILE]?
: [COMPILE]
-FIND 0 = 0? ERROR DROP CFA
,; IMMEDIATE
file: /Techref/language/forth/z80fig-forth1_1g_files/immediate_words.htm, 42KB, , updated: 2018/11/8 20:04, local time: 2024/11/13 22:16,
3.145.171.99:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/forth/z80fig-forth1_1g_files/immediate_words.htm"> 16 Immediate words </A> |
Did you find what you needed? |
Welcome to massmind.org! |
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.