Email list hosting service & mailing list manager


Re: Pika-style from first principles Marc Feeley 07 Jan 2004 05:47 UTC

> Marc> To avoid the tedium of writing by hand the associated Scheme-to-C and
> Marc> C-to-Scheme conversion functions (i.e. "FILENAME_FROM_SCHEME" and
> Marc> "FILENAME_TO_SCHEME", "STREAM_FROM_SCHEME", ...), a way to define type
> Marc> aliases on the C side of the FFI is useful so that one can write in a
> Marc> C header file something like:
>
> Marc> /* file: "my_types.h" */
> Marc> #include "basic_types.h"
> Marc> #ifdef UNICODE
> Marc> #define FILENAME NONNULL_UCS2STAR
> Marc> #define FILENAME_FROM_SCHEME NONNULL_UCS2STAR_FROM_SCHEME
> Marc> #define FILENAME_TO_SCHEME NONNULL_UCS2STAR_TO_SCHEME
> Marc> #else
> Marc> #define FILENAME NONNULL_CHARSTAR
> Marc> #define FILENAME_FROM_SCHEME NONNULL_CHARSTAR_FROM_SCHEME
> Marc> #define FILENAME_TO_SCHEME NONNULL_CHARSTAR_TO_SCHEME
> Marc> #endif
>
> I think I'm missing a crucial bit here: Where do
> NONNULL_UCS2STAR_FROM_SCHEME, NONNULL_UCS2STAR_TO_SCHEME and
> associates come from?  What's "a way to define type aliases on the C
> side of the FFI"?

These are conversion functions (in C) defined by the FFI (they take a
bunch of parameters that are irrelevant to this discussion).  The C
code generated by the Gambit compiler contains calls to these
conversion functions at the appropriate places.  What I am saying is
that the C code generated to interface to the function defined by

   (define-c-function (open-path FILENAME) STREAM "open_path")

contains a call to FILENAME_FROM_SCHEME (and STREAM_TO_SCHEME).  By
defining FILENAME_FROM_SCHEME to be synonymous to
NONNULL_CHARSTAR_FROM_SCHEME we get a conversion to a "char*" string.
By defining FILENAME_FROM_SCHEME to be synonymous to
NONNULL_UCS2STAR_FROM_SCHEME we get a conversion to a "wchar_t*"
string.

Does that make it clearer?

[Note: this is not exactly the syntax or names that Gambit uses... I
have simplified things to ease comprehension of the general approach.]

Marc