Understanding regexes (Was: Re: DMD 0.147 release)

Lionello Lunesu lio at remove.lunesu.com
Wed Feb 22 00:20:30 PST 2006


Interesting indeed.

Is there no way to "fold constants" in this kind of code too? If you know 
the inputs to a function are all constant, can't you simply replace the 
inputs + function call with the function's output?

Would be really cool if this kind of general constant folding could take 
place. The compiler would need to keep track of all constant variables, and 
flagging outputs of operations with constants as constants too. In your 
example, since the input to the strlen function is a constant, the compiler 
could just call the strlen-code itself and replace the actual call with that 
call's output.

I have no experience what-so-ever with compiler writing, so I'm probably 
overlooking MANY things :-)

Lio.

"Walter Bright" <newshound at digitalmars.com> wrote in message 
news:dtfin6$29hi$1 at digitaldaemon.com...
>
> "Georg Wrede" <georg.wrede at nospam.org> wrote in message 
> news:43FB25FC.8090806 at nospam.org...
>> Walter Bright wrote:
>>> If the compiler is to constant fold regular expressions, then it
>>> needs to build in to the compiler exactly what would happen if the
>>> regex code was evaluated at runtime.
>> Yes. IMHO in essence, the binary machine code, which the runtime also 
>> would build. What I have a hard time seeing is, how this differs from 
>> building a normal function at compile time?
>
> Consider the strlen() function. Compiling a strlen() function and 
> generating machine code for it is a very different thing from the compiler 
> knowing what strlen is and replacing:
>
>    strlen("abc")
>
> with:
>
>    3
> 





More information about the Digitalmars-d-announce mailing list