SWOOP Object-Oriented Programming
Order SwiftForth™ for Windows, Mac OS X and Linux programming. Examples, source, documentation, more.
Mac and the Mac logo are trademarks of Apple Inc., registered in the U.S. and other countries.
SwiftForth includes a powerful object-oriented programming package called SWOOP. SWOOP provides the essential features of object-oriented programming.
SwiftForth's support of object-oriented programming is extensive and powerful. The following brief introductory information is excerpted from the SwiftForth Reference Manual.
POINT (defined below) is a simple class we shall use as a primary building-block example for SWOOP. It demonstrates two of the four basic class member types: data and colon. The word following CLASS is the name of the class; all definitions between CLASS and END-CLASS belong to it. These definitions are referred to as the members of the class. When a class name is executed, it leaves its handle (xt) on the stack. The constructor words are the primary consumers of this handle.
CLASS POINT VARIABLE X VARIABLE Y : SHOW ( -- ) X @ . Y @ . ; : DOT ( -- ) ." Point at " SHOW ; END-CLASS
The class definition itself does not allocate any instance storage; it only records how much storage is required for each instance of the class. VARIABLE reserves a cell of space and associates it with a member name.
The colon members SHOW and DOT are like normal Forth colon definitions, but are only valid in the execution context of an object of type POINT. X and Y also behave exactly like normal Forth VARIABLEs.
There are five kinds of members:
Objects may be static or dynamic. Both early and late binding are supported. Instance data and methods are implemented in a manner that is very efficient in the context of a Forth development environment.