It used to work! I noticed a stupid bug in lib/os_dyn.c . You have to replace all the ___WORD_SIZE by ___WORD_WIDTH and then recompile the system with "make".
Then, on supported platforms such as 32 bit intel, you'll be able to run code like this which passes a closure to a foreign function:
(c-declare "
int f( int g( int x ) ) { return g(1) + g(2); }
")
(define f (c-lambda ((function (int) int)) int "f"))
(c-define (square n) (int) int "square" "" (* n n))
(pp (square 10)) ;; prints 100
(pp (f square)) ;; prints 5 (i.e. 1^2 + 2^2)
(pp (f (lambda (x) (expt 2 x)))) ;; prints 6 (i.e. 2^1 + 2^2)
It is the last expression, i.e. the call (f (lambda (x) (expt 2 x))), which is enabled by the dynamic code generation. The call (f square) is always supported because it does not require dynamic code generation (because square is defined with a c-define form).
Marc
I made clean ./configure CFLAGS="-g" and make after replacing ___WORD_SIZE by ___WORD_WIDTH in os_dyn.c
This is what I then do: bind.scm contains (c-declare " int f(int g(int x)) {return g(1)+g(2);} ")
(define f (c-lambda ((function (int) int)) int "f"))
after doing gsc bind.scm, I invoke gsi
(load "bind")
"/home/michele/src/scheme/gambit/ffi/4/bind.o1"
(f (lambda (x) (expt 2 x)))
I get a segmentation fault
bt full is provided.
System is OpenBSD 4.5 (GENERIC) #1749: Sat Feb 28 14:51:18 MST 2009 deraadt@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC cpu0: Mobile Intel(R) Pentium(R) 4 CPU 2.30GHz ("GenuineIntel" 686-class) 2.16 GHz
michele