FFI closures are on the way

Q&A's, tips, howto's
Post Reply
sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

FFI closures are on the way

Post by sunmountain »

This morning, while commuting, I did finish the foundation for ffi closures.
That said, now I can create real ffi closures and get their addresses for later use,
and more important, call them.

Hopefully on my way back home I finish the marshalling code and can show some demo.

To give you a clue on how it is used:

Code: Select all

(set 'a (callback (lambda (a b c) (mul a b c)) "int" "int" "int" "int"))
(println (a 1 2 3))
(println a)
(exit)
Which gives

Code: Select all

OK <0x7b0008>
Me was called ...
with 3 arguments
6
<closure><6D0090>
The most interesting part here is Me was called ..., which is a real C call (the (println (a 1 2 3)) should not confuse you) to a ffi closure,
which then calls a trampoline function which executes the lambda in the callback definition.

The missing pieces are stuffing the lamba with arguments and returning the result cell(s) back
to the caller.
This explanation might get clearer if you see the code, though.

Post Reply