[cvs-nhc98] Status of foreign import wrapper/dynamic

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Sun Jun 13 12:18:15 EDT 2004


Sven Panne <Sven.Panne at aedion.de> writes:

> What is the status of 'foreign import "wrapper"' and 'foreign import
> "dynamic"' in nhc98? http://haskell.org/nhc98/ffi.html claims that
> neither is supported, but at least the "dynamic" part compiles.

>From the cvs log of src/compiler98/Foreign.hs:

    revision 1.25
    date: 2003/06/16 13:43:03;  author: malcolm;  state: Exp;  lines: +51 -53
    Improvements to the FFI.  Translate the FunPtr type into the correct
    prototypes on the C side, i.e. as a pointer to a function with the
    named argument and result types.  This refinement makes it possible
    to implement "foreign import dynamic", which is also contained in
    this commit.

So it looks like "dynamic" may work now, although I don't really
remember what was required.  Looking in the same source code shows that
"wrapper" is definitely not implemented.

    genProto Wrapper cname = error "foreign import wrapper not yet supported."

> Having both available is mission-critical for a working OpenGL/GLUT
> binding, so are there any plans to implement the missing parts? I
> could offer a helping hand, I've done some work at the corresponding
> parts of GHC and Hugs before.

At nhc98 central, we don't have plans, just hopes.  :-)  Perhaps some
funding will eventually be obtained that enables us to have real plans.
So, in the meantime, all help gratefully received.

> But for doing this, I would need some
> detailed info about the current implementation of nhc98's FFI. Is
> there such a thing? (apart from the source code, of course :-)

Unlikely.  :-(

Using nhc98 -C, you can grab the .hc file for an example module and
read the C source stub generated for each foreign import - it should
look fairly straightforward, basically marshalling a few arguments off
the stack, calling the external fn, and marshalling the result back.
The function address of the stub is stored in the bytecode so that
when the mutator encounters the bytecode instruction PRIMITIVE,
it can read the address and jump to it.

That's the basic sketch.  Ask more detailed questions when you need to.

Regards,
    Malcolm


More information about the Cvs-nhc98 mailing list