![]() |
You. Forth. Simplicity. |
reload node | edit | recent changes | front page
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