[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
goops classes for smobs
From: |
Marco Maggi |
Subject: |
goops classes for smobs |
Date: |
Tue, 13 Nov 2007 23:01:31 +0100 |
Damn!
I discovered that if GOOPS is loaded first,
libguile/smob.c's 'scm_make_smob_type()' creates
an extended class for registered SMOB types, but
this is (AFAICT) undocumented!
Now, in extensions adding new number reps to
Guile I used everywhere:
(define-class <long-double> (<number>)
(n #:init-keyword #:smob))
I cannot replace this with the SMOB's class built
by Guile because there is no way to select a base
class. And I need it.
It is my understanding that libguile/goops.c's
'make_class_from_template()' accepts as third
argument a list of base classes; if this is the
case we can add:
SCM
scm_make_extended_class_with_supers (char const *type_name,
scm_t s_supers)
{
/* is there a class assertion to put here? */
return make_class_from_template ("<%s>", type_name,
s_supers, 0);
}
that can be called with:
scm_make_extended_class_with_supers("my",
scm_variable_ref("<number>"));
A variant of 'scm_make_smob_type()' is needed to
use 'scm_make_extended_class_with_supers()'.
Adding a 'scm_set_smob_supers()' function to
register the list of supers in the SMOB structure
breaks the protocol of SMOB type creation (create
the type, THEN call the 'scm_set_smob_*()'
functions).
But now the hardcoded limit to SMOB types slaps
me in the face. In the base library of GEE I use
a primitive SMOB [1] that implements dispatching
to sub-SMOB's driver functions, a sub-SMOB is
defined by a statically allocated custom driver
structure. It changes nothing in the interface:
the driver functions do the same thing.
A sub-SMOB is created with:
SCM_NEWSMOB2(smob, multi_smob_driver, client_data,
sub_smob_driver);
Including such a thing in the core would solve
the hardcoded SMOB limit problem and allow the
selection of base classes in the sub-SMOB driver
structure. A change in the 'scm_tcs_struct'
'switch' branch of libguile/goops.c's
'scm_class_of()' would be needed:
{
/* Goops object */
if (! scm_is_false (SCM_OBJ_CLASS_REDEF (x)))
scm_change_object_class (x, SCM_CLASS_OF (x),
SCM_OBJ_CLASS_REDEF (x));
if (SCM_SMOB_PREDICATE(multi_smob_driver, x))
{
SCM class =
((sub_smob_driver_t)SCM_SMOB_DATA_2(x))->class;
if (SCM_UNSPECIFIED != class)
return class;
}
else
return SCM_CLASS_OF (x);
}
Wadda ya think?
[1] http://download.gna.org/gee/tmp/multi-smob.tar.gz
--
Marco Maggi
"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
- goops classes for smobs,
Marco Maggi <=