unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: "Maciek Godek" <pstrychuj@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: SOS: Simple Object System
Date: Mon, 15 Sep 2008 08:48:47 +0200	[thread overview]
Message-ID: <m31vzllx9s.fsf@pobox.com> (raw)
In-Reply-To: <e2ceda030809131542i224cb1dep83f50bca8e4a5fa5@mail.gmail.com> (Maciek Godek's message of "Sun, 14 Sep 2008 00:42:25 +0200")

Howdy,

On Sun 14 Sep 2008 00:42, "Maciek Godek" <pstrychuj@gmail.com> writes:

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

Neat!

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

Use what you want :)

But:

> 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:

   http://wingolog.org/archives/2008/04/11/allocate-memory-part-of-n

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), scm_si_getters_n_setters);
      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.

Andy
-- 
http://wingolog.org/




  parent reply	other threads:[~2008-09-15  6:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13 22:42 SOS: Simple Object System Maciek Godek
2008-09-14 10:22 ` Neil Jerram
2008-09-14 11:21 ` Greg Troxel
2008-09-15  6:48 ` Andy Wingo [this message]
2008-09-24 13:09   ` Maciek Godek
2008-09-24 16:14     ` Ludovic Courtès
2008-09-24 18:00     ` Clinton Ebadi
2008-09-24 21:04       ` Maciek Godek
2008-09-24 22:14         ` David Séverin
2008-09-24 22:38         ` Clinton Ebadi
2008-09-25 23:03           ` Linas Vepstas
2008-09-26 14:20           ` Maciek Godek
2008-09-25 13:58         ` David Séverin
2008-09-25 17:17           ` Maciek Godek
2008-09-24 22:25     ` Jon Wilson
2008-09-24 22:45     ` Jon Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m31vzllx9s.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-user@gnu.org \
    --cc=pstrychuj@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).