guile-devel
[Top][All Lists]
Advanced

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

Re: make-vtable


From: Ludovic Courtès
Subject: Re: make-vtable
Date: Thu, 15 Feb 2007 09:45:27 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Hi,

Kevin Ryde <address@hidden> writes:

> address@hidden (Ludovic Courtès) writes:
>>
>> I'm not sure the indirection in `scm_init_stacks ()' is needed since it
>> uses STACK_LAYOUT for both VTABLE and SCM_STACK_TYPE,
>
> Not sure what you mean there.

We have:

  VTABLE -> SCM_STACK_TYPE -> stack objects

where `x -> y' means "`y' is an instance of `x'".  When creating stack
objects with (roughly) `(make-struct stack-type)', VTABLE is _not_
consulted at all.  The layout of stack objects is determined only by
that specified in SCM_STACK_TYPE.  Thus, VTABLE is redundant.

All this would be clearer if we had a `struct-vtable' type such that
`(make-struct struct-vtable)' would yield a new vtable (just like `(make
<class>)' yields a new GOOPS class).  Like `<class>', `struct-vtable'
would terminate the "reflective tower" (i.e., its vtable is itself).

Actually, such a `struct-vtable' stealthily appears in
`make-vtable-vtable', under the name of REQUIRED_VTABLE_FIELDS: We could
really have a `struct-vtable' whose layout is REQUIRED_VTABLE_FIELDS and
then `make(-vtable)+' could be simply implemented in terms of
`make-struct' (just like `make-class' uses `make').

I guess I should try implementing this theory one of these days.  ;-)

> At any rate, below is where I'm up to so far with trying to make the
> docs a bit easier.  It includes my proposed make-vtable.  Could be
> possible to leave that out, but perhaps those like me who managed to
> never understand structs can see if it makes the understanding easier
> :-).

Thanks for working on this!

> A "structure" is a first class data type which holds Scheme values or C
> words in slots numbered 0 upwards.  A "vtable" represents a structure
> type, giving read/write permissions on slots, whether they're Scheme
> values or uninterpreted words, and giving an optional print function
> for the structure (for use by `write' etc).

Perhaps a word saying the struct fields are laid out in a contiguous
memory area, which makes interaction with C much easier (using C arrays
or some such).

> Vtable Vtables
> ..............
>
> As noted above, vtables are structures and such a structure is itself
> described by a vtable.  Such a "vtable of a vtable" can be created with
> `make-vtable-vtable' below and used to build sets of related vtables,
> possibly with extra application fields.
>
>    This second level of vtable can be a little confusing.  An example,
> and indeed a typical use, is Guile's own record system (*note
> Records::).  Currently record types are implemented as vtables, and
> those vtables have an extra slot holding the list of field names for
> that type (as passed to `make-record-type').

While the rest looks good, I remain skeptical about this part.  And a
manual that claims to be confusing does not inspire confidence.  ;-)

Thanks,
Ludovic.




reply via email to

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