Next: , Previous: Defining Words, Up: Words


5.10 Interpretation and Compilation Semantics

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 compiles1 the compilation semantics of word.

The standard also talks about execution semantics. They are used only for defining the interpretation and compilation semantics of many words. 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.2

Unnamed words (see Anonymous Definitions) cannot be encountered by the text interpreter, ticked, or postponed, so they have no interpretation or compilation semantics. Their behaviour is represented by their XT (see Tokens for Words), and we call it execution semantics, too.

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       “compile-only”

Remove the interpretation semantics of a word.

restrict              gforth       “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 an error (“Interpreting a compile-only word”).


Footnotes

[1] In standard terminology, “appends to the current definition”.

[2] 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.