* Proof of concept dynamic FFI
@ 2007-07-19 6:29 Jon Wilson
2007-07-19 8:51 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: Jon Wilson @ 2007-07-19 6:29 UTC (permalink / raw)
To: Guile Users, guile-sources
Hi,
I've written a bit of code that lets you call any function from a
dynamically loaded shared lib with any args. Well, actually, since it
is just a proof of concept, it only lets you call functions that take
zero or one args. The arg (if there is one) must be of type int. The
return type can be either void or int.
If you want to play, you can get the code by
bzr branch http://bzr.wilsonjc.us/foreign/
or by just grabbing the files from that URL manually. The README
contains brief instructions on how to try it out.
If I'm just reinventing the wheel, or if you can think of a better way
to do it, or if you just think I look funny, let me know.
Regards,
Jon Wilson
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Proof of concept dynamic FFI
2007-07-19 6:29 Jon Wilson
@ 2007-07-19 8:51 ` Ludovic Courtès
0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2007-07-19 8:51 UTC (permalink / raw)
To: guile-user
Hi,
Jon Wilson <jsw@wilsonjc.us> writes:
> I've written a bit of code that lets you call any function from a
> dynamically loaded shared lib with any args. Well, actually, since it
> is just a proof of concept, it only lets you call functions that take
> zero or one args. The arg (if there is one) must be of type int. The
> return type can be either void or int.
Interesting. If I were to write this, I'd use GNU lightning to compile
natively the glue code instead of having to go through
`foreign-dispatch' (alternatively, there's libffi which can help a bit,
but it adds an indirection). You also need to make sure that building a
"foreign lambda" is fast since this would typically have to be done a
number of times at startup.
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Proof of concept dynamic FFI
[not found] <200707191606.l6JG6r724380@cm-mail.stanford.edu>
@ 2007-07-19 16:58 ` Kjetil S. Matheussen
0 siblings, 0 replies; 3+ messages in thread
From: Kjetil S. Matheussen @ 2007-07-19 16:58 UTC (permalink / raw)
To: guile-user
Jon Wilson:
>
> Hi,
> I've written a bit of code that lets you call any function from a
> dynamically loaded shared lib with any args. Well, actually, since it
> is just a proof of concept, it only lets you call functions that take
> zero or one args. The arg (if there is one) must be of type int. The
> return type can be either void or int.
>
> If you want to play, you can get the code by
> bzr branch http://bzr.wilsonjc.us/foreign/
> or by just grabbing the files from that URL manually. The README
> contains brief instructions on how to try it out.
>
> If I'm just reinventing the wheel, or if you can think of a better way
> to do it, or if you just think I look funny, let me know.
> Regards,
> Jon Wilson
>
With guile, I usually prefer writing c-code using s-expressions:
(load "eval-c.scm")
(eval-c ""
(public
(<void> hello-world (lambda ()
(printf (string "hello world\\n"))))))
(hello-world)
=> hello-world
(eval-c ""
(public
(<int> add-ints (lambda ((<int> a)(<int> b))
(return (+ a b))))))
(add-ints 2 3)
=> 5
etc.
http://snd.cvs.sourceforge.net/snd/cvs-snd/eval-c.scm
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-19 16:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <200707191606.l6JG6r724380@cm-mail.stanford.edu>
2007-07-19 16:58 ` Proof of concept dynamic FFI Kjetil S. Matheussen
2007-07-19 6:29 Jon Wilson
2007-07-19 8:51 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).