Compile time getTimes

Casper Færgemand" <shorttail at hotmail.com> Casper Færgemand" <shorttail at hotmail.com>
Fri Dec 27 17:08:37 PST 2013


I'm writing a compiler that uses Pegged for parsing D code. 
Pegged is fed a string with a special grammar syntax and changes 
it into templated D code, which is in turn mixed in. Even with 
just a small subset of D, Pegged currently produces 4000 lines of 
dense code, and it consumes enough time for it to be bothersome 
on every change, especially changes to the compiler that don't 
touch the grammar.

I wrote some simple code that uses datetime's getTimes to compare 
modification time. If grammar.d was modified more recently than 
precompiled_grammar.d, grammar.d will be churned through the 
machine once more and the result overwrite the 
precompiled_grammar.d.

However, it works only on runtime. I moved stuff around and used 
an enum for the mixin, forcing compile time function execution, 
but it whines about getTimes being unusable: "Error: 
GetFileAttributesExW cannot be interpreted at compile time, 
because it has no available source code"

Is there some hack available? Currently I run the compiler twice 
to use the past precompiled stuff or run it once and accept that 
it's slow. And this is D, so I really feel I shouldn't have to. =3


More information about the Digitalmars-d-learn mailing list