This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: struct interface


On Thu, 6 Apr 2000, Dirk Herrmann wrote:

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

After the discussion about this issue I think that the SCM_MEMORY macros
as a general base for memory accesses that hold either SCM or scm_bits_t
values does not make sense:

1) It's of no use for garbage collection, since the question whether a
   reference from an older cell to a newer one is created can not be
   decided within those macros.
2) The memory layout of cells, structs, smobs and so on may be different
   for each of these types.

However, I think that we should provide a couple of macros for each of
these types to allow for easier data access and to avoid the need for
packing / unpacking:

Cells (as is already provided):

SCM_CELL_TYPE (x)
SCM_CELL_WORD (x, n)
SCM_CELL_OBJECT (x, n)
SCM_SET_CELL_TYPE (x, v)
SCM_SET_CELL_WORD (x, n, v)
SCM_SET_CELL_OBJECT (x, n, v)

Smobs:

SCM_SMOB_TYPE (x)
SCM_SMOB_WORD (x, n)
SCM_SMOB_OBJECT (x, n)
SCM_SET_SMOB_TYPE (x, v)
SCM_SET_SMOB_WORD (x, n, v)
SCM_SET_SMOB_OBJECT (x, n, v)

Currently, there is only SCM_SMOB_DATA, otherwise the SCM_CELL_... macros
are used.  But since there are smobs for double cells, this would be a
natural extension, which also nicely matches the cell accessing
macros.

Structs:

SCM_STRUCT_WORD (x, n)
SCM_STRUCT_OBJECT (x, n)
SCM_SET_STRUCT_WORD (x, n, v)
SCM_SET_STRUCT_OBJECT (x, n, v)

etc.


Best regards
Dirk Herrmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]