Next: Compilation token, Previous: Tokens for Words, Up: Tokens for Words
An execution token (XT) represents some behaviour of a word.
You can use execute
to invoke this behaviour.
You can use '
to get an execution token that represents the
interpretation semantics of a named word:
5 ' . ( n xt ) execute ( ) \ execute the xt (i.e., ".")
'
"name" – xt core “tick”
xt represents name's interpretation
semantics. Perform -14 throw
if the word has no
interpretation semantics.
'
parses at run-time; there is also a word [']
that parses
when it is compiled, and compiles the resulting XT:
: foo ['] . execute ; 5 foo : bar ' execute ; \ by contrast, 5 bar . \ ' parses "." when bar executes
[']
compilation. "name" – ; run-time. – xt core “bracket-tick”
xt represents name's interpretation
semantics. Perform -14 throw
if the word has no
interpretation semantics.
If you want the execution token of word, write [']
word
in compiled code and '
word in interpreted code. Gforth's
'
and [']
behave somewhat unusually by complaining about
compile-only words (because these words have no interpretation
semantics). You might get what you want by using COMP'
word
DROP
or [COMP']
word DROP
(for details see Compilation token).
Another way to get an XT is :noname
or latestxt
(see Anonymous Definitions). For anonymous words this gives an xt
for the only behaviour the word has (the execution semantics). For
named words, latestxt
produces an XT for the same behaviour it
would produce if the word was defined anonymously.
:noname ." hello" ; execute
An XT occupies one cell and can be manipulated like any other cell.
In ANS Forth the XT is just an abstract data type (i.e., defined by the operations that produce or consume it). For old hands: In Gforth, the XT is implemented as a code field address (CFA).
execute
xt – core “execute”
Perform the semantics represented by the execution token, xt.
perform
a-addr – gforth “perform”
@ execute
.