ficl oop

Index


ANS
API
Debugger
Download
Licensing
Links
Locals
OOP In Ficl
Parse Steps
Release History
Upgrading To 4.0

Ficl Object Oriented Programming

Ficl's object extensions provide the traditional OO benefits of associating data with the code that manipulates it, and reuse through single inheritance. Ficl also has some unusual capabilities that support interoperation with systems written in C.

Some design points of Ficl's OOP system:

  • Ficl objects are normally late bound for safety (late binding guarantees that the appropriate method will always be invoked for a particular object). Early binding is also available, provided you know the object's class at compile-time.
  • Ficl OOP supports single inheritance, aggregation, and arrays of objects.
  • Classes have independent name spaces for their methods: methods are only visible in the context of a class or object. Methods can be overridden or added in subclasses; there is no fixed limit on the number of methods of a class or subclass.
  • Ficl OOP syntax is regular and unified over classes and objects. In ficl, all classes are objects. Class methods include the ability to subclass and instantiate.
  • Ficl can adapt legacy data structures with object wrappers. You can model a structure in a Ficl class, and create an instance that refers to an address in memory that holds an instance of the structure. The ref object can then manipulate the structure directly. This lets you wrap data structures written and instantiated in C.

Object-Oriented Programming concepts

If you're not familiar with object-oriented programming, you can click here or here for a general-purpose overview. Or click here for a short review of object-oriented ideas, terms, and implementations in C.

Acknowledgements

Ficl is not the first Forth to include Object Oriented extensions. Ficl's OO syntax owes a debt to the work of John Hayes and Dick Pountain, among others. OO Ficl is different from other OO Forths in a few ways, though (some things never change). First, unlike several implementations, the syntax is documented (below) beyond the source code. In Ficl's spirit of working with C code, the OO syntax provides means to adapt existing data structures. I've tried to make Ficl's OO model simple and safe by unifying classes and objects, providing late binding by default, and separating namespaces so that methods and regular Forth words are not easily confused.

Ficl Object Model

All classes in Ficl are derived from the common base class OBJECT as shown in the figure below. All classes are instances of METACLASS. This means that classes are objects, too. METACLASS implements the methods for messages sent to classes. Class methods create instances and subclasses, and give information about the class. Each class is represented by a data stucture of three elements:
  1. The address (named .CLASS ) of a parent class, or zero if it's a base class (only OBJECT and METACLASS have this property).
  2. The size (named .SIZE ) in address units of an instance of the class.
  3. A wordlist ID (named .WID ) for the methods of the class.
In the figure below, METACLASS and OBJECT are real system-supplied classes. The others are contrived to illustrate the relationships among derived classes, instances, and the two system base classes. The dashed line with an arrow at the end indicates that the object/class at the arrow end is an instance of the class at the other end. The vertical line with a triangle denotes inheritance.

Note for the curious: METACLASS behaves like a class—it responds to class messages and has the same properties as any other class. If you want to twist your brain in knots, you can think of METACLASS as an instance of itself.


Ficl Object-Oriented Syntax Tutorial

It's helpful to have some familiarity with Forth and the customary Forth stack notation to understand this tutorial. To get started, take a look at this web-based Forth tutorial. If you're comfortable with both OO and Forth, you can jump ahead.

A Ficl object associates a class with an instance (the storage for one set of instance variables). This is done explicitly on Ficl's stack, in that any Ficl object is represented by a cell pair:

( INSTANCE-address CLASS-address )
The INSTANCE-address is the address of the object's storage, and the CLASS-address is the address of its class. Whenever a named Ficl object executes (e.g. when you type its name and press enter at the Ficl prompt), it leaves this "signature". All methods by convention expect a class and instance on the stack when they execute, too. In many other OO languages, including C++, instances contain information about their classes (a vtable pointer, for example). By making this pairing explicit rather than implicit, Ficl can be OO about chunks of data that don't realize that they are objects, without sacrificing any robustness for native objects. That means that you can use Ficl to write object wrappers for data structures created in C or assembly language, as long as you can determine how they're laid out in memory.

Whenever you create an object in Ficl, you specify its class. After that, the object always pushes its class and the address of its payload (instance variable space) when invoked by name.

