You. Forth. Simplicity.

git repository
download
prior releases
documentation wiki
issue tracker
mailing list and forum
irc channel and logs
try it


This wiki remains, like the original forum, mainly for historical value. There is a new wiki which, while having less content, is more secure and oriented towards modern Retro implementations.

reload node | edit | recent changes | front page

What are word classes?

Helmar Wodtke introduced the concept of word classes to the RetroForth family of Forths. Word classes are now a key piece of RetroForth. They are basically re a way to group related words, based on their compilation and execution behaviors.

A special word, called a class handler, is defined to handle an execution token (xt) passed to it on the stack. The compiler uses a variable named class to set the default class when compiling a word. We'll take a closer look at class later. The Rx Core provides RetroForth with several inital classes that handle the most common use scenarios. All of these have the same stack usage, ( xt -- )

.class .forth
If interpreting, call the xt. If compiling, compile a call to the xt.

.inline
If interpreting, call the xt. If compiling, inline everything up to opcode $c3 (ret).

.macro
If interpreting, drop the xt and exit silently. If compiling, call the xt.

.self
Call the xt.

.data
If interpreting, leave the xt on the stack. If compiling, compile the xt as a literal value into the definition.


When writing programs for RetroForth, you will need to set the class of each word you write. The normal way to do this is to give the name of the class, minus the standard . prefix. You can also set the class variable to the xt of the class itself. The wrappers have a class of .forth and are listed below. In general, it's recommended to use these wrappers to set the default class for readability reasons.

forth
Set .forth as the active class

macro
Set .macro as the active class

self
Set .self as the active class

inline
Set .inline as the active class