This is the mail archive of the guile@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] |
Hi, While the gh_ interface is a hot topic, I thought I'd chime in with my personal wish list. When I use guile as an extension language, one of the most common tasks I do is define new application specific types. Right now, the only way I know how to do this is with a SMOB which means I have to dive into the SCM code. That's not a terrible thing, but it means that I tend to avoid the gh_ since I don't want to remember two different interfaces. Another problem is that there are a limited number of SMOB's available. There's talk about expanding that, but it appears to involve serious GC hacking. I'd really like to see a way to define a new type using gh_. I seem to have a distant memory that way back in GUILE-I there was a way to wrap user types without using smobs. Cheers, Clark ************************************************************ I think the interface could work something like this. ;; Declare a new user type "name". This will create a scheme ;; predicate "name?". And return a unique integer (a type_id) to ;; identify the type. This doesn't allocate any new space, but just ;; makes a new type known. ;; name - The name of the type. Used for default printing and ;; to construct a predicate. ;; size - The number of bytes to allocate for the user when a ;; new variable is created. ;; mark, free, print, equal - Simplified version of the usual ;; smobfuns. The user can pass NULL and get reasonalble ;; defaults. Print just returns a string so that it ;; doesn't need to know about the SCM ports. int gh_new_type(char *name, int size, void (*mark)(SCM), void (*free)(SCM), char *(*print)(SCM), int (*equal)(SCM,SCM)); ;; Make a new type object of type_id. If data is not NULL, then fill ;; the user area with the data pointed to by data. SCM gh_type2scm(int type_id, void *data); ;; Return a pointer to the user area contained in val. void *gh_scm2type(SCM val); ;; Return the type_id of val. int gh_scm2typeid(SCM val); ;; And for completeness... int gh_name2typeid(char *name); char *gh_typeid2name(int typeid); ;; To completely protect the user from scm_ we need an interface to ;; scm_gc_mark. This is used in the user's free function. void gh_mark(SCM p); All of the new user objects would use single SMOB. The CDR of the new smob could look like this struct gh_type_struct { int type_id; int size; void (*mark)(SCM), void (*free)(SCM), char *(*print)(SCM), int (*equal)(SCM,SCM)); char user_data[] }; Well, I'm sure you get the idea. If people (ie. Jim B.) are interested I will volunteer to write a first version. Cheers, Clark