Classes are special kinds of objects that store the methods of their instances, the size of an instance's payload, and a parent class pointer. Classes themselves are instances of a special base class called METACLASS, and all classes inherit from class OBJECT. This is confusing at first, but it means that Ficl has a very simple syntax for constructing and using objects. Class methods include subclassing (SUB), creating initialized and uninitialized instances (NEW and INSTANCE), and creating reference instances (REF), described later. Classes also have methods for disassembling their methods (SEE), identifying themselves (ID), and listing their pedigree (PEDIGREE). All objects inherit (from OBJECT) methods for initializing instances and arrays of instances, for performing array operations, and for getting information about themselves.

Methods And Messages

Methods are the functions that objects execute in response to messages. A message is a request to an object for a behavior that the object supports. When it receives a message, the target object looks up a method that performs the behavior for its class, and executes it. Any specific message may be bound to different methods in different objects, according to class. This separation of messages and methods allows objects to behave polymorphically. (In Ficl, methods are words defined in the context of a class, and messages are the names of those words.) Ficl classes associate messages with methods for their instances (a fancy way of saying that each class owns a wordlist). Ficl provides a late-binding operator --> that sends messages to objects at run-time, and an early-binding operator => that compiles a specific class's method. These operators are the only supported way to invoke methods. Regular Forth words are not visible to the method-binding operators, so there's no chance of confusing a message with a regular word of the same name.

Tutorial

(Finally!)

This is a tutorial. It works best if you follow along by pasting the examples into ficlWin, the Win32 version of Ficl included with the release sources (or some other build that includes the OO part of softcore.c). If you're not familiar with Forth, please see one of these references. Ficl's OOP words are in vocabulary OOP. To put OOP in the search order and make it the compilation wordlist, type:

ONLY
ALSO OOP DEFINITIONS
Note for beginners: To see the effect of the commands above, type ORDER after each line. You can repeat the sequence above if you like.

To start, we'll work with the two base classes OBJECT and METACLASS. Try this:

METACLASS --> METHODS
The line above contains three words. The first is the name of a class, so it pushes its signature on the stack. Since all classes are instances of METACLASS, METACLASS behaves as if it is an instance of itself (this is the only class with this property). It pushes the same address twice: once for the class and once for the payload, since they are the same. The next word finds a method in the context of a class and executes it. In this case, the name of the method is METHODS. Its job is to list all the methods that a class knows. What you get when you execute this line is a list of all the class methods Ficl provides.
OBJECT --> SUB C-LED
Causes the base-class OBJECT to derive from itself a new class called C-LED. Now we'll add some instance variables and methods to the new class.

Note: I like to prefix the names of classes with c- and the names of member variables with a period, but this is just a convention. If you don't like it, pick your own.

C-BYTE OBJ: .STATE
: INIT   { 2:THIS -- }
    THIS --> SUPER --> INIT
    ." Initializing an instance of "
    THIS --> CLASS --> ID TYPE CR ;
