chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] noobie question about chicken/swig/csi


From: Zbigniew
Subject: Re: [Chicken-users] noobie question about chicken/swig/csi
Date: Mon, 2 Apr 2007 15:02:25 -0500

Just injecting a bit of humour into the proceedings.  No need to take offense.

For what it's worth, though, Graham's explanation is spot-on.
Interfacing to a C function is no more complex in Chicken than it is
in Lua or, for that matter, any other language.  In all of these, you
need special calls for argument parsing, data structure manipulation,
library setup, and so on.  The point of SWIG or indeed most of the FFI
variants is to reduce the need for this boilerplate or interface
code--especially when you do not wish to modify the original source.
Or load shared libraries on the fly, as with lazy-ffi.  As another
example, the native Chicken FFI converts arguments and return types
for you automatically--a pure Lua, or Python, or Perl, or Chicken C
module has to do this explicitly.

Let's look at Perl for a moment.  Perl does not use CPS nor use the
machine stack in a highly unconventional way.  Yet it still contains
an interface description file format, XS, which does argument and
return value conversion among other things.  The Perl guide states
that

"Of course, one could write such glue code directly in C.  However,
this would be a tedious task, especially if one needs to write glue
for multiple C functions [...] Instead of writing this glue C code in
long-hand, one can write a more concise short-hand description of what
should be done by the glue, and let the XS compiler xsubpp handle the
rest."

This is similar to what the foreign-lambda and foreign-primitive
declarations do in Chicken.  Furthermore, easyffi's foreign-parse is
pretty much the equivalent of Perl's h2xs.

Looking at the Chicken compiler output is not instructive here, and
may even make your head explode--it is not meant to be human readable.
There are occasions in which you will need to do lowlevel things like
call C_alloca or write in CPS or set bit types in the right places
(what are you doing that you need this?).  This part is difficult and
requires a different paradigm of thinking, but the various FFIs does
not simplify this.

To sum up, the choice between easyffi, lazy-ffi and basic
foreign-lambda is not related to the machine stack, as you originally
suggested.  Instead they mirror the typical glue code of other
interpreted languages (and better it, in my opinion).  After all, even
Lua can be wrapped with SWIG.

On 4/2/07, Alex Queiroz <address@hidden> wrote:
On 4/2/07, Zbigniew <address@hidden> wrote:
> Finally, some time passed and--well, you know
> how these things go--I had inadvertantly Greenspun my pure C module
> into a Lisp interpreter.  I was just about to put the finishing
> touches on the FFI when I saw your post.

     Your sarcasm is utterly unnecessary.




reply via email to

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