This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: struct interface
- To: Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Re: struct interface
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Thu, 6 Apr 2000 11:35:58 +0200 (MEST)
On Thu, 6 Apr 2000, Dirk Herrmann wrote:
> Similar as with cells, struct data memory can also hold raw data and
> scheme objects. I am currently changing the data part from SCM[] to
> scm_bits_t, thus following the paradigm that SCM should only be used if
> we are sure that the content is a valid scheme object.
>
> However, as with cells, it would make sense to provide low-level macros to
> read struct slots as raw data as well as scheme objects in order to reduce
> the amount of packing/unpacking on the user side.
>
> Thus, I suggest the following macros:
We could even provide an even more general way to do things like
this: There are many places in guile where we access a memory field that
contains either raw data or scheme objects:
* scheme cells are the most common case.
* struct data
* struct vtables (ok, these are also structs)
* maybe others (vectors?)
In a previous post Michael suggested to change the SCM_CELL_WORD macros to
access cell entries as constand values, in order to be always sure about
places where SCM data is written to memory. I assume that this is
important for gengc? If this is the case, then even with the availability
of SCM_CELL_WORD there are various other places where wild mixtures of SCM
and scm_bits_t values occur.
What about putting all of these on a common base:
SCM_MEMORY_WORD(p, n) --> (((scm_bits_t *) p) [n])
SCM_MEMORY_OBJECT(p, n) --> (SCM_PACK (((scm_bits_t *) p) [n]))
SCM_SET_MEMORY_WORD(p, n, v) --> (((scm_bits_t *) p) [n] = (v))
SCM_SET_MEMORY_OBJECT(p, n, v) --> (((scm_bits_t *) p) [n] = SCM_UNPACK (v))
And then, we define all other accesses to mixed memory regions on top of
these, for example the scheme cell accesses:
SCM_CELL_WORD(x, n) --> (SCM_MEMORY_WORD (SCM2PTR (x), (n)))
SCM_CELL_OBJECT(x, n) --> (SCM_MEMORY_OBJECT (SCM2PTR (x), (n)))
SCM_SET_CELL_WORD(x, n, v) --> (SCM_SET_MEMORY_WORD (SCM2PTR (x), (n), (v)))
SCM_SET_CELL_OBJECT(x, n, v) --> (SCM_MEMORY_OBJECT (SCM2PTR (x), (n), (v)))
If this is done consequently, all accesses to SCM values go through the
SCM_{SET_}?MEMORY_* macros.
Best regards
Dirk Herrmann