
I'm trying to define a macro inside a template that generates an existing macro: --- #define hsc_test(hst,ct) \ { \ printf("#def inline int b_%s(void){return %s;}\n", hst,ct); \ printf("foreign import ccall b_%s :: CInt\n", hst); \ } --- Contrary to my expectation, the '#def' construct printed at the first 'printf' is included in the final haskell file, instead of beeing removed and replaced by a C function definition in a c header file. Is it possible to define an hsc_-like construct that generates code that is again parsed by hsc2hs? Thanks, Maurício

On Tue, Jul 14, 2009 at 9:51 PM, Maurício
I'm trying to define a macro inside a template that generates an existing macro:
---
#define hsc_test(hst,ct) \ { \ printf("#def inline int b_%s(void){return %s;}\n", hst,ct); \ printf("foreign import ccall b_%s :: CInt\n", hst); \ }
---
Contrary to my expectation, the '#def' construct printed at the first 'printf' is included in the final haskell file, instead of beeing removed and replaced by a C function definition in a c header file.
I thought CPP igored tokens occurring in strings? So CPP wouldn't even see the #define in the argument to printf. I'm not a C wizard, but I though that's how it worked. Antoine

On Jul 14, 2009, at 22:51 , Maurí cio wrote:
I'm trying to define a macro inside a template that generates an existing macro:
Won't fly; cpp doesn't scan its own output recursively, so if you generate a #define in a macro it will appear in the output unexpanded. AFAIK cpphs is no different. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Wed, Jul 15, 2009 at 5:21 AM, Brandon S. Allbery
KF8NH
On Jul 14, 2009, at 22:51 , Maurí cio wrote:
I'm trying to define a macro inside a template that generates an existing macro:
Won't fly; cpp doesn't scan its own output recursively, so if you generate a #define in a macro it will appear in the output unexpanded. AFAIK cpphs is no different.
Maybe it's time for someone to write m4hs? ;-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe

I'm trying to define a macro inside a template that generates an existing macro:
Won't fly; cpp doesn't scan its own output recursively, so if you generate a #define in a macro it will appear in the output unexpanded.
But isn't this also scanned by hsc2hs? After all, #def (not #define) is not a cpp macro, but an instruction for hsc2hs to insert code in a header file. In hsc2hs, a construct like: #test is actually handled by a function definition with name hsc_test, which outputs an expansion. I can't find, however, something like hsc_def that I could call from my function. If I could get my code to be first processed by cpp and only then by hsc2hs, I think the problem would be solved. Is it possible to do that? Maurício
participants (4)
-
Antoine Latter
-
Brandon S. Allbery KF8NH
-
Magnus Therning
-
Maurício