Compile time function execution...

Max Samukha samukha at voliacable.com
Fri Feb 16 04:43:40 PST 2007


On Thu, 15 Feb 2007 13:02:40 -0800, Walter Bright
<newshound at digitalmars.com> wrote:

>Gregor Richards wrote:
>> I see that I can't do this:
>> 
>> char[] someCompileTimeFunction()
>> {
>>     return "writefln(\"Wowza!\");";
>> }
>> 
>> int main()
>> {
>>     mixin(someCompileTimeFunction());
>>     return 0;
>> }
>> 
>> 
>> Any chance of compile-time code generation via this mechanism? Or are 
>> they simply handled in different, incompatible steps of compilation?
>> 
>>  - Gregor Richards
>> 
>> PS: Yes, I realize this is a terrible idea ^^
>
>That's a bug. I'll fix it.

The following must be a related bug. The compiler complains that the
argument to the mixin is not a string and parse() cannot be evaliated
at compile-time.

char[] parse(char[] src)
{
	return src;
}

class Test
{
	mixin(parse(import("guts.dspx")));
}

void main()
{
	
}

BTW, thanks for the awesome feature!



More information about the Digitalmars-d mailing list