Eli Barzilay <[email protected]> writes:

> On Feb 23, Guillermo J. Rozas wrote:
>> >> And why would I do that?  Because, presumably, I don't want to
>> >> re- type the definitions of the library that are already included
>> >> in a .h file, and I'd rather write a tool that can be used and
>> >> re-used as the .h file changes, than have to fix things by hand.
>> >
>> > (That is a perfectly fine job for a macro, BTW.)
>> 
>> Parsing a .h file?  Boy, I've written hairy macros in my life, but
>> that's got to be a winner.
>
> I don't see why this would be hairier than writing code that parses a
> header file...  After all, this is Scheme, and macros are written in
> Scheme.  (Assuming that you're not restricted by a `syntax-rules'-only
> implementation.)
>
> One example is PLT's interface to OpenGL -- it has a macro that writes
> a small C file, compiles it, runs the result, and eventually expands
> into Scheme code that can now use that information.  (And BTW, I
> intend to write a macro to write those kinds of macros, and even that
> wouldn't be too difficult.)
>
> This approach has been used in several other cases; the most recent
> notable example that I can think of was a similar thing that was done
> in Larceny (there the C program writes information about offsets of
> fields in C structs).
>
sbank (a Scheme binding for gobject-introspection [0]) does that as
well; in one place it uses a S-exp data file that defines C dataypes [1]
to generate accessors for those at expand-time, and in another place it
uses a binary (typelib) file to figure out which bindings its
`typelib-import' (which similiar to R6RS `import') should provide for a
given typelib "namespace" [2] (iff the user doesn't provide an explicit
list of bindings to import).

[0] http://live.gnome.org/sbank
[1] http://download.gna.org/spells/darcs/r6rs/sbank/data/typelib.scm
[2]
http://download.gna.org/spells/darcs/r6rs/sbank/typelib/expanders.sls

Regards, Rotty


_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to