On Mon, Sep 28, 2009 at 2:59 AM, David Rush <[email protected]> wrote:
> I've been doing a lot of FFI work in Scheme lately, and it's finally
> gotten me to wondering: Is there any good reason to *not* have a
> standard FFI in Thing2?

Rather than suggesting nice-to-have features, can you point to an
example of such a feature?

> At the end of the day, the point of an FFI is to declare to the Scheme
> run-time how to call bit of non-Scheme code, so it is far more
> dependent on the underlying operating system ABIs than the
> architecture of any given run-time - and it seems to me that there
> just aren't all that many conventions in use by different operating
> systems (yes - feel free to prove me wrong here :)

I did a lot of work on the `FFI' between Common Larceny and the
underlying .NET runtime.  Part of the goal was to eliminate the
FFI as much as possible.  We largely achieved that, although there
is a lot more that can be done.

By `eliminating' the FFI, I mean that you could start up Larceny
and type (.ToString System.TimeZone.CurrentTimeZone) and it would
return the appropriate string.  No prior declarations were necessary;
you simply named the type, method, or field you wanted and passed
Scheme objects to them.  The rest was magic.

The .NET CLR is somewhat similar.  You can declare that a function
exists in some arbitrary DLL and call it with arbitrary arguments and
`magic' happens.

So allow me to point at the existing Common Larceny implementation
and suggest that an FFI should take that model into account.

> I do realize that there are legitimate questions w/rt an FFI that may
> not be easy to codify - interaction with CALL/CC being among the most
> obvious - but declaring type mappings and calling conventions for
> native ABI functions seems fairly straightforward and easily
> represents a 90% of the work that needs to be done kind of solution.

Error handling, memory management, object representation, metadata sources,
type conversion...   Call/cc is pretty straightforward, actually.  No ABI
that I am aware of would permit a re-entrant continuation, so putting
the appropriate barriers at the transitions ought to take care of that.  What
is harder is unwinding the scheme stack when the foreign function
does a longjmp.


-- 
~jrm

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

Reply via email to