Motivation for compile time function execution

Miles _______ at _______.____
Thu Feb 15 15:39:56 PST 2007


Walter Bright wrote:
> Even worse, if you're going to use
> string templates to parse, say, a 1000 character DSL, the template name
> generated must include its arguments, so that template identifier will
> be 1000 characters long.

Wait... this sounds too wrong... instantiated templates with string
arguments hold the whole string on the template symbol?

(checking myself...)

Ugh... yes, it is. Worse, the string is in hexadecimal...

Using the whole string on the template symbol limits the parameter size.
 On Linux, IIRC, the maximum symbol size is 4096 bytes, which limits
strings to a little less than 2000 bytes using the current scheme.

Is there some rationale for not using an MD5 hash of the string?

1. Although MD5 is not (anymore) a good cryptographic hash, it is fast
and good to avoid collisions;
2. collisions should not be a problem unless the programmer really wants
to collide symbols, for whatever strange reason;
3. it uses a fixed space on symbol name, allowing parameters of
arbitrary size;
4. it reduces the text object memory space for long strings;
5. it should reduce the overhead over the compiler and the linker.

Better yet would be to encode the MD5 hash using a variant of Base64
instead of hexadecimal digits, to make it shorter.



More information about the Digitalmars-d mailing list