digitalmars.D.learn - Compile time getTimes
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail hotmail.com> (20/20) Dec 27 2013 I'm writing a compiler that uses Pegged for parsing D code.
- Jonathan M Davis (9/32) Dec 27 2013 CTFE requires that all of the source code be available (which is not the...
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
Dec 27 2013
On Saturday, December 28, 2013 01:08:37 Casper Færgemand" <shorttail hotmail.com> puremagic.com wrote: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. =3CTFE requires that all of the source code be available (which is not the case with C functions) and isn't able to interact with the file system or any kind of I/O (beyond importing a file as a string). So, I believe that it's impossible to do something like check file times at compile time. You'll have to restrict yourself to stuff that you can do in code without any kind of I/O. http://dlang.org/function.html#interpretation - Jonathan M Davis
Dec 27 2013