www.delorie.com/gnu/docs/gforth/gforth_113.html   search  
Buy GNU books!

Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.11.1 Execution token

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 ' .


' 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


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 section 5.11.2 Compilation token).

Another way to get an XT is :noname or lastxt (see section 5.9.6 Anonymous Definitions). For anonymous words this gives an xt for the only behaviour the word has (the execution semantics). For named words, lastxt produces an XT for the same behaviour it would produce if the word was defined anonymously.

:noname ." hello" ;

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).

doc-execute doc-perform

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003