Thread overview
what does CTFE get that external code gen dosn't?
Jul 24, 2007
BCS
Jul 24, 2007
BCS
July 24, 2007
If you can compile a program with CTFE then you can compile and run a D program.
If you can do that then you can run the same code and  have it generate .d file and then compile that on the next pass.

CTFE for data generation isn't mush harder to work with.

All I'm seeing is that CTFE lets you do it all in one pass (or with bud and no "fun stuff")

a script, makefile or whatever should be used for anything of any complexity so forgetting to do something isn't much of a problem.

So what does CTFE get you?

I'm wondering if anyone has some examples of where CTFE is a big plus over the other options.


July 24, 2007
"BCS" <ao@pathlink.com> wrote in message news:ce0a3343c2708c99c0f56ecb9e4@news.digitalmars.com...
> If you can compile a program with CTFE then you can compile and run a D
> program.
> If you can do that then you can run the same code and  have it generate .d
> file and then compile that on the next pass.

How on earth would you do:

mixin(GenCode!(int)("x"));

char[] GenCode(T)(char[] name)
{
    return T.stringof ~ " " ~ name ~ ";";
}

Across the program execution boundary?  How do you pass that template param? Your CodeGen program can only take char[][], remember.

(This is a simple example which could be done with templates too, but imagine this function is much longer.)

Multiple compilations sounds like a terrible hack, and isn't nearly as simple or expressive as this.


July 24, 2007
Reply to Jarrett,

> "BCS" <ao@pathlink.com> wrote in message
> news:ce0a3343c2708c99c0f56ecb9e4@news.digitalmars.com...
> 
>> If you can compile a program with CTFE then you can compile and run a
>> D
>> program.
>> If you can do that then you can run the same code and  have it
>> generate .d
>> file and then compile that on the next pass.
> How on earth would you do:
> 
> mixin(GenCode!(int)("x"));
> 
> char[] GenCode(T)(char[] name)
> {
> return T.stringof ~ " " ~ name ~ ";";
> }

I can be done as long as the mixin is global (can != should)

Your point can also be used for things like BLADE ware lots of semantic stuff gets built up and then used. (If inlining could be counted on then this might even be done externally)

> Across the program execution boundary?  How do you pass that template
> param? Your CodeGen program can only take char[][], remember.

that char[][] can include file names to input files that can be binary and or text. The program can also take as stdin the output from a full build (including link errors) and from this learn what is needed.

(again can != should, can ~ should not)

So the benefit of CTFE here is that CTFs can take semantic entities as template parameters?

> 
> Multiple compilations sounds like a terrible hack, and isn't nearly as
> simple or expressive as this.
> 

it's not much worse than lex/yacc. OTOH I'm trying to replace yacc with templates so what can I say?

I guess I was stuck thinking about just functions and then things more like yacc.

Thanks for the thoughts. It's exactly what I was hoping for.