[gambit-list] How to pass a procedure to a nonnull-function?
Vok Vojwo
ceving at gmail.com
Thu Nov 3 10:16:15 EDT 2011
2011/11/3 Mikael <mikael.rcv at 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:Procedure_gc-report-set!
But I can not find any description how to make an object nonmovable.
Does anybody know how to make a closure nonmovable?
More information about the Gambit-list
mailing list