2011/11/3 Mikael mikael.rcv@gmail.com:
Yes. The external representation is effectively an int. Btw any closure can be passed <-> the external world under the type representation scmobj which is effectively an int also, look it up in the manual.
I'm not clear right now if scmobj:s are persistent to GC iterations though, if you/anyone knows please let the ml know.
I think I got it:
;; Local Variables: ;; compile-command: "gsc -exe ffi-hello-3.scm" ;; End:
(c-define (apply0 proc) (scheme-object) void "apply0" "" (proc))
(c-declare #<<end-of-c-declare
void call_scheme (___SCMOBJ proc) { apply0 (proc); }
end-of-c-declare )
(define call-scheme (c-lambda (scheme-object) void "call_scheme"))
(define (proc) (print "Hello, World!\n"))
(print (procedure? proc) "\n")
(call-scheme proc)
Now the C function call_scheme can call any Scheme procedure by using apply0.
With gc persistence you mean that the address of the scheme procedure might change because of a mark and compact gc? That would be a problem and will break the above code.
The Gambit documentation distinguishes movable and nonmovable objects in:
http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Pr...
But I can not find any description how to make an object nonmovable. Does anybody know how to make a closure nonmovable?