unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* goops classes for smobs
@ 2007-11-13 22:01 Marco Maggi
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Maggi @ 2007-11-13 22:01 UTC (permalink / raw)
  To: guile-user

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"




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: goops classes for smobs
@ 2007-11-14  5:48 Marco Maggi
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Maggi @ 2007-11-14  5:48 UTC (permalink / raw)
  To: guile-user

Corrections... :(

"Marco Maggi" wrote:
>scm_make_extended_class_with_supers("my",
>scm_variable_ref("<number>"));

This must be:

scm_make_extended_class_with_supers("my",
scm_list_1(scm_variable_ref("<number>")));

and the change to 'scm_class_of()' must
be something like:

{
  /* 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;
    }

  return SCM_CLASS_OF (x);
}

--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-14  5:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-13 22:01 goops classes for smobs Marco Maggi
  -- strict thread matches above, loose matches on Subject: below --
2007-11-14  5:48 Marco Maggi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).