This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Goops methods from C...


Clark McGrew <mcgrew@ale.physics.sunysb.edu> writes:

> I'm trying to figure out how to define a new goops method from C.  I'd
> like to create a new class (a la guile-oops/fdi.c, but I'd like to
> create sub-classes) and create new generics and methods associated
> with the class?

The C interface is not complete.  If you have opinions/code, please
send them!

Here's how you can do it currently:

Subclasses: Third arg to SCM_CLASS macro is list of supers.

New generics:

gf = scm_make (SCM_LIST1 (scm_class_generic));

There is currently no C interface to the module system.  Until Jost's
environment patches are included, you can use, e.g. scm_sysintern.
When we have a C interface to the module system, it will be possible
to create standard functions for generic function creation from the C
level.

New methods:

SCM_KEYWORD (k_specializers, "specializers");
SCM_KEYWORD (k_procedure, "procedure");

m = scm_make (SCM_LIST5 (scm_class_method,
			 k_specializers, SCM_LIST<n> (<spec1>, ..., <specn>),
                         k_procedure, proc));

The procedure must be a closure, however.  If you need a subr, you
have to create a wrapper closure using scm_closure.  This is because
the current generic function dispatch mechanism only works for closure
methods.  When we get 4-word cells (both Michael Livshin and Greg
Harvey have implementations for this), we can create a new
representation for GOOPS objects and rearrange in the type system so
that we can have several alternative GF dispatch mechanisms, e.g. one
"standard", one for C-level methods, one for arithmetic functions etc.

But we could of course already now write convenience functions for
creation of methods.  Such a convenience function could automatically
wrap subrs.

Adding a method to a generic:

scm_add_method (gf, m);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]