6.15.1 Execution token

An execution token (xt) represents some behaviour of a word. You can use execute to invoke the behaviour represented by the xt and compile, (see Macros) to compile it into the current definition. Other uses include deferred words (see Deferred Words).

In particular, there is the execution token of a word that represents its interpretation semantics (see Interpretation and Compilation Semantics).

For a named word x, you can use `x to get its execution token:

5 `. ( n xt )
execute ( )        \ "5"
: foo `. execute ;
5 foo              \ "5"

However, the tick-recognizer that recognizes the ` prefix is a Gforth extension, so you may prefer to use the Standard Forth words:

' ( "name" – xt  ) core “tick”

xt represents name’s interpretation semantics.

['] ( compilation. "name" – ; run-time. – xt  ) core “bracket-tick”

xt represents name’s interpretation semantics.

These are parsing words (whereas `x is treated as a literal by a recognizer), and you may find the behaviour in interpreted and compiled code unintuitive:

5 ' .   ( n xt ) 
execute ( )          \ "5"

: foo ['] . ;
5 foo execute        \ "5"

: bar ' dup ;
5 bar . drop execute \ "5"

' parses at run-time, so if you put it in a colon definition, as in bar, it does not consume the next word in the colon definition, but the next word at run-time (i.e., the . in the invocation of bar). If you want to put a literal xt in a colon definition without writing `x, write ['] x.

Gforth’s `x, ' and ['] warn when you use them on compile-only words, because such usage may be non-portable between different Forth systems.

You get the xt of the most recently defined word with latestxt (see Anonymous Definitions). For words defined using noname, this is the usual way of getting a token.

For words defined with :noname, the definition already pushes the xt, so you do not need to use latestxt for :noname-defined words.

:noname ." hello" ;
execute

An xt occupies one cell and can be manipulated like any other cell.

In Standard Forth the xt is just an abstract data type (i.e., defined by the operations that produce or consume it). The concrete implementation (since Gforth 1.0) is the body address (for old hands: PFA) of the word; in Gforth 0.7 and earlier, the xt was implemented as code field addres (CFA, 2 cells before the PFA).

execute ( xt – ) core “execute”

Perform the semantics represented by the execution token, xt.

execute-exit ( compilation – ; run-time xt nest-sys –  ) gforth-1.0 “execute-exit”

Execute xt and return from the current definition, in a tail-call-optimized way: The return address nest-sys and the locals are deallocated before executing xt.

perform ( a-addr – ) gforth-0.2 “perform”

@ execute.

[Noop] is sometimes used as a placeholder execution token:

[noop] ( ) gforth-experimental “bracket-noop”

Does nothing, both when executed and when compiled.

noop ( ) gforth-0.2 “noop”

Does nothing. However, code generation does not optimize it away; use [noop] for that.