Go to the first, previous, next, last section, table of contents.


Tokens for Words

This chapter describes the creation and use of tokens that represent words on the stack (and in data space).

Named words have interpretation and compilation semantics. Unnamed words just have execution semantics.

An execution token represents the execution semantics of an unnamed word. An execution token occupies one cell. As explained in section section Supplying names for the defined words, the execution token of the last words defined can be produced with

lastxt       -- xt         gforth       ``lastxt''

You can perform the semantics represented by an execution token with

execute       xt --       core       ``execute''

You can compile the word with

compile,       xt --         core-ext       ``compile-comma''

In Gforth, the abstract data type execution token is implemented as CFA (code field address).

The interpretation semantics of a named word are also represented by an execution token. You can get it with

[']       compilation. "name" -- ; run-time. -- xt         core       ``bracket-tick''

xt represents name's interpretation semantics. Performs -14 throw if the word has no interpretation semantics.

'       "name" -- xt         core       ``tick''

xt represents name's interpretation semantics. Performs -14 throw if the word has no interpretation semantics.

For literals, you use ' in interpreted code and ['] in compiled code. Gforth's ' and ['] behave somewhat unusual by complaining about compile-only words. To get an execution token for a compiling word X, use COMP' X drop or [COMP'] X drop.

The compilation semantics are represented by a compilation token consisting of two cells: w xt. The top cell xt is an execution token. The compilation semantics represented by the compilation token can be performed with execute, which consumes the whole compilation token, with an additional stack effect determined by the represented compilation semantics.

[COMP']       compilation "name" -- ; run-time -- w xt         gforth       ``bracket-comp-tick''

w xt represents name's compilation semantics.

COMP'       "name" -- w xt         gforth       ``comp-tick''

w xt represents name's compilation semantics.

You can compile the compilation semantics with postpone,. I.e., COMP' word POSTPONE, is equivalent to POSTPONE word.

postpone,       w xt --         gforth       ``postpone-comma''

Compiles the compilation semantics represented by w xt.

At present, the w part of a compilation token is an execution token, and the xt part represents either execute or compile,. However, don't rely on that knowledge, unless necessary; we may introduce unusual compilation tokens in the future (e.g., compilation tokens representing the compilation semantics of literals).

Named words are also represented by the name token. The abstract data type name token is implemented as NFA (name field address).

find-name       c-addr u -- nt/0         gforth       ``find-name''

Find the name c-addr u in the current search order. Return its nt, if found, otherwise 0.

name>int       nt -- xt         gforth       ``name>int''

xt represents the interpretation semantics of the word nt. Produces ' compile-only-error if nt is compile-only.

name?int       nt -- xt         gforth       ``name?int''

Like name>int, but throws an error if compile-only.

name>comp       nt -- w xt         gforth       ``name>comp''

w xt is the compilation token for the word nt.

name>string       nt -- addr count         gforth       ``head-to-string''

addr count is the name of the word represented by nt.


Go to the first, previous, next, last section, table of contents.