[plt-scheme] cffi.ss

From: Ed Cavazos (proteus at theworld.com)
Date: Wed Jun 25 04:56:33 EDT 2003

On Wednesday 25 June 2003 02:55 am, Ed Cavazos wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> On Wednesday 25 June 2003 01:19 am, David Van Horn wrote:
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > Ed Cavazos wrote:
> > > I noticed in the Gambit-C manual that an allowed type specifier in
> > > c-lambda is one of: "c-type-id". So, just a string naming a C
> > > type. For example, given these 2 C function prototypes:
> > >
> > > person make_person(char *name);
> > > int    move_person(person p);
> > >
> > > I guess the c-lambda code would be:
> > >
> > > (c-lambda (char-string) "person" "make_person")
> > > (c-lambda ("person")    int      "move_person")
> > >
> > > It doesn't look like the current cffi.ss supports this. Would adding
> > > this be as simple as modifying cffi.ss or would support have to be
> > > added to mzc itself?
> > >
> > > Ed
> >
> > I believe in Gambit this should be:
> >
> > (c-define-type person "person")
> > (c-lambda (char-string) person "make_person")
> > (c-lambda (person)      int    "move_person")
> >
> > -d
>
> Yes, you're right. I was smoking crack. I just read in the Gambit-C manual
> that what I specified above is prohibited. You have to first use
> c-define-type, then c-lambda can accept this type as an arg or return item.
> Here's the exact paragraph that mentions this:
>
> "Note that not all of these types can be used in all contexts. In
> particular the arguments and result of functions defined with c-lambda and
> c-define can not be (struct "name") or (union "name") or "c-type-id". On
> the other hand, pointers to these types are acceptable."
>
> So the right thing to do is implement c-define-type and teach c-lambda to
> recognize these newly defined types. It's not clear to me how the code
> generated by c-lambda and c-declare is communicated back to mzc. Something
> to do with the mzc-cffi syntax-property. So I guess that implementing the
> c-define-type macro would involve modifying mzc.(?)
>
> Ed

Hmmm. Maybe this isn't so hard. The core contribution of c-define-type would 
be to call "scheme_make_type" over the given C type name. It would also 
generate the code for the struct that boxes the C value. Also, it should 
generate auxilliary code that c-lambda could call, things like a constructor, 
predicate, and extractor.

As far as c-define-type communicating with the rest of mzc, it looks like only 
compiler/private/prephase.ss would have to be modified so that it looks out 
for syntax properties from c-define-type.

c-lambda would have to be able to recognize a type as one of these new types 
setup by c-define-type. I guess some global table could map the symbolic name 
to the C type name.

Ed


Posted on the users mailing list.