[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SOS: Simple Object System

From: Andy Wingo
Subject: Re: SOS: Simple Object System
Date: Mon, 15 Sep 2008 08:48:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)


On Sun 14 Sep 2008 00:42, "Maciek Godek" <address@hidden> writes:

> Hi,
> Using some hints you gave me, I've implemented a really tiny
> object system


> your opinion ("why it's still better to use goops" :D)

Use what you want :)


> storing objects as vectors allows for an efficient and convenient
> object treating from C level, so boatmen should be satisfied.

GOOPS objects are internally implemented similar to vectors:

The only trick is that the mapping between slot names and indices in the
slot array is not part of GOOPS' specification -- it depends on many
things. But in normal cases, the first slot that you name in the class
definition is stored in slot 0, etc:

    guile> (define-class <circle> () (radius #:init-keyword #:radius))
    guile> (make <circle> #:radius 10)
    $1 = #<<circle> b7f8be20>
    guile> (struct-ref $2 0)
    $2 = 10

Of course from scheme the way to take advantage of this is to use the
accessors, which compile down to this. But from C, probably your best
bet is to introspect which index a slot is stored in at runtime, then
cache that. From Guile-GNOME:

    /* from goops.c */
    static int
    gtype_struct_offset (SCM class)
        register SCM slots = SCM_SLOT (scm_class_of (class), 
      for (; !scm_is_null (slots); slots = SCM_CDR (slots))
          if (SCM_CAAR (slots) == scm_sym_gtype)
              return scm_to_int (SCM_CDDR (SCM_CAR (slots)));
      scm_c_gruntime_error ("%gtype-class-bind",
                            "`gtype' not allocated a slot in struct!",
                            SCM_LIST1 (class));
      return -1;

This could certainly be improved, somehow, on an API level.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]