
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 shackell@cs.york.ac.uk wrote:
[...]
Of the two I think 1) is the better option, but any solution is going to be nasty when implementing an FFI that was essentially designed for compilers that generate C code.
Agreed.
So suggestions are welcome, but ultimately I can't see a "nice" solution :-)
Hmm. Foreign import being not particularly nice either, but implemented, I'll try comparing to it. foreign import ccall puts arguments on the stack(or whatever) in the C calling convention. foreign export ccall takes arguments off the stack in the C calling convention. Either way might use ctypes/libffi. In order to _call_ C code, you need to be linked to the compiled C code somehow (grabbing a function pointer? linking the C object files directly in with the yhi interpreter's? how does it work?). In order to be callable _from_ C code, you need the C code to be linked to you somehow (perhaps each call into Haskell goes through the same interpreter call-in function, which somehow knows which function it's masquerading as? can something like that be done without any _recompilation_ to machine code, and using ctypes/libffi to extract the arguments?). Maybe if I knew how foreign import works I'd have a better understanding here... For a start, how do you even use it with Yhc? yhc-foreign-import-hs.hs: import Foreign.C (CInt) foreign import ccall my3 :: CInt main = print my3 yhc-foreign-import-c.c: int my3(void) { return 3; } $ yhc yhc-foreign-import-hs.hs $ yhi Main.hbc Which of course doesn't work, because I haven't even compiled yhc-foreign-import-c.c: ERROR: couldn't load external module './Main', demanded from module 'Main' ./Main.so: cannot open shared object file: No such file or directory Does the error mean that yhi is expecting foreign functions to be contained in the shared object file Main.so (if so, how does one go about creating such a thing, starting with C source code?) Isaac -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE6HI2HgcxvIWYTTURAttlAJwO69cvJiEyz+Si/7yDjiumqv6zNQCfZrIr mPc5Wm3D8zLYqQ0dJNfU1/A= =WzOf -----END PGP SIGNATURE-----