CTFE ^^ (pow)

Manu turkeyman at gmail.com
Sat Mar 24 16:37:06 UTC 2018


On 24 March 2018 at 01:42, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 3/23/2018 11:09 AM, Manu wrote:
>>
>> Like, in this particular project, being able to generate all tables at
>> compile time is the thing that distinguishes the D code from the C++
>> code; it's the *whole point*... If I have to continue to generate
>> tables offline and paste big tables of data in the source code (and
>> then re-generate them manually when I change something); then
>> situation is identical to C++, therefore, stick with C++.\
>
>
> This file:
>
>   https://github.com/dlang/dmd/blob/master/src/dmd/backend/optabgen.c
>
> computes tables, and writes several tables out to several .c files, which
> are then #include'd into the main build. It all happens automagically using
> the makefile:
>
>   https://github.com/dlang/dmd/blob/master/src/win32.mak#L420
>
> I've been using this technique continually since the early 1980's :-)
>
> Some IDEs have problems with it, because they cannot support layered builds
> like this, but good old make does it just fine.
>
> I can't recall ever seeing anyone else use this technique (other than
> Nick!), but it works and isn't that bad.
>
> The dmd front end used to do this as well, but that has since been replaced
> with CTFE since it was converted to D.

I understand table generation, that is the standard approach. It's
made awkward by the fact that build systems are hard, and numerous,
and a user of a lib with such build requirement inherits that baggage
into their project.
I'm not sure why I seem to have to defend the idea that it's a *great
thing* that D (in theory; according to the advertising brochure) does
away with these requirements.
It just occurred to me too that it's not even that simple. The
instantiation sites (which are in user code) dictate what tables need
to be emit. It's not feasible to generate all possible tables...
there's a combinatorial explosion of possible inputs. I instantiate
only what tables the user needs on demand. It's impossible to
pre-generate 'all' tables; there's no such quantity.


More information about the Digitalmars-d mailing list