
On Tue, 2009-09-22 at 11:54 -0700, Thomas DuBuisson wrote:
True. Perhaps I'll try pushing the regparm3 patch to HEAD. The main issue is flexibility - it would be much better to support some sort of __attribute__() system so we don't have to manually ad regparmX for all reasonable values of X.
Right, the "" part of the FFI syntax is the most flexible, but the main calling convention is given outside that. For the "foreign import prim" stuff we have loads of extra attributes which we're just planning to add to the "" part of the syntax, like: foreign import prim "integerAdd commutable=True" integerAdd# :: Int# -> ByteArray# -> Int# -> ByteArray# -> (# Int#, ByteArray# #) So perhaps something like that is the way to go: foreign import ccall "k_thingy (regparam 3)" It's worth asking on the ghc and/or libraries list.
I just made this and gcc accepts it without issue:
---- START enum.h ---- extern enum hello hello_fn(int); ---- END enum.h ----
This can be # included in any .c and gcc will compile it without complaint (even with -Wall). OTOH, c2hs will not parse such a file.
Ah hah: c2hs: C header contains errors: foo.h:1: (column 8) [ERROR] >>> error Forward definition of enumeration! ANSI C does not permit forward definitions of enumerations! So it's not actually a parser error. We parse it just fine, the problem is the C analysis phase does not like this (which is why we get such a detailed error message). I've filed a ticket: http://hackage.haskell.org/trac/c2hs/ticket/23 Duncan