The interpretation semantics of a (named) word are what the text
interpreter does when it encounters the word in interpret state. It also
appears in some other contexts, e.g., the execution token returned by
' word
identifies the interpretation semantics of word
(in other words, ' word execute
is equivalent to
interpret-state text interpretation of word
).
The compilation semantics of a (named) word are what the text
interpreter does when it encounters the word in compile state. It also
appears in other contexts, e.g, POSTPONE word
compiles21 the compilation semantics of word.
Most words have default compilation semantics: compile the execution
semantics (stack effect ( -- )
). But a number of words have
other compilation semantics, documented for the individual word
(including its stack effect).
The standard also talks about execution semantics. In the standard it never differs from the interpretation semantics if both are defined, but one or both of them may not be defined. Gforth makes no difference between interpretation and execution semantics, so these terms are used interchangeably.
In Gforth (since 1.0) all words have defined interpretation/execution
semantics. For many words that have no defined interpretation nor
execution semantics in the standard (e.g., if
), the
interpretation/execution semantics in Gforth are to perform the
compilation semantics.
In the standard, execution semantics are used to define interpretation
and compilation semantics by default: By default, the interpretation
semantics of a word are to execute
its execution semantics, and
the compilation semantics of a word are to compile,
its
execution semantics.22
Unnamed words (see Anonymous Definitions) cannot be encountered by
the text interpreter, ticked, or postpone
d. Such a word is
represented by its xt (see Tokens for Words), and the behaviour
when this xt is execute
d is called its execution semantics.
You can change the semantics of the most-recently defined word:
immediate
( – ) core “immediate”
Make the compilation semantics of a word be to execute
the execution semantics.
compile-only
( – ) gforth-0.2 “compile-only”
Mark the last definition as compile-only; as a result, the text
interpreter and '
will warn when they encounter such a word.
restrict
( – ) gforth-0.2 “restrict”
A synonym for compile-only
By convention, words with non-default compilation semantics (e.g.,
immediate words) often have names surrounded with brackets (e.g.,
[']
, see Execution token).
Note that ticking ('
) a compile-only word gives a warning
(“<word> is compile-only”).
In standard terminology, “appends to the current definition”.
In standard terminology: The default interpretation semantics are its execution semantics; the default compilation semantics are to append its execution semantics to the execution semantics of the current definition.