[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] foreign-lambda*
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] foreign-lambda* |
Date: |
Wed, 2 Feb 2005 05:29:33 -0800 |
On Wed, 02 Feb 2005 04:57:11 -0800 (PST), Nicolas Pelletier
<address@hidden> wrote:
> Hello,
>
> I often want to generate some C code as a string somewhere in a Scheme
> file and then call it dynamically. However, foreign-lambda* insists on
> having a string as its last parameter, so that the following does not
> work:
>
> (let* ([v (make-byte-vector 37 0)]
> [s "some_random_call (C_data_pointer (x), 37);"]
> [f (foreign-lambda* void ((scheme-object o)) s)])
> (f v))
>
> The construction of the string of C code is usually more convoluted
> than this. The above just shows the pattern.
>
> How can I achieve the effect I am looking for ?
>
You can either use the tcc extension
(http://www.call.with-current-continuation.org/eggs/tcc.html),
or you can put the code into a temporary file,, compile into a dll/so
and load it dynamically (but that will grow the used code space,
because the loaded file can not be unloaded).
To call the code, you can define some glue code (using the ffi)
to invoke it via a function pointer).
Besides using tcc, Chicken doesn't have an embedded C compiler.
cheers,
felix