Writing/Creating files at compile-time

Etienne via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 9 16:01:53 PDT 2015


On Sunday, 9 August 2015 at 21:48:13 UTC, JDemler wrote:
> On Sunday, 9 August 2015 at 14:00:55 UTC, Rikki Cattermole 
> wrote:
>> On 10/08/2015 1:57 a.m., cym13 wrote:
>>> On Sunday, 9 August 2015 at 13:51:21 UTC, Andrei Alexandrescu 
>>> wrote:
>>>> On 8/9/15 5:07 AM, JDemler wrote:
>>>>> [...]
>>>>
>>>> I think this is an interesting pursuit that closes the 
>>>> circle on a
>>>> number of issues, such as debuggability and compilation 
>>>> speed of mixin
>>>> code. -- Andrei
>>>
>>> The moment this is added to D, we will have two complete 
>>> languages in
>>> one: an interpreted one at compile-time and another at 
>>> runtime.
>>>
>>> While I find this interesting, I wonder wether this is  a 
>>> good idea or not.
>>
>> I'm actually at the point where I believe the addition of 
>> string import was a bad one. No. I prefer preprocessing into a 
>> D file first.
>> It irks me, you have to be pretty careful with them, but at 
>> least a preprocessed file you know _exactly_ where all files 
>> need to be for CT.
>
> Consider vibe.d's diet templates: They are compiled into d code 
> using information of the types provided by the user.
> Without string imports at compile-time that would either result 
> in a two-step compile process or would rely on run-time type 
> information. Both is nothing I would like to use.
>
> Imagine the .dt files could be compiled into .dt.d files and 
> then imported at compile-time. The development process would be 
> much easier (debugging and examining the source files becomes 
> trivial) and the usage would be more transparent (I see what my 
> .dt file gets compiled into) and would have faster compile 
> times (as Andrei mentioned).

You cam already do this I believe. You only need to write the 
string to a file instead of putting it through mixin. You import 
the module corresponding to the compiled diet template if it 
exists, or create it if it doesn't (at runtime). This means you 
get 2 runtimes though... But you also need a way to delete the .d 
file automatically once the .dt is changed. In the end, this is 
totally less convenient than writing a custom precompiler but 
whatever :)


More information about the Digitalmars-d mailing list