[gambit-list] Problem with interactive development using remote REPL of iOS Sim.

mikel evins mevins at me.com
Thu Mar 7 01:16:29 EST 2013


On Mar 6, 2013, at 9:57 PM, Marc Feeley <feeley at iro.umontreal.ca> wrote:

> Interesting!  

Since it's interesting, I figure it would be helpful if I told you the exact steps I used. Here they are:

1. Get ffigen itself.

This page tells you how to get it and build it:

http://trac.clozure.com/ccl/wiki/BuildFFIGEN

I used the version listed under the heading "(Experimental) ObjC blocks support". 


2. Build ffigen

I simply followed the instructions under the abovementioned heading to obtain a working build.  Please note that I had GCC 4.7.2 installed on my machine before starting; I use it to build Gambit, so I always have it installed.

3. Install ffigen

I followed the instructions on the ffigen page. That process installed ffigen in /usr/local, putting h-to-ffi.sh in /usr/local/bin, and some other files in /usr/local/ffigen. I added /usr/local/ffigen/bin to my PATH, though that may not have been necessary; /usr/local/bin was already on my PATH.


4. Make a directory for ffi files

ffigen grovels over C, C++, and Objective-C header files, generating many lines of s-expressions as output. It wants to write an .ffi file for each header file, and it wants to put them in a directory structure that parallels the directory structure where it finds the header files.

Make a directory somewhere convenient. In that directory, create a directory named "Cocoa", with a subdirectory named "C". In the "C" directory, put a file called "populate.sh" and put these lines in it:

#!/bin/sh
rm -rf ./Applications
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
CFLAGS="-m64 -isysroot ${SDK} -mmacosx-version-min=10.6"; export CFLAGS
h-to-ffi.sh ${SDK}/usr/include/objc/objc-runtime.h
h-to-ffi.sh ${SDK}/usr/include/objc/objc-exception.h
h-to-ffi.sh ${SDK}/usr/include/objc/Object.h
h-to-ffi.sh ${SDK}/usr/include/objc/Protocol.h
h-to-ffi.sh ${SDK}/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h

cd to that directory, and from there run the script. If all goes well, then less than a second later you should wind up with a new Application subdirectory. Buried inside it, in a deep directory hierarchy that parallels that of Apple's SDKs, you should find newly-generated .ffi files containing output similar to the examples I sent previously.

This script handles Cocoa.h and the Objective-C runtime APIs. There are lots more frameworks you might want to process. If you install the source release of CCL (not the prebuilt version that is on the App Store), you'll find that it includes header directories with "populate.sh" scripts for processing a bunch of useful frameworks--addressbook, audtiotoolbox, carbon, cocoa, coreaudiokit, gl, jni, libc, and so on.

If you succeed in following the steps I gave above, then you should see how you can write your own "populate.sh" scripts to process other frameworks, whether from Apple or from other sources.

Occasionally you may find some obscure corner case that ffigen doesn't quite handle correctly. In those cases, you can just write an FFI by hand. Even when such gaps do arise, ffigen saves a ton of time.

> Now the question is... can the forms generated by ffigen be transformed easily to Gambit's FFI (and if not, what can we change in the Gambit FFI to make it easy).

I figure that, since they're just s-expression versions of the C declarations, processing them should be pretty straightforward. The Lisp source file I identified in my previous message shows how CCL  turns the .ffi files into foreign definitions using CCL's. Naturally, Gambit's FFI is different, but I'm guessing that adapting ffigen's output will not be onerous. One of several advantages to using ffigen is that it's already seen many years of duty serving this same purpose for CCL, which has a very comprehensive and featureful Cocoa bridge as a result. With luck, maybe it can help Gambit do the same.

--me




More information about the Gambit-list mailing list