[previous] [up] [next]     [contents] [index]
Next: Custodians Up: ObjectsClasses, and Interfaces Previous: ObjectsClasses, and Interfaces

Library Functions

Scheme_Object *scheme_make_class(char *name, Scheme_Object *sup, 
               Scheme_Method_Prim *init, int num_methods) 

Creates a new primitive class. If an intializer method init is provided, then objects of this class can be created from Scheme. The class sup specifies a superclass for the primitive class; it can be NULL. The num_methods argument must be an upper-bound on the actual number of methods to be installed with scheme_add_method_w_arity or scheme_add_method. Once all of the methods are installed, scheme_made_class must be called.

void scheme_add_method_w_arity(Scheme_Object *cl, char *name, Scheme_Method_Prim *f, 
     short mina, short maxa) 

Adds a primitive method to a primitive class. The form of the method f is defined by:

Scheme_Object *Scheme_Method_Prim(Scheme_Object *obj, int argc, Scheme_Object **argv);

void scheme_add_method(Scheme_Object *cl, char *name, Scheme_Method_Prim *f) 

Like scheme_add_method_w_arity, but mina and maxa are defaulted to 0 and -1, respectively.

void scheme_made_class(Scheme_Object *cl) 

Indicates that all of the methods have been added to the primitive class cl.

Scheme_Object *scheme_make_object(Scheme_Object *sclass, int argc, Scheme_Object **argv) 

Creates an instance of the class sclass. The arguments to the object's intialization function are speicified by argc and argv.

Scheme_Object *scheme_make_uninited_object(Scheme_Object *sclass) 

Creates a Scheme object instance of sclass without intitializing the object. This is useful for creating a Scheme representation of an existing primitive object.

Scheme_Object *scheme_find_ivar(Scheme_Object *obj, Scheme_Object *sym, int force) 

Finds an instance variable by name (as a symbol). Returns NULL if the instance variable is not found. The force argument should be 1.

Scheme_Object *scheme_get_generic_data( Scheme_Object *class_or_intf, Scheme_Object *name) 

Creates a Scheme value that contains the essential information of a generic procedure. This information can be applied to an object using scheme_apply_generic_data. If the named field is not found in the specified class, then the NULL pointer is returned.

Scheme_Object *scheme_apply_generic_data( Scheme_Object *gdata, Scheme_Object *sobj) 

Given the result of a call to scheme_get_generic_data, extracts a value from the specified Scheme object. If the object is not in the appropriate class, and error is raised.

int scheme_is_subclass(Scheme_Object *sub, Scheme_Object *parent) 

Returns 1 if the class sub is derived from the class parent, 0 otherwise.

int scheme_is_implementation(Scheme_Object *cl, Scheme_Object *intf) 

Returns 1 if the class cl implements the interface intf, 0 otherwise.

int scheme_is_interface_extension(Scheme_Object *sub, Scheme_Object *intf) 

Returns 1 if the interface sub is an extension of the interface intf, 0 otherwise.

int scheme_is_a(Scheme_Object *obj, Scheme_Object *sclass) 

Returns 1 if obj is an instance of the class sclass or of a class derived from sclass, 0 otherwise.

char *scheme_get_class_name(Scheme_Object *sclass, int *len) 

Returns the name of the class sclass if it has one, or NULL otherwise. If the return value is not NULL, *len is set to the length of the string.

struct Scheme_Class_Assembly *scheme_make_class_assembly(
                              const char *name, int n_interface, 
                              int n_public, Scheme_Object **names,
                              int n_inh, Scheme_Object **inherited,
                              int n_ren, Scheme_Object **renamed,
                              int mina, int maxa,
                              Scheme_Instance_Init_Proc *initproc) 

``Compiles'' a class expression, given a name for the class (or NULL), the number of interfaces that will be declared as implemented by the class in n_interfaces, and names for public, inherited, and rename instance variables as symbols. The mina and maxa arguments specify the arity of the initialization procedure (i.e., the implicit lambda in a class expression that accepts initialization arguments). The initproc function has the following prototype:

  typedef void (*Scheme_Instance_Init_Proc)(Scheme_Object **init_boxes,
                                            Scheme_Object **extract_boxes,
                                            Scheme_Object *super_init,
                                            int argc,
                                            Scheme_Object **argv,
                                            Scheme_Object *instance,
                                            void *data);

When an instance of the class is created, initproc will be called. The first two arguments are arrays of environment boxes (whose values are manipulated with SCHEME_ENVBOX_VAL). These arrays are in parallel: the first array is used for initializing variables from local expressions, and the second array is for looking up the value of a possibly-overridden instance variable. In both arrays, the public and inherited variables are ordred as provided in scheme_make_class_assembly (with public variables first). The argc and argv arguments specify the values passed in as initialization arguments. The super_init argument is the procedure for initializing the superclass (use _scheme_apply to invoke it). The instance argument is the value of this. The data argument is supplied by the caller of scheme_create_class.

The result from scheme_make_class_assembly is used with scheme_create_class to create an actual class at run-time given the a run-time-determined superclass and interfaces.

Scheme_Object *scheme_create_class(struct Scheme_Class_Assembly *a, 
               void *data, Scheme_Object *super, Scheme_Object **interfaces) 

Returns a Scheme class value given the result of a call to scheme_make_class_assembly, a superclass, and an array of interface values. (The number of interfaces values must match the number of interfaces specified in the call to scheme_make_class_assembly.) Type-checking on the superclass and interface array is performed by scheme_create_class.

struct Scheme_Interface_Assembly *scheme_make_interface_assembly(
                                  const char *name, int n_supers, 
                                  int n_names, Scheme_Object **names) 

``Compiles'' an interface expression, given the interface's name (or NULL), the number of super interfaces that will be extended by the interface in n_supers, and names for instance variables as symbols.

The result from scheme_make_interface_assembly is used with scheme_create_interface to create an actual class at run-time given the run-time-determined superinterfaces.

Scheme_Object *scheme_create_interface(struct Scheme_Interface_Assembly *a, 
               Scheme_Object **supers) 

Returns a Scheme interface value given the result of a call to scheme_make_interface_assembly and an array of superinterface values. (The number of superinterfaces values must match the number of superinterfaces specified in the call to scheme_make_interface_assembly.) Type-checking on the superinterface array is performed by scheme_create_interface.


[previous] [up] [next]     [contents] [index]
Next: Custodians Up: ObjectsClasses, and Interfaces Previous: ObjectsClasses, and Interfaces

PLT