[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] Using stringize and string concatenation in ghc preprocessing
From:       Harendra Kumar <harendra.kumar () gmail ! com>
Date:       2016-08-22 5:52:03
Message-ID: CAPW+kka=RhxRzRrtuBuumcwf2DEbjFYuk+XVei9q+zwbQhAAiw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thanks Mathieu. This works pretty well for gcc (
https://gcc.gnu.org/onlinedocs/cpp/Traditional-macros.html) but sadly it
does not work for clang cpp as Brandon too pointed out earlier that clang
does not have a traditional mode.

-harendra

On 22 August 2016 at 02:01, Boespflug, Mathieu <m@tweag.io> wrote:

> Hi Harendra,
>
> I ran into this very problem recently. Turns out -traditional knows string
> concatenation too. I seem to remember learning this by browsing the GHC
> source code, but now I can't find any occurrence of this pattern. But
> here's an example of how to do string concatenation with CPP in
> -traditional mode: https://github.com/tweag/sparkle/blob/
> a4e481aa5180b6ec93c219f827aefe932b66a953/inline-java/src/
> Foreign/JNI.hs#L274.
>
> HTH,
>
> --
> Mathieu Boespflug
> Founder at http://tweag.io.
>
> On 20 August 2016 at 20:33, Brandon Allbery <allbery.b@gmail.com> wrote:
>
>> On Sat, Aug 20, 2016 at 2:27 PM, Harendra Kumar <harendra.kumar@gmail.com
>> > wrote:
>>
>>> But "-optP" seems to only append to the flags that GHC already passes
>>> and gcc has no "-no-traditional" option to undo the effect of the
>>> "-traditional" that GHC has already passed. I think "-optP" should override
>>> the flags passed by ghc rather than appending to them. Is there a reason
>>> not to do that?
>>>
>>> Is there any other better way to achieve this? What is the standard way
>>> of doing this if any?
>>>
>>
>> Removing -traditional will break much Haskell source. Go look at the
>> history of clang with ghc (clang doesn't do -traditional) to see what
>> happens. (tl;dr: without -traditional, cpp knows too much about what
>> constitutes valid C, and mangles and/or throws errors on valid Haskell that
>> doesn't lex the way C does.)
>>
>> You might want to look at cpphs as an alternative preprocessor. There are
>> some ancient K&R-era hacks that could be used if absolutely necessary, but
>> cpphs should be a much simpler and cleaner solution.
>>
>> --
>> brandon s allbery kf8nh                               sine nomine
>> associates
>> allbery.b@gmail.com
>> ballbery@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>> _______________________________________________
>> ghc-devs mailing list
>> ghc-devs@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>>
>>
>

[Attachment #5 (text/html)]

<div dir="ltr">Thanks Mathieu. This works pretty well for gcc (<a \
href="https://gcc.gnu.org/onlinedocs/cpp/Traditional-macros.html">https://gcc.gnu.org/onlinedocs/cpp/Traditional-macros.html</a>) \
but sadly it does not work for clang cpp as Brandon too pointed out earlier that \
clang does not have a traditional mode.<div><br></div><div>-harendra<br><div \
class="gmail_extra"><br><div class="gmail_quote">On 22 August 2016 at 02:01, \
Boespflug, Mathieu <span dir="ltr">&lt;<a href="mailto:m@tweag.io" \
target="_blank">m@tweag.io</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" \
style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div \
dir="ltr">Hi Harendra,<div><br></div><div>I ran into this very problem recently. \
Turns out -traditional knows string concatenation too. I seem to remember learning \
this by browsing the GHC source code, but now I can&#39;t find any occurrence of this \
pattern. But here&#39;s an example of how to do string concatenation with CPP in \
-traditional mode:  <a \
href="https://github.com/tweag/sparkle/blob/a4e481aa5180b6ec93c219f827aefe932b66a953/inline-java/src/Foreign/JNI.hs#L274" \
target="_blank">https://github.com/<wbr>tweag/sparkle/blob/<wbr>a4e481aa5180b6ec93c219 \
f827aefe<wbr>932b66a953/inline-java/src/<wbr>Foreign/JNI.hs#L274</a>.</div><div><br></div><div>HTH,</div></div><div \
class="gmail_extra"><br clear="all"><div><div \
data-smartmail="gmail_signature">--<br>Mathieu Boespflug<br>Founder at <a \
href="http://tweag.io" target="_blank">http://tweag.io</a>.</div></div> <br><div \
class="gmail_quote"><div><div class="h5">On 20 August 2016 at 20:33, Brandon Allbery \
<span dir="ltr">&lt;<a href="mailto:allbery.b@gmail.com" \
target="_blank">allbery.b@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div \
class="h5"><div dir="ltr"><div class="gmail_extra"><span><div class="gmail_quote">On \
Sat, Aug 20, 2016 at 2:27 PM, Harendra Kumar <span dir="ltr">&lt;<a \
href="mailto:harendra.kumar@gmail.com" \
target="_blank">harendra.kumar@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div \
dir="ltr">But &quot;-optP&quot; seems to only append to the flags that GHC already \
passes and gcc has no &quot;-no-traditional&quot; option to undo the effect of the \
&quot;-traditional&quot; that GHC has already passed. I think &quot;-optP&quot; \
should override the flags passed by ghc rather than appending to them. Is there a \
reason not to do that?<div><br></div><div><div>Is there any other better way to \
achieve this? What is the standard way of doing this if \
any?</div></div></div></blockquote></div><br></span>Removing -traditional will break \
much Haskell source. Go look at the history of clang with ghc (clang doesn&#39;t do \
-traditional) to see what happens. (tl;dr: without -traditional, cpp knows too much \
about what constitutes valid C, and mangles and/or throws errors on valid Haskell \
that doesn&#39;t lex the way C does.)</div><div class="gmail_extra"><br></div><div \
class="gmail_extra">You might want to look at cpphs as an alternative preprocessor. \
There are some ancient K&amp;R-era hacks that could be used if absolutely necessary, \
but cpphs should be a much simpler and cleaner solution.<span><font \
color="#888888"><br clear="all"><div><br></div>-- <br><div \
data-smartmail="gmail_signature"><div dir="ltr"><div>brandon s allbery kf8nh          \
sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" \
target="_blank">allbery.b@gmail.com</a>                                               \
<a href="mailto:ballbery@sinenomine.net" \
target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, \
infrastructure, xmonad            <a href="http://sinenomine.net" \
target="_blank">http://sinenomine.net</a></div></div></div> \
</font></span></div></div> \
<br></div></div>______________________________<wbr>_________________<br> ghc-devs \
mailing list<br> <a href="mailto:ghc-devs@haskell.org" \
target="_blank">ghc-devs@haskell.org</a><br> <a \
href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" \
target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/ghc-devs</a><br>
 <br></blockquote></div><br></div>
</blockquote></div><br></div></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic