
Hi, I'm looking into implementing C preprocessing in WinHugs. I've looked around and bundling a copy of cpphs seems like the best solution, since few windows users will have a cpp hanging around somewhere that can be found. I've hacked together a basic implementation, the only thing is that its a lot slower, mainly because its being run on every single file which is completely unneeded. Is there some way to detect if a hs file requires preprocessing? If not, its almost going to be better to stick with no preprocessing, and have a faster development environment. The ways I thought of were: * Add some magic to the parser, so that if it encounters a # at the start of a line, it bails out and restarts again after preprocessing. * Only preprocess .cpp.hs or .hscpp or some other special suffix as having cpp directives. * Look into the file for some sort of command line arguments pragma on the first line denoting preprocessing. Thoughts? Thanks Neil

On Sun, Oct 30, 2005 at 02:18:09PM +0000, Neil Mitchell wrote:
I'm looking into implementing C preprocessing in WinHugs. I've looked around and bundling a copy of cpphs seems like the best solution, since few windows users will have a cpp hanging around somewhere that can be found.
Hugs uses cpphs for preprocessing the libraries, so there should already be a copy in the distribution.
I've hacked together a basic implementation, the only thing is that its a lot slower, mainly because its being run on every single file which is completely unneeded.
Are you using -F? Actually the preprocessor is run twice on most files, due to the way Hugs handles imports.
Is there some way to detect if a hs file requires preprocessing? If not, its almost going to be better to stick with no preprocessing, and have a faster development environment. The ways I thought of were:
* Add some magic to the parser, so that if it encounters a # at the start of a line, it bails out and restarts again after preprocessing.
* Only preprocess .cpp.hs or .hscpp or some other special suffix as having cpp directives.
* Look into the file for some sort of command line arguments pragma on the first line denoting preprocessing.
None are terribly attractive (and they would only be for cpp).

Hugs uses cpphs for preprocessing the libraries, so there should already be a copy in the distribution. There is a copy of the source code, but not a compiled binary.
I've hacked together a basic implementation, the only thing is that its a lot slower, mainly because its being run on every single file which is completely unneeded.
Are you using -F? Actually the preprocessor is run twice on most files, due to the way Hugs handles imports.
Yes, I'm using -F, but with some additional tweaks because popen on WinHugs without a console spawns an additional console window every time it is run, which is most annoying, and plays havoc with the focus of the window.
None are terribly attractive (and they would only be for cpp).
I agree. Is there no other way to stop the preprocessor running on all files, and restricting it to just those which are needed?

Neil Mitchell
None are terribly attractive (and they would only be for cpp).
I agree. Is there no other way to stop the preprocessor running on all files, and restricting it to just those which are needed?
There was talk at one stage of a standard language-extensions pragma, corresponding to your third option. {-# LANGUAGE cpp MPTC fundeps #-} I think SimonM has just implemented it for ghc, the rest of us are lagging behind. FWIW, hmake uses both of your first two suggestions - detect a # in the first column, and also permit a filename extension to trigger cpp. The latter doesn't seem too awful, since other preprocessors use the same method (Happy .y, Alex .x, hsc2hs .hsc, etc). Regards, Malcolm

On Mon, Oct 31, 2005 at 09:02:58AM +0000, Malcolm Wallace wrote:
There was talk at one stage of a standard language-extensions pragma, corresponding to your third option. {-# LANGUAGE cpp MPTC fundeps #-} I think SimonM has just implemented it for ghc, the rest of us are lagging behind.
{-# LANGUAGE CPP #-} has been supported for Hugs since last year, but only when building via Cabal. That is, the Cabal library handles it for --hugs, but assumes the compilers will handle it themselves.
participants (3)
-
Malcolm Wallace
-
Neil Mitchell
-
Ross Paterson