[Prev][Next][Index][Thread]
Re: Assorted C-FFI goodies
Nolan Darilek wrote:
> I've been toying with call-out now that I've discovered it.
call-out is cool. I've hand-written my Mac Toolbox library by hand using
call-out. It's very, very tedious but not difficult to do.
c-expr is good, too. I use that a little but Gabor Greif posted a m,uch
better example of (mis-)using it on dylan-hackers a while back.
It might be worthwhile getting Pidgin to spew call-out / c-expr calls and
<machine-pointer> types rather than write to the C-FFI, which isn't
complete yet by a long shot.
> What components of c-ffi need to be buried in the compiler?
Type mapping and translation, call translation, callback translation.
Stack frames don't build themselves. :-)
> Unless I'm mistaken, the complete definition allows for
> Dylan functions to be called from C, which I'm not particularly
> interested in at the moment.
Melange and the current call-out style FFI allow callbacks. They are
important for interfacing to Operating Systems. MacOS needs them and I'm
sure BeOS does, too. X is entirely callback based, if I remember
correctly.
> If I sacrifice that functionality, then
> how difficult would it be to achieve access to C data from within
> Dylan?
Use c-expr, or <statically-typed-pointer> and the (int|long|char)-at
methods and you can do that today. See the Mac toolbox lib for examples
(they're hand written, so they have to be human readable). Gareth Baker's
Carbon application example has melange-parsed interfaces to the same
functionality, which make a good comparison. It also shows how callbacks
are created.
> With call-out, is it possible to implement a Dylan function
> which simply runs call-out on the results of a macro call and returns
> the result variable?
Absolutely. I don't know about type safety, though.
define macro dummy
{ dummy( ?val:expression ) }
=>( call-out( "GetValue", int:, int: unseen-macro( as(
<c-string>, ?val ).raw-value ) ) )
end macro dummy;
> What about access to C variables? Would the
> c-decl macros within the System module be useful for this?
Yes. The d2c sources import errno from the std c libs in this way. See
Gabor's example from the gwydion list, which creates, manipulates and
passes C variables from within Dylan (this may be applicable to the
poster asking about embedding C in Dylan, too).
> Or am I missing something important?
No.
> That'd be awesome! If this is as difficult as it is then I'm not sure
> if I can help, but I'd be interested in seeing if I'm on the right
> track with this.
Any and all help on d2c is greatly appreciated, and people should play to
their strengths. I'm working on DUIM because I don't know how to finish
the C-FFI or class/each-subclass slots no matter how badly they're
needed.
Please take a look at the Mac Toolbox examples from mac-d2c and
carbon-application, I'm sure they'll help with understanding how call-out
and friends work. I'm happy to answer questions on it.
- Rob.
References: