February 04, 2003 D Templates + DCG = love. | ||||
---|---|---|---|---|
| ||||
It has striken me like a lightning! EXPLICIT TEMPLATE INSTANTIATION MAKES A VERY WELL-SUITED CONTEXT FOR DYNAMIC CODE GENERATION!!! I came to this conclusion when i thought about Tick C compiler. What it does, for code specified to be dynamic, it generates "templates" consisting of almost-compiled code with placeholders for runtime-established constants. As soon as this code is to be used, a template is instantiated, placeholders filled in, and a compilation is being concluded with a few simple optimisations. This could be done in some future VM implementation of D. It actually requieres no VM, since instantiation code might be very small. Think about it: your code handles matrices of different sizes. If such a runtime system is used, the object code size would be reduced. Sometimes you want to make a lot of processing on an array of a dimension, which becomes fixed at runtime. This would give it some boost as well. (It did with Tick C against GCC in a GIMP plug-in!) I recommend, that template parameters can thus be not only integers, but also any kinds of "small" values: real, complex, even structures. Thus, e.g. if a template is instantiated with an array, it gets a constant structure with a pointer and a length. Since for now there are no clear ways of implementation, such obscure template parameters (anything non-integer or not known at compile time) could simply become immutable variables having a scope of template. Possibly a warning can be issued if they are used. So it actually can be made part of the language now, and get active and efficient support later on. Opinons? -i. |
Copyright © 1999-2021 by the D Language Foundation