what does CTFE get that external code gen dosn't?

BCS ao at pathlink.com
Tue Jul 24 14:58:28 PDT 2007


Reply to Jarrett,

> "BCS" <ao at pathlink.com> wrote in message
> news:ce0a3343c2708c99c0f56ecb9e4 at 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.




More information about the Digitalmars-d-learn mailing list