: ON   { LED# 2:THIS -- }
    THIS --> .STATE --> GET
    1 LED# LSHIFT OR DUP !OREG
    THIS --> .STATE --> SET  ;
: OFF   { LED# 2:THIS -- }
    THIS --> .STATE --> GET
    1 LED# LSHIFT INVERT AND DUP !OREG
    THIS --> .STATE --> SET  ;
END-CLASS
The first line adds an instance variable called .STATE to the class. This particular instance variable is an object—it will be an instance of C-BYTE, one of Ficl's stock classes (the source for which can be found in the distribution in softcore/classes.fr).

Next we've defined a method called INIT. This line also declares a local variable called THIS (the 2 in front tells Ficl that this is a double-cell local). All methods by convention expect the address of the class and instance on top of the stack when called. The next three lines define the behavior of INIT when it's called. It first calls its superclass's version of INIT (which in this case is "OBJECT => INIT"—this default implementation clears all instance variables). The rest displays some text and causes the instance to print its class name (THIS --> CLASS --> ID).

The INIT> method is special for Ficl objects: whenever you create an initialized instance using NEW or NEW-ARRAY, Ficl calls the class's INIT method for you on that instance. The default INIT method supplied by OBJECT clears the instance, so we didn't really need to override it in this case (see the source code in softcore/oo.fr).

The ON and OFF methods defined above hide the details of turning LEDs on and off. The interface to FiclWin's simulated hardware is handled by !OREG. The class keeps the LED state in a shadow variable (.STATE) so that ON and OFF can work in terms of LED number rather than a bitmask.

Now make an instance of the new class:

C-LED --> NEW LED
And try a few things...
LED --> METHODS
LED --> PEDIGREE
1 LED --> ON
1 LED --> OFF
Or you could type this with the same effect:
LED  2DUP  --> METHODS  --> PEDIGREE
Notice (from the output of METHODS) that we've overridden the INIT method supplied by object, and added two more methods for the member variables. If you type WORDS, you'll see that these methods are not visible outside the context of the class that contains them. The method finder --> uses the class to look up methods. You can use this word in a definition, as we did in INIT, and it performs late binding, meaning that the mapping from message (method name) to method (the code) is deferred until run-time. To see this, you can decompile the init method like this:
C-LED --> SEE INIT
or
LED --> CLASS --> SEE INIT

Early Binding

Ficl also provides early binding if you ask for it. Early binding is not as safe as late binding, but it produces code that is more compact and efficient because it compiles method addresses rather then their names. In the preferred uses of early binding, the class is assumed to be the one you're defining. This kind of early binding can only be used inside a class definition. Early bound methods still expect to find a class and instance cell-pair on top of the stack when they run.

Here's an example that illustrates a potential problem:

OBJECT --> SUB C1
: M1   { 2:THIS -- }  ." C1'S M1" CR ;
: M2   { 2:THIS -- }  ." Running  " THIS  MY=> M1 ; ( early )
: M3   { 2:THIS -- }  ." Running  " THIS --> M1     ( late )
END-CLASS
C1     --> SUB C2
: M1   { 2:THIS -- }  ." C2'S M1" CR ;
END-CLASS
C2 --> NEW I2
I2 --> M1   ( runs the M1 defined in C2 )
I2 --> M2   ( Is this what you wanted? )
I2 --> M3   { runs the overridden M1)
Even though we overrode method M1 in class C2, the definition of M2 with early binding forced the use of M1 as defined in C1. If that's what you want, great, but more often you'll want the flexibility of overriding parent class behaviors appropriately.
  1. MY=> binds early to a method in the class being defined, as in the example above.
  2. MY=[ ] binds a sequence of methods in the current class. Useful when the class has object members. Lines like THIS --> STATE --> SET in the definition of C-LED above can be replaced with THIS MY=[ STATE SET ] to use early binding.
  3. => (dangerous) pops a class off the stack and compiles the method in that class. Since you have to specify the class explicitly, there is a real danger that this will be out of sync with the class you really wanted. I recommend you use MY=> or MY=[ ] instead.
Early binding using => is dangerous because it partially defeats the data-to-code matching mechanism object oriented languages were created to provide, but it does increase run-time speed by binding the method at compile time. In many cases, such as the INIT method, you can be reasonably certain of the class of thing you're working on. This is also true when invoking class methods, since all classes are instances of METACLASS. Here's an example from the definition of METACLASS in oo.fr (don't paste this into ficlWin—it's already there):
: NEW   \ ( class metaclass "name" -- )
    METACLASS => INSTANCE --> INIT ;
Try this:
METACLASS --> SEE NEW
Decompiling the method with SEE shows the difference between the two strategies. The early bound method is compiled inline, while the late-binding operator compiles the method name and code to find and execute it in the context of whatever class is supplied on the stack at run-time.

Notice that the primitive early-binding operator => requires a class at compile time. For this reason, classes are IMMEDIATE, meaning that they push their signature at compile time or run time. I'd recommend that you avoid early binding until you're very comfortable with Forth, object-oriented programming, and Ficl's OOP syntax.

More About Instance Variables

Untyped instance variable methods (created by CELL: CELLS: CHAR: and CHARS:) just push the address of the corresponding instance variable when invoked on an instance of the class. It's up to you to remember the size of the instance variable and manipulate it with the usual Forth words for fetching and storing.

As advertised earlier, Ficl provides ways to objectify existing data structures without changing them. Instead, you can create a Ficl class that models the structure, and instantiate a ref from this class, supplying the address of the structure. After that, the ref instance behaves as a Ficl object, but its instance variables take on the values in the existing structure. Example (from softcore/ficlclass.fr):

OBJECT SUBCLASS C-WORDLIST
    C-WORDLIST REF: .PARENT
    C-PTR      OBJ: .NAME
    C-CELL     OBJ: .SIZE
    C-WORD     REF: .HASH   ( first entry in hash table )

    : ?
        --> GET-NAME ." ficl wordlist "  TYPE CR ;
    : PUSH  DROP  >SEARCH ;
    : POP   2DROP PREVIOUS ;
    : SET-CURRENT   DROP SET-CURRENT ;
    : GET-NAME   DROP WID-GET-NAME ;
    : WORDS   { 2:THIS -- }
        THIS MY=[ .SIZE GET ] 0 DO 
            I THIS MY=[ .HASH INDEX ]  ( 2list-head )
            BEGIN
                2DUP --> GET-NAME TYPE SPACE
                --> NEXT OVER
            0= UNTIL 2DROP CR
        LOOP
    ;
END-CLASS
In this case, C-WORDLIST describes Ficl's wordlist structure; NAMED-WID creates a wordlist and binds it to a ref instance of C-WORDLIST. The fancy footwork with POSTPONE and early binding is required because classes are immediate. An equivalent way to define NAMED-WID with late binding is:
: NAMED-WID   ( c-address u -- )
    WORDLIST   POSTPONE C-WORDLIST --> REF
    ;
To do the same thing at run-time (and call it MY-WORDLIST):
wordlist  c-wordlist --> ref  my-wordlist
Now you can deal with the wordlist through the ref instance:
MY-WORDLIST --> PUSH
MY-WORDLIST --> SET-CURRENT
ORDER
Ficl can also model linked lists and other structures that contain pointers to structures of the same or different types. The class constructor word REF: makes an aggregate reference to a particular class. See the instance variable glossary for an example.

Ficl can make arrays of instances, and aggregate arrays into class descripions. The class methods ARRAY and NEW-ARRAY create uninitialized and initialized arrays, respectively, of a class. In order to initialize an array, the class must define (or inherit) a reasonable INIT method. NEW-ARRAY invokes it on each member of the array in sequence from lowest to highest. Array instances and array members use the object methods INDEX, NEXT, and PREV to navigate. Aggregate a member array of objects using ARRAY:. The objects are not automatically initialized in this case—your class initializer has to call ARRAY-INIT explicitly if you want this behavior.

For further examples of OOP in Ficl, please see the source file softcore/ficlclass.fr. This file wraps several Ficl internal data structures in objects and gives use examples.

Ficl String Classes

C-STRING is a reasonably useful dynamic string class. Source code for the class is located in softcore/string.fr. Features: dynamic creation and resizing; deletion, char cout, concatenation, output, comparison; creation from quoted string constant (S").

Examples of use:

C-STRING --> NEW HOMER
S" In this house, " HOMER --> SET
S" we obey the laws of thermodynamics!" HOMER --> CAT
HOMER --> TYPE

OOP Glossary

Note: With the exception of the binding operators (the first two definitions here), all of the words in this section are internal factors that you don't need to worry about. These words provide method binding for all classes and instances. Also described are supporting words and execution factors. All are defined in softcore/oo.fr.
--> ( instance class "method-name" -- xn )
Late binding: looks up and executes the given method in the context of the class on top of the stack.
C-> ( instance class "method-name" -- xn exc )
Late binding with CATCH: looks up and CATCHes the given method in the context of the class on top of the stack, pushes zero or exception code upon return.
MY=> compilation: ( "method-name" -- ) execution: ( instance class -- xn )
Early binding: compiles code to execute the method of the class being defined. Only visible and valid in the scope of a --> SUB .. END-CLASS class definition.
MY=[ compilation: ( "obj1 obj2 .. method ]" -- ) execution: ( instance class -- xn )
Early binding: compiles code to execute a chain of methods of the class being defined. Only visible and valid in the scope of a --> SUB .. END-CLASS class definition.
=> compilation: ( class metaclass "method-name" -- ) execution: ( instance class -- xn )
Early binding: compiles code to execute the method of the class specified at compile time.
do-do-instance
When executed, causes the instance to push its ( INSTANCE CLASS ) stack signature. Implementation factor of METACLASS --> SUB . Compiles .DO-INSTANCE in the context of a class; .DO-INSTANCE implements the DOES> part of a named instance.
exec-method ( instance class c-address u -- xn )
Given the address and length of a method name on the stack, finds the method in the context of the specified class and invokes it. Upon entry to the method, the instance and class are on top of the stack, as usual. If unable to find the method, prints an error message and aborts.
find-method-xt ( class "method-name" -- class xt )
Attempts to map the message to a method in the specified class. If successful, leaves the class and the execution token of the method on the stack. Otherwise prints an error message and aborts.
lookup-method ( class c-address u -- class xt )
Given the address and length of a method name on the stack, finds the method in the context of the specified class. If unable to find the method, prints an error message and aborts.
parse-method compilation: ( "method-name" -- ) execution: ( -- c-address u )
Parse "method-name" from the input stream and compile code to push its length and address when the enclosing definition runs.

Instance Variable Glossary

Note:: These words are only visible when creating a subclass! To create a subclass, use the SUB method on OBJECT or any class derived from it (not METACLASS). Source code for Ficl OOP is in softcore/oo.fr.

Instance variable words do two things: they create methods that do san action appropriate for the type of instance variable they represent, and they reserve space in the class template for the instance variable. We'll use the term instance variable to refer both to the method that gives access to a particular field of an object, and to the field itself. Rather than give esentially the same example over and over, here's one example that shows several of the instance variable construction words in use:

OBJECT SUBCLASS C-EXAMPLE
  CELL:            .CELL0
  C-4BYTE     OBJ: .NCELLS
  4 C-4BYTE ARRAY: .QUAD
  CHAR:            .LENGTH
  79 CHARS:        .NAME
END-CLASS
This class only defines instance variables, and it inherits some methods from OBJECT. Each untyped instance variable (.CELL0, .LENGTH, .NAME) pushes its address when executed. Each object instance variable pushes the address and class of the aggregate object. Similar to C, an array instance variable leaves its base address (and its class) when executed. The word SUBCLASS is shorthand for --> sub .
CELL: compilation: ( offset "name" -- offset ) execution: ( -- cell-address )
Create an untyped instance variable one cell wide. The instance variable leaves its payload's address when executed.
CELLS: compilation: ( offset nCells "name" -- offset' ) execution: ( -- cell-address )
Create an untyped instance variable nCells cells wide.
CHAR: compilation: ( offset "name" -- offset' ) execution: ( -- cell-address )
Create an untyped member variable one character wide.
CHARS: compilation: ( offset nChars "name" -- offset' ) execution: ( -- cell-address )
Create an untyped member variable nChars characters wide.
OBJ: compilation: ( offset class metaclass "name" -- offset' ) execution: ( -- instance class )
Aggregate an uninitialized instance of CLASS as a member variable of the class under construction.
ARRAY: compilation: ( offset nObjects class metaclass "name" -- offset' ) execution: ( -- instance class )
Aggregate an uninitialized array of instances of the class specified as a member variable of the class under construction.
EXAMPLEREF: compilation: ( offset class metaclass "name" -- offset' ) execution: ( -- ref-instance ref-class )
Aggregate a reference to a class instance. There is no way to set the value of an aggregated ref—it's meant as a way to manipulate existing data structures with a Ficl OO model. For example, if your system contains a linked list of 4 byte quantities, you can make a class that represents a list element like this:
OBJECT SUBCLASS C-4LIST
  C-4LIST REF: .LINK
  C-4BYTE OBJ: .PAYLOAD
END-CLASS

ADDRESS-OF-EXISTING-LIST C-4LIST --> REF MYLIST
The last line binds the existing structure to an instance of the class we just created. The link method pushes the link value and the class C_4LIST, so that the link looks like an object to Ficl and like a struct to C (it doesn't carry any extra baggage for the object model—the Ficl methods alone take care of storing the class information).

Note: Since a REF: aggregate can only support one class, it's good for modeling static structures, but not appropriate for polymorphism. If you want polymorphism, aggregate a C_REF (see softcore/classes.fr for source) into your class—it has methods to set and get an object.

By the way, it is also possible to construct a pair of classes that contain aggregate pointers to each other. Here's an example:

OBJECT SUBCLASS AKBAR
  SUSPEND-CLASS         \ put akbar on hold while we define jeff

OBJECT SUBCLASS JEFF
  AKBAR REF: .SIGNIFICANT-OTHER
  ( ... your additional methods here ... )
END-CLASS               \ done with jeff

AKBAR --> RESUME-CLASS  \ resume defining akbar
  JEFF REF: .SIGNIFICANT-OTHER
  ( ... your additional methods here ... )
END-CLASS               \ done with akbar

Class Methods Glossary

These words are methods of METACLASS. They define the manipulations that can be performed on classes. Methods include various kinds of instantiation, programming tools, and access to member variables of classes. Source is in softcore/oo.fr.
INSTANCE ( class metaclass "name" -- instance class )
Create an uninitialized instance of the class, giving it the name specified. The method leaves the instance's signature on the stack (handy if you want to initialize). Example:
C_REF --> INSTANCE UNINIT-REF  2DROP
NEW ( class metaclass "name" -- )
Create an initialized instance of class, giving it the name specified. This method calls INIT to perform initialization.
ARRAY ( nObjects class metaclass "name" -- nObjects instance class )
Create an array of nObjects instances of the specified class. Instances are not initialized. Example:
10 C_4BYTE --> ARRAY 40-RAW-BYTES  2DROP DROP
NEW-ARRAY ( nObjects class metaclass "name" -- )
Creates an initialized array of nObjects instances of the class. Same syntax as ARRAY.
ALLOC ( class metaclass -- instance class )
Creates an anonymous instance of CLASS from the heap (using a call to ficlMalloc() to get the memory). Leaves the payload and class addresses on the stack. Usage example:
C-REF --> ALLOC  2CONSTANT INSTANCE-OF-REF

Creates a double-cell constant that pushes the payload and class address of a heap instance of C-REF.

ALLOC-ARRAY ( nObjects class metaclass -- instance class )
Same as NEW-ARRAY, but creates anonymous instances from the heap using a call to ficlMalloc(). Each instance is initialized using the class's INIT method.
ALLOT ( class metaclass -- instance class )
Creates an anonymous instance of CLASS from the dictionary. Leaves the payload and class addresses on the stack. Usage example:
C-REF --> ALLOT  2CONSTANT INSTANCE-OF-REF

Creates a double-cell constant that pushes the payload and class address of a heap instance of C-REF.

ALLOT-ARRAY ( nObjects class metaclass -- instance class )
Same as NEW-ARRAY, but creates anonymous instances from the dictionary. Each instance is initialized using the class's INIT method.
REF ( instance-address class metaclass "name" -- )
Make a ref instance of the class that points to the supplied instance address. No new instance space is allotted. Instead, the instance refers to the address supplied on the stack forever afterward. For wrapping existing structures.
SUB ( class metaclass -- old-wid address[size] size )
Derive a subclass. You can add or override methods, and add instance variables. Alias: SUBCLASS. Examples:

C_4BYTE --> SUB C_SPECIAL4BYTE
  ( ... your new methods and instance variables here ... )
END-CLASS
or
C_4BYTE SUBCLASS C_SPECIAL4BYTE
  ( ... your new methods and instance variables here ... )
END-CLASS
.SIZE ( class metaclass -- instance-size )
Returns address of the class's instance size field, in address units. This is a metaclass member variable.
.SUPER ( class metaclass -- superclass )
Returns address of the class's superclass field. This is a metaclass member variable.
.WID ( class metaclass -- wid )
Returns the address of the class's wordlist ID field. This is a metaclass member variable.
GET-SIZE ( -- instance-size )
Returns the size of an instance of the class in address units. Imeplemented as follows:
: GET-SIZE   METACLASS => .SIZE @ ;
GET-WID ( -- wid )
Returns the wordlist ID of the class. Implemented as:
: GET-WID   METACLASS => .WID @ ;
GET-SUPER ( -- superclass )
Returns the class's superclass. Implemented as
: GET-SUPER   METACLASS => .super @ ;
ID ( class metaclass -- c-address u )
Returns the address and length of a string that names the class.
METHODS ( class metaclass -- )
Lists methods of the class and all its superclasses.
OFFSET-OF ( class metaclass "name" -- offset )
Pushes the offset from the instance base address of the named member variable. If the name is not that of an instance variable method, you get garbage. There is presently no way to detect this error. Example:
metaclass --> offset-of .wid
PEDIGREE ( class metaclass -- )
Lists the pedigree of the class (inheritance trail).
SEE ( class metaclass "name" -- )
Decompiles the specified method—obect version of SEE, from the TOOLS wordset.

OBJECT Base-Class Methods Glossary

These are methods that are defined for all instances by the base class OBJECT. The methods include default initialization, array manipulations, aliases of class methods, upcasting, and programming tools.
INIT ( instance class -- )
Default initializer, called automatically for all instances created with NEW or NEW-ARRAY. Zero-fills the instance. You do not normally need to invoke INIT explicitly.
ARRAYINIT ( nObjects instance class -- )
Applies INIT to an array of objects created by NEW-ARRAY. Note that ARRAY: does not cause aggregate arrays to be initialized automatically. You do not normally need to invoke ARRAY-INIT explicitly.
FREE ( instance class -- )
Releases memory used by an instance previously created with ALLOC or ALLOC-ARRAY. Note: This method is not presently protected against accidentally deleting something from the dictionary. If you do this, Bad Things are likely to happen. Be careful for the moment to apply free only to instances created with ALLOC or ALLOC-ARRAY.
CLASS ( instance class -- class metaclass )
Convert an object signature into that of its class. Useful for calling class methods that have no object aliases.
SUPER ( instance class -- instance superclass )
Upcast an object to its parent class. The parent class of OBJECT is zero. Useful for invoking an overridden parent class method.
PEDIGREE ( instance class -- )
Display an object's pedigree—its chain of inheritance. This is an alias for the corresponding class method.
SIZE ( instance class -- instance-size )
Returns the size, in address units, of one instance. Does not know about arrays! This is an alias for the class method GET-SIZE.
METHODS ( instance class -- )
Class method alias. Displays the list of methods of the class and all superclasses of the instance.
INDEX ( n instance class -- instance[n] class )
Convert array-of-objects base signature into signature for array element n. No check for bounds overflow. Index is zero-based, like C, so
0 MY-OBJ --> INDEX
is equivalent to
MY-OBJ
Check out the description of -ROT for help in dealing with indices on the stack.
NEXT ( instance[n] class -- instance[n+1] )
Convert an array-object signature into the signature of the next object in the array. No check for bounds overflow.
PREV ( instance[n] class -- instance[n-1] class )
Convert an object signature into the signature of the previous object in the array. No check for bounds underflow.

Supplied Classes

For more information on theses classes, see softcore/classes.fr.
METACLASS
Describes all classes of Ficl. Contains class methods. Should never be directly instantiated or subclassed. Defined in softcore/oo.fr. Methods described above.
OBJECT
Mother of all Ficl objects. Defines default initialization and array indexing methods. Defined in softcore/oo.fr. Methods described above.
C-REF
Holds the signature of another object. Aggregate one of these into a data structure or container class to get polymorphic behavior. Methods and members:
GET ( instance class -- ref-instance ref-class )
Push the referenced object value on the stack.
SET ( ref-instance ref-class instance class -- )
Set the referenced object being held.
.INSTANCE ( instance class -- a-address )
Cell member that holds the instance.
.CLASS ( instance class -- a-address )
Cell member that holds the class.
C-BYTE
Primitive class derived from OBJECT, with a 1-byte payload. SET and GET methods perform correct width fetch and store. Methods and members:
GET ( instance class -- byte )
Push the object's value on the stack.
SET ( byte instance class -- )
Set the object's value from the stack.
.PAYLOAD ( instance class -- address )
Member holds instance's value.
C-2BYTE
Primitive class derived from OBJECT, with a 2-byte payload. SET and GET methods perform correct width fetch and store. Methods and members:
GET ( instance class -- 2byte )
Push the object's value on the stack.
SET ( 2byte instance class -- )
Set the object's value from the stack.
.PAYLOAD ( instance class -- address )
Member holds instance's value.
C-4BYTE
Primitive class derived from object, with a 4-byte payload. SET and GET methods perform correct width fetch and store. Methods and members:
GET ( instance class -- 4byte )
Push the object's value on the stack.
SET ( 4byte instance class -- )
Set the object's value from the stack.
.PAYLOAD ( instance class -- address )
Member holds instance's value.
C-CELL
Primitive class derived from OBJECT, with a cell payload (equivalent to C-4BYTE on 32 bit platforms, 64 bits wide on Alpha and other 64-bit platforms). SET and GET methods perform correct width fetch and store. Methods and members:
GET ( instance class -- 4byte )
Push the object's value on the stack.
SET ( 4byte instance class -- )
Set the object's value from the stack.
.PAYLOAD ( instance class -- address )
Member holds instance's value.
C-PTR
Base class derived from OBJECT for pointers to non-object types. This class is not complete by itself: several methods depend on a derived class definition of @SIZE. Methods and members:
.ADDR ( instance class -- a-address )
Member variable, holds the pointer address.
GET-PTR ( instance class -- pointer )
Pushes the pointer address.
SET-PTR ( pointer instance class -- )
Sets the pointer address.
INC-PTR ( instance class -- )
Adds @SIZE to the pointer address.
DEC-PTR ( instance class -- )
Subtracts @SIZE to the pointer address.
INDEX-PTR ( i instance class -- )
Adds i * @SIZE to the pointer address.
C-BYTEPTR
Pointer to byte derived from C-PTR. Methods and members:
@SIZE ( instance class -- size )
Push size of the pointed-to object.
GET ( instance class -- byte )
Pushes the pointer's referent byte.
SET ( byte instance class -- )
Stores byte at the pointer address.
C-2BYTEPTR
Pointer to 2byte derived from C-PTR. Methods and members:
@SIZE ( instance class -- size )
Push size of the pointed-to object.
GET ( instance class -- 2byte )
Pushes the pointer's referent 2byte.
SET ( 2byte instance class -- )
Stores 2byte at the pointer address.
C-4BYTEPTR
Pointer to 4byte derived from C-PTR. Methods and members:
@SIZE ( instance class -- size )
Push size of the pointed-to object.
GET ( instance class -- 4byte )
Pushes the pointer's referent 4byte.
SET ( 4byte instance class -- )
Stores 4byte at the pointer address.
C-CELLPTR
Pointer to cell derived from C-PTR. Methods and members:
@SIZE ( instance class -- size )
Push size of the pointed-to object.
GET ( instance class -- cell )
Pushes the pointer's referent cell.
SET ( cell instance class -- )
Stores cell at the pointer address.
C-STRING
Dynamically allocated string, similar to MFC's CString. For more information, see softcore/string.fr. Partial list of methods and members:
GET ( instance class -- c-address u )
Pushes the string buffer's contents as a C-ADDR U style string.
SET ( c-address u instance class -- )
Sets the string buffer's contents to a new value.
CAT ( c-address u instance class -- )
Concatenates a string to the string buffer's contents.
COMPARE ( c-address u instance class -- result )
Lexical compiration of a string to the string buffer's contents. Return value is the same as the FORTH function COMPARE.
TYPE ( instance class -- )
Prints the contents of the string buffer to the output stream.
HASHCODE ( instance class -- i )
Returns a computed hash based on the contents of the string buffer.
FREE ( instance class -- )
Releases the internal buffer.
C-HASHSTRING
Subclass of C-STRING, which adds a member variable to store a hashcode. For more information, see softcore/string.fr.