From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:20 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:01 2007 Subject: [C2hs] patch applied (c2hs): Trivial cleanups Message-ID: <20070514011020.GA675@cvs.haskell.org> Wed May 2 13:50:35 PDT 2007 Duncan Coutts * Trivial cleanups M ./base/state/State.hs -15 +2 M ./base/state/StateTrans.hs -6 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:21 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:01 2007 Subject: [C2hs] patch applied (c2hs): Emit " with" marshaling function rather than deprecated " withObject" Message-ID: <20070514011021.GA695@cvs.haskell.org> Wed May 2 13:51:04 PDT 2007 Duncan Coutts * Emit "with" marshaling function rather than deprecated "withObject" M ./c2hs/gen/GenBind.hs -1 +1 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:22 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:03 2007 Subject: [C2hs] patch applied (c2hs): Pretty print ffi import strings as proper Haskell strings Message-ID: <20070514011022.GA710@cvs.haskell.org> Wed May 2 13:52:32 PDT 2007 Duncan Coutts * Pretty print ffi import strings as proper Haskell strings foriegn import ccall "foo\\bar.h baz" baz :: IO () Since the import spec string is actually parsed by the compiler as a Haskell string we should use show to pretty-print it. For one thing this means that windows backslash directory separators get escaped properly "foo\\bar". M ./c2hs/gen/GenBind.hs -2 +2 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:24 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:04 2007 Subject: [C2hs] patch applied (c2hs): Use filepath package Message-ID: <20070514011024.GA724@cvs.haskell.org> Sun May 13 10:46:51 PDT 2007 Duncan Coutts * Use filepath package And drop the home-grown FNameOps module. R ./base/general/FNameOps.hs M ./c2hs.cabal -1 +1 M ./c2hs/c/C.hs -3 +3 M ./c2hs/chs/CHS.hs -8 +9 M ./c2hs/toplevel/Main.hs -16 +20 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:25 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:06 2007 Subject: [C2hs] patch applied (c2hs): Don' t bother putting version info into the PreCST monad Message-ID: <20070514011025.GA738@cvs.haskell.org> Sun May 13 15:53:01 PDT 2007 Duncan Coutts * Don't bother putting version info into the PreCST monad Just get it from the Version module when we need it. R ./base/admin/BaseVersion.hs M ./base/state/State.hs -20 +4 M ./base/state/StateBase.hs -2 M ./c2hs.cabal -2 +1 M ./c2hs/chs/CHS.hs -4 +4 M ./c2hs/state/C2HSState.hs -2 +2 M ./c2hs/toplevel/Main.hs -8 +7 M ./c2hs/toplevel/Version.hs -2 +2 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:27 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:06 2007 Subject: [C2hs] patch applied (c2hs): Remove Config module Message-ID: <20070514011027.GA752@cvs.haskell.org> Sun May 13 16:16:41 PDT 2007 Duncan Coutts * Remove Config module It only exported one constant, which now lives in the module that uses it. R ./base/admin/ R ./base/admin/Config.hs M ./base/state/State.hs -1 +2 M ./c2hs.cabal -2 +1 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:28 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:08 2007 Subject: [C2hs] patch applied (c2hs): Remove unused mutable variable functions Message-ID: <20070514011028.GA766@cvs.haskell.org> Sun May 13 16:30:43 PDT 2007 Duncan Coutts * Remove unused mutable variable functions M ./base/state/State.hs -19 +1 M ./base/state/StateTrans.hs -20 +1 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:29 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:10 2007 Subject: [C2hs] patch applied (c2hs): Remove unused fixpoint monad combinator Message-ID: <20070514011029.GA781@cvs.haskell.org> Sun May 13 16:32:53 PDT 2007 Duncan Coutts * Remove unused fixpoint monad combinator If we ever need to add this back in, we should use the standard MonadFix class M ./base/state/State.hs -2 +2 M ./base/state/StateBase.hs -7 +2 M ./base/state/StateTrans.hs -21 +1 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:31 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:10 2007 Subject: [C2hs] patch applied (c2hs): Don' t rename standard monad operators Message-ID: <20070514011031.GA795@cvs.haskell.org> Sun May 13 16:37:45 PDT 2007 Duncan Coutts * Don't rename standard monad operators Don't bother providing nop, yield, (+>=), (+>), instead just use: return (), return, (>>=), (>>) M ./base/state/State.hs -2 M ./base/state/StateBase.hs -1 M ./c2hs/c/C.hs -1 +1 M ./c2hs/c/CNames.hs -7 +7 M ./c2hs/c/CTrav.hs -3 +3 M ./c2hs/chs/CHSLexer.hs -2 +2 M ./c2hs/gen/GenBind.hs -2 +2 M ./c2hs/toplevel/Main.hs -2 +2 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:32 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:12 2007 Subject: [C2hs] patch applied (c2hs): Remove more unused bits from the base State modules Message-ID: <20070514011032.GA809@cvs.haskell.org> Sun May 13 16:46:07 PDT 2007 Duncan Coutts * Remove more unused bits from the base State modules M ./base/state/StateBase.hs -15 M ./base/state/StateTrans.hs -8 From duncan.coutts at worc.ox.ac.uk Sun May 13 21:10:33 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun May 13 21:07:13 2007 Subject: [C2hs] patch applied (c2hs): Minimise imports Message-ID: <20070514011033.GA823@cvs.haskell.org> Sun May 13 17:40:40 PDT 2007 Duncan Coutts * Minimise imports Using ghc's -fwarn-unused-imports M ./base/general/UNames.hs -1 +1 M ./base/state/CIO.hs -3 +6 M ./base/state/State.hs -5 +3 M ./base/state/StateBase.hs -4 +1 M ./base/state/StateTrans.hs -6 M ./base/syms/Attributes.hs -5 +3 M ./base/syms/Idents.hs -1 +1 M ./base/syntax/Lexers.hs -4 +4 M ./c2hs.cabal -1 +1 M ./c2hs/c/C.hs -9 +4 M ./c2hs/c/CAST.hs -1 +1 M ./c2hs/c/CAttrs.hs -4 +3 M ./c2hs/c/CBuiltin.hs -1 +1 M ./c2hs/c/CLexer.x -4 +2 M ./c2hs/c/CNames.hs -2 +2 M ./c2hs/c/CParserMonad.hs -2 +2 M ./c2hs/c/CTrav.hs -4 +3 M ./c2hs/chs/CHS.hs -6 +4 M ./c2hs/chs/CHSLexer.hs -7 +6 M ./c2hs/gen/CInfo.hs -3 +2 M ./c2hs/gen/GBMonad.hs -7 +6 M ./c2hs/gen/GenBind.hs -16 +13 M ./c2hs/gen/GenHeader.hs -2 +2 M ./c2hs/state/C2HSState.hs -1 +1 M ./c2hs/toplevel/Main.hs -9 +6 M ./c2hs/toplevel/Version.hs -1 +1 From duncan.coutts at worc.ox.ac.uk Mon May 14 10:32:10 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon May 14 10:28:49 2007 Subject: [C2hs] patch applied (c2hs): CPtrDeclr can actually have no qualifiers Message-ID: <20070514143210.GA15402@cvs.haskell.org> Mon May 14 06:35:17 PDT 2007 Duncan Coutts * CPtrDeclr can actually have no qualifiers Remenant of the previous semantics. It used to be a non-empty list of possibly empty lists of qualifiers. Now it's just a possibly-empty list of qualifiers. So adjust the patterns to not specifially look for a non-empty qualifiers list. M ./c2hs/c/CTrav.hs -2 +2 From duncan.coutts at worc.ox.ac.uk Mon May 14 11:58:30 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon May 14 12:09:24 2007 Subject: [C2hs] new release? Message-ID: <1179158310.20151.236.camel@localhost> Hi Manuel, We could probably do a new release soonish. The main thing is testing. Two of the c2hs/tests/ are not working. In test/Calls.chs there's a slightly weird issue with C/Haskell name aliases. In the .chs file we've got: {#call fun MyString as myString#} but it generates: foreign import ccall safe "calls.h MyString" MyString :: (Ptr CChar) when it obviously should be: foreign import ccall safe "calls.h MyString" myString :: (Ptr CChar) It seems to me the wrong thing is happening when we parse the .chs file, we call (normAP apath oalias) which returns Nothing in this case: normAP :: CHSAPath -> Maybe Ident -> Maybe Ident normAP ide Nothing = Nothing normAP ide (Just ide') | apathToIdent ide == ide' = Nothing | otherwise = Just ide' and: apathToIdent (CHSRoot ide) = let lowerFirst (c:cs) = toLower c : cs in onlyPosIdent (posOf ide) (lowerFirst $ identToLexeme ide) For reasons I don't quite understand, it's comparing case insensitively on the first char and then because they appear to be equal it drops the alias and then end up using the original C name which was not a valid Haskell identifier. I've not looked at this code carefully enough to understand what's supposed to be happening. The structs test also fails, though I've not investigated why yet: c2hs structs.h Structs.chs c2hs: Errors during expansion of binding hooks: Structs.chs:32: (column 60) [ERROR] >>> Expected a pointer object! Attempt to dereference a non-pointer object or to use it in a `pointer' hook. The failing line is: val4 <- liftM cIntConv $ {#get weird->nested.pnt->y#} weird and the C types were: typedef struct _point *point; struct _point { int x, y; }; typedef struct { bool b; int x; struct { int y, z; point pnt; } nested; } *weird; Presumably the problem is with the nested.pnt part. Other things I'd like to do, not related to a release: * eliminate the C2HS.hs source module and the corresponding --copy-library flag. * use the MTL rather than the current StateTrans, StateBase, State * use bytestrings in the C lexer * add pre-compiled header support It turns out very few things in C2HS.hs are actually used by generated code, and the ones that are used are either just aliases of standard library functions or simple compositions of library functions. The remaining functions are presumably there to be used by the programmer in .chs modules. I'm not sure that we need to provide this, especially since most of them are duplicates of things in the standard lib. The main difficulty with this change is that currently the marshalers are just a single Ident identifier where as for simple compositions we need code fragments like "fmap fromIntegral . peek". Perhaps we should just replace it with a String. For pre-compiled headers, I think this can be done and be compatible with the #cppery we currently allow in .chs files. C translation units have the nice suffix extension property. Declarations added later cannot change the meaning of earlier declarations. So it'd be possible to precompile a common header and so long as that appears before any per-file custom stuff that all works out fine, we just extend the info from the pre-compiled header. For example: Foo.chs: #include #c blah #endc Bar.chs: #include #include "something-else.h" So these generate different .chs.h header files, but they share a common prefix. This will be very common when using cabal which passes on the command line all the .h files in the 'includes:', and these headers are considered to be #included before any other directives in the .chs files. So a simple scheme would be to just allow pre-compilation of those headers passed on the command line. To actually do this we have to keep track of some info so we can pick up extending the header where we left off. At a pure parsing level all we need is the current set of typedef identifiers. We can reasonably assume that the header defines a number of complete external declarations so we don't need to preserve the list of nested scopes, that list should always be empty. However we would want to have the pre-compiled header file contain not the C AST but the maps that c2hs generates. This would involve adjusting name analysis phase a bit so that it can work incrementally, one external declaration at a time. So the info kept in the pre-compiled header file would be the 4 maps and the set of typeidents along with various bits of meta data for sanity checking. To have cpp only produce the suffix of a translation unit it's possible to use: -imacros file Exactly like -include, except that any output produced by scanning file is thrown away. Macros it defines remain defined. This allows you to acquire all the macros from a header without also processing its declarations. So in the above example we'd use that flag with a .chs.h file containing just the #includes of the headers passed on the command line. As for the UI, this should be a bit easier these days since Cabal can automate things. We needn't try and make it totally transparent at the c2hs level, since we can get Cabal to make it transparent at the user level. The simplest thing I can think of is to have Cabal pass a precomp flag that tells c2hs to generate or use the given precomp file. Cabal would put this file in the dist/build dir so it'd be cleaned automatically. If the file didn't exist yet, c2hs would generate it based just on the headers passed on the command line, and without examining the .chs file. If the precomp file did exist, c2hs would use it and check that the list of headers (and other -C flags) passed were exactly the same as for the previous invocation when the file was generated. I'm not sure if it should be c2hs or Cabal's responsibility to re-generate the precomp file if a header file in the local source tree changed. All this assumes of course that actually using pre-compiled headers is really significantly faster. That has yet to be properly demonstrated but my expectation is that it will be much faster. I'll probably be doing this demo as part of the Data.Binary optimisation work. Duncan