View mode: basic / threaded / horizontal-split · Log in · Help
September 22, 2011
Re: Paradox about D's popularity.
On 2011-09-22 11:47, Regan Heath wrote:
> At one time (2+ years back) I started writing a C lexer, and then C
> preprocessor in D. In part to learn about how compilers work and in part
> to convert C headers to D (there was no .di at that stage) so I could
> interface C. The lexer was no trouble, I even managed to make it
> flexible by having it read a C grammar file but when I got to the
> preprocessor I lost steam/momentum and it all fell by the way side.
>
> Something I discovered, which may help bootstrap your plans, is that
> most C compilers will preprocess source for you and give you the
> resulting stream of text, which you can then lex/parse/etc. However,
> this results in the C compiler processing macros and following includes,
> which you often don't actually want it to do - as you're likely trying
> to replicate the file tree (so want to see includes) and trying to
> replace macros with CTFE or similar.
>
> So, perhaps a combined approach, tame a compiler and have it preprocess
> a file at a time and then use that output, plus the original file to
> produce some D replacement code.. not sure if that would work but it
> might be worth investigating.
>
> R
>
>

I've done something similar using Clang: 
https://github.com/jacob-carlborg/clang

-- 
/Jacob Carlborg
September 22, 2011
Re: Paradox about D's popularity.
Ideally, you also want to simply convert #ifdefs to static ifs as well. It's details like this that have convinced me I can manually convert headers in less time than it takes me to manually post-process the result of an automatic translator. Sad. 

Sent from my iPhone

On Sep 21, 2011, at 2:33 PM, Dmitry Olshansky <dmitry.olsh@gmail.com> wrote:

> On 22.09.2011 1:14, Gor F. Gyolchanyan wrote:
>> I had an idea of a D library for including C headers for a while now.
>> All i need is to make a compile-time C parser for that. This thing would literally
>> remove any need for binding.
> 
> Translating header file is a one-time job, as in
> sh-$: translate fancy.h fancy.di
> 
> Why would you need to do it at compile time, except because it's fancy :), I don't quite get.
> 
> And, as much as I'm sorry to bring bad news, you'd have to make a C preprocessor as well (or even in the first place). Then you'd have to struggle through vendor extensions but that's doable.
> 
> 
> 
> -- 
> Dmitry Olshansky
September 22, 2011
Re: Paradox about D's popularity.
I'm thinking the best way to translate C headers is to run it
through a string processor instead of a compiler.

There's some places where I want the compiler - especially figuring
out the values of some constants - but usually, when translating
C headers, I just copy/paste and find/replace.
September 22, 2011
Re: Paradox about D's popularity.
On 21/09/11 6:41 PM, bearophile wrote:
> Gor Gyolchanyan:
>
>> I'm ready to donate money to sponsor an ad campaign.
>
> Advertising has to be done at the right time and rhythm. Too little and no one knows you, too much and you risk wasting the single opportunity certain persons will give you. D doesn't need too much advertising now. There is not even a hash map in Phobos and there are some unfinished parts in the core language, like inout, const, modules, associative arrays, etc.
>
> Bye,
> bearophile

I agree with this. There are large and important parts of the language 
that simply haven't been implemented or barely work.

If everyone were to come and use D now, expecting a finished language, 
they would be disappointed. A single bad experience can put people off 
for years, or even a lifetime. Just look at how many people still 
complain about Tango vs. Phobos. It's not worth risking IMO.
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home