From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: SOS: Simple Object System Date: Mon, 15 Sep 2008 08:48:47 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1221461449 18128 80.91.229.12 (15 Sep 2008 06:50:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Sep 2008 06:50:49 +0000 (UTC) Cc: guile-user@gnu.org To: "Maciek Godek" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Sep 15 08:51:44 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kf7vz-0004BD-Tv for guile-user@m.gmane.org; Mon, 15 Sep 2008 08:51:44 +0200 Original-Received: from localhost ([127.0.0.1]:39804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kf7uz-00071N-7N for guile-user@m.gmane.org; Mon, 15 Sep 2008 02:50:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kf7uu-00070z-5k for guile-user@gnu.org; Mon, 15 Sep 2008 02:50:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kf7us-00070O-BV for guile-user@gnu.org; Mon, 15 Sep 2008 02:50:35 -0400 Original-Received: from [199.232.76.173] (port=43710 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kf7us-00070L-7Z for guile-user@gnu.org; Mon, 15 Sep 2008 02:50:34 -0400 Original-Received: from a-sasl-fastnet.sasl.smtp.pobox.com ([207.106.133.19]:55507 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kf7us-0003Ii-6Z for guile-user@gnu.org; Mon, 15 Sep 2008 02:50:34 -0400 Original-Received: from localhost.localdomain (localhost [127.0.0.1]) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTP id 58DC56132C; Mon, 15 Sep 2008 02:50:12 -0400 (EDT) Original-Received: from unquote (177.Red-83-34-179.dynamicIP.rima-tde.net [83.34.179.177]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTPSA id 27FC36130E; Mon, 15 Sep 2008 02:49:29 -0400 (EDT) In-Reply-To: (Maciek Godek's message of "Sun, 14 Sep 2008 00:42:25 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-Pobox-Relay-ID: 8B678A06-82F2-11DD-9935-D0CFFE4BC1C1-02397024!a-sasl-fastnet.pobox.com X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6769 Archived-At: Howdy, On Sun 14 Sep 2008 00:42, "Maciek Godek" 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 () (radius #:init-keyword #:radius)) guile> (make #:radius 10) $1 = #< 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/