
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 (the only reason I'm trying _this_ is to test if the Yhc implementation of concurrency described on the wiki works properly; Yhc seems to compile foreign import successfully, though I haven't yet tried running the bytecode it generates for that) - -------- import Foreign.C (CInt) return3 :: IO CInt return3 = return 3 foreign export ccall return3 :: IO CInt main = putStrLn "okay" - -------- I've tried commenting out various combinations of the type-signatures, reordering the definition and the foreign export, making the return be IO or not, () or not... ghc -fffi only complains when I comment out the type-signature on the foreign export line, as expected based on the FFI spec. This is always just yhc -c dying, with various error messages. Isaac -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE5a46HgcxvIWYTTURAjBPAKCF8fyuZCrwxOdK4hVsdDljMFWwZwCcCMxh ULKutHs0sNcQreGf86fauC8= =pXnT -----END PGP SIGNATURE-----

Hi,
As far as I know, Yhc doesn't have foreign export - but only Tom can
say for definate.
You can of course use yhi as a library (once the code is finished!) to
give you dynamic calling into Haskell at runtime. I guess thats the
yhc way of doing this.
One thing we were discussing a few days ago is that we need an FFI
test suite for Yhc, since it appears that packedstring fails in the
FFI.
Thanks
Neil
On 8/18/06, Isaac
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
(the only reason I'm trying _this_ is to test if the Yhc implementation of concurrency described on the wiki works properly; Yhc seems to compile foreign import successfully, though I haven't yet tried running the bytecode it generates for that)
- -------- import Foreign.C (CInt) return3 :: IO CInt return3 = return 3 foreign export ccall return3 :: IO CInt main = putStrLn "okay" - --------
I've tried commenting out various combinations of the type-signatures, reordering the definition and the foreign export, making the return be IO or not, () or not... ghc -fffi only complains when I comment out the type-signature on the foreign export line, as expected based on the FFI spec. This is always just yhc -c dying, with various error messages.
Isaac -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE5a46HgcxvIWYTTURAjBPAKCF8fyuZCrwxOdK4hVsdDljMFWwZwCcCMxh ULKutHs0sNcQreGf86fauC8= =pXnT -----END PGP SIGNATURE----- _______________________________________________ Yhc mailing list Yhc@haskell.org http://www.haskell.org/mailman/listinfo/yhc

- -------- import Foreign.C (CInt) return3 :: IO CInt return3 = return 3 foreign export ccall return3 :: IO CInt main = putStrLn "okay" - --------
Well thinking about what this says it says "make the function 'return3' available to the C world as a C function". This is easy to arrange in GHC, just compile in an extra C-World function that converts the arguments and calls the Haskell world. However Yhc (very deliberately) doesn't generate C code, it generates byte code. The bytecode is then loaded at runtime, so if you want foreign exports then there are a couple of options, none of which are very nice: 1) Have a -wrap option to yhc which generates a C file with the wrapper functions in. This works but then there needs to be a special case for Yhc in peoples makefiles that knows to compile the generated C file with the rest of the C code. 2) Generate machine code at runtime. There is no even vaguely portable method for doing this, so it would have to be implemented on a case by case basis. I would also argue that generating machine code is rather against the spirit of Yhc's "clean and simple" design. 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. So suggestions are welcome, but ultimately I can't see a "nice" solution :-) Thanks Tom

-----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-----
participants (3)
-
Isaac
-
Neil Mitchell
-
shackell@cs.york.ac.uk