Classic single-xt approach
In the classic single-xt approach, a Forth system defines execution semantics for every word, and these semantics are identified by an execution token (xt) that is associated with the word.
So, in the classic single-xt approach, to perform the observable interpretation semantics of a word we should perform its execution semantics in interpretation state.
To perform the observable interpretation semantics of a word regardless of the current state, we should:
- if the system is in interpretation state: perform the execution semantics;
- if the system is in compilation state: leave compilation state (i.e., enter compilation state), perform the execution semantics, enter compilation state.
Similar, to perform the observable compilation semantics of a word regardless of the current state, we should:
- if the system is in compilation state: perform the execution semantics;
- if the system is in interpretation state: enter compilation state, perform the execution semantics, leave compilation state (i.e., enter interpretation state).
To perform for a word the observable interpretation semantics if the Forth system in interpretation state, and the observable compilation semantics if the Forth system in compilation state we should simply perform the execution semantics of the word.
Any standard system
At first glance, one might think that to perform the observable interpretation semantics for a word regardless of the state it is sufficient to simply execute the xt returned by name>interpret
for the word's nt. But this is not true on most Forth systems.
Some examples:
: test1 ( -- flag ) state @ 0<> ;
: test2 ( -- -1 | ) s" true" evaluate ;
These words are ordinary words, which are defined by specifying their execution semantics. Note that in both cases the execution semantics depends on the system's state.
The observable interpretation semantics of test1
are to place 0
on the data stack.
The observable interpretation semantics of test2
are to find the word "true
" and perform its interpretation semantics, that are (in a standard system) to place -1
on the data stack, and if the word is not found, throw exception -13.
On most Forth systems, executing of the xt returned by name>interpret
for these words produces different results depending on the state.
Thus, to perform the observable interpretation semantics for these words, we should execute an xt returned by name>interpret
in interpretation state only.
What name>interpret
returns
If we admit that the above behavior of name>interpret
is desired, then there are no difference with the single-xt approach: in the general case, we should set interpretation state to perform the observable interpretation semantics for a word (see the steps in the section "Classic single-xt approach" above).
Consequently, we can admit that name>interpret
always returns an xt that identifies the execution semantics of the word, because:
- it is true for any user-defined word (except synonyms for standard words that are considered the same as the corresponding standard words);
- it is true for ordinary standard words;
- it is true for immediate standard words;
- it is true in the cases when special interpretation semantics are defined for a standard word, because the execution semantics are not defined in these cases, thus, a returned xt can be considered as an identifier for the system-dependent execution semantics of the word, but executing of this xt in interpretation state shall exhibit the observable interpretation semantics for the word, which are specified by the standard;
- it is true in the cases when interpretation semantics are undefined for a standard word, because obtaining the execution token of the word is ambiguous (at the moment), and so a returned xt can be considered as an identifier for the system-dependent execution semantics of the word, but executing of this xt in interpretation state shall exhibit the observable interpretation semantics for the word, which are system-defined.
There are no other cases. This applies to single-xt systems as well as to dual-xt systems.
Standard language
In all cases when special interpretation semantics or special compilation semantics are defined for a standard word, they are observable interpretation semantics or observable compilation semantics for the word correspondingly — and this is as it must be, unless we want to impose a particular implementation.
Also, by the definitions, the Forth text interpreter performs the observable interpretation semantics for the word when in interpretation state, and the observable compilation semantics for the word when in compilation state.
There are only few places in the normative parts of the standard where a reader can be confused whether observable semantics are meant or something else.
For example, in 3.4.3.2 Interpretation semantics: "unless otherwise specified [...], the interpretation semantics of a Forth definition are its execution semantics". Obviously, in this case it is not about observable interpretation semantics. The observable interpretation semantics in this case are to perform the execution semantics in interpretation state. I think, that is an omission — that item should describe observable interpretation semantics.
So, in few places the term interpretation semantics does not mean observable interpretation semantics, whereas in most cases this term means observable interpretation semantics. This is an inconsistency that produces many problems.
I think, the wording should be adjusted so that everywhere the term interpretation semantics means observable interpretation semantics. Similar for "compilation semantics". This will eliminate some confusing, many questions and disputes.