> David Rush scripsit: > >> "C FFI" is a misnomer. Try "Native ABI", which exists in a JVM world >> (JNI) , the CLR (as unmanaged code), and most every other platform >> imaginable. I did neglect to consider the implications of a VM FFI, >> but that is frequently addressed through system binding conventions >> (e.g. java-dot notation).
PLT Scheme has the MysterX extension which allows Scheme to call COM/ActiveX objects. You can think of this as a Scheme to C++ FFI. The two implementations of Java-dot notation I'm familiar with (JScheme and Common Larceny) do it in very different ways. Both convert the Java-dot notation into calls into the FFI interface, but the similarity ends there. JScheme maintains a low-level mapping table between the Scheme objects and the reflected Java objects. Common Larceny uses a port of Eli Barzilay's Swindle (a tiny-CLOS derivative) and maps the reflected objects via the MOP. On Tue, Sep 29, 2009 at 7:20 AM, John Cowan <[email protected]> wrote: > > I can't see a standard FFI that usefully hides the distinctions between > Java, C#, and C. Of course, if you care to sketch one, I'd like to > see it. The key is to come up with a reasonable type-system unification. At the lowest level, it is easy: you push stuff on the stack and jump to the entry point. There is no difference between C, C#, or Java at this level. The difference shows up in *what* you push, and that can be directed by the metadata. Start at the high level. You want to call something like this: (MessageBox.Alert "Hello World!") and have a little box pop up on the screen with the appropriate buttons. We need to have the name `MessageBox.Alert' be bound to the appropriate foreign function, and the argument is obviously a string. Now we look at the metadata for the foreign function. It says what language and calling conventions are expected. If it is C, it could be CDECL or STDCALL (or fastcall, etc.), if it is Java, then it is the standard Java conventions. The foreign function metadata should also include info on how to marshal the arguments. If it is a COM interface, we need to construct a BSTR, if it is an ANSI C function, we need to pass a zero-terminated string, etc. We create the appropriate marshaled data, construct the stack frame and jump to the entry (and pray it returns). At a certain level, all you need is some representation of an entry point, and a stack frame, and that should be mostly language neutral. (You may have some difficulty with languages that don't have stack frames.) -- ~jrm _______________________________________________ r6rs-discuss mailing list [email protected] http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss
