New syntax for string mixins

foobar foo at bar.com
Sat Dec 18 07:27:34 PST 2010


Don Wrote:

> VladD2 wrote:
> > Don Wrote:
> >> Suppose the pre-compiled code, when run, asks what CPU it's on. What's 
> >> the answer? Is it X or Y?
> > 
> > Current: X
> > Target: Y
> > 
> > Macro - a plugin to the compiler. It works on the same platform as the compiler, but generates code through the API which abstracts the macro from the target platform. If you need generate platform specific code, you should worry about it in macro logic.
> > In any case macro is a meta-programm wich generate or/and transform code. 
> 
> Yes. But in D there's no distinction between code which is destined for 
> a macro, versus any other function. You can call a function once at 
> compile time, and the same function at compile time. My understanding of 
> Nemerle (which is quite likely to be wrong!) is that at least some 
> functions are callable only at compile-time.
> 

I don't see how there needs to be different code to accomplish the above use case. You have a function that tests the hardware it's being run on. When this function is called in the compiler context it would return X, when it's called from the target executable it returns Y. 

> I'm also scared of the implications of allowing arbitrary code execution 
> during compilation. Make a typo in your program, and then compilation 
> may wipe files from your hard disk, or corrupt an external database, 
> etc... On some platforms you may be able to sandbox it, but since it's 
> running as part of the compilation process, rather than with the 
> permissions it will eventually have, it just seems like a security 
> nightmare.
> 

This is a void argument since templates are Turing complete.
It's *already* possible to do all of the above in D at compile time, it's just a matter of how much code is required to accomplish this. 

> All these problems would be reduced somewhat if it were only permissible 
> to call pure functions at compile time. Although even that has issues, 
> since not all compiler platforms may allow calling of shared libraries. 
> If we build that into the language, we'd be cutting ourselves off from 
> those platforms.
> 
> I'm not certain that there are any unsurmountable problems, but these 
> issues make me really cautious.



More information about the Digitalmars-d mailing list