www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - compile-time functions, mixins, reflection

Hi,
1) Compile-time functions are very restricted atm and I wonder
whether it's wanted to make them more powerful at all.
I ask because Walter mentioned his concerns about the potential
abuse for malware authors.

I already suggested to process compile-time functions by spawning
another dmd as an interpreter (sh style script) while compiling.

2) Mixins seem to be processed before the objects are initialized.
That's one of the errors when trying to compile the example code.
 Error: variable owner is used before initialization
Couldn't this be done in one process ? I mean line-by-line processing of object initialization and mixins. 3) My example code below would benefit a lot from build-in reflection. An improved .tupleof for classes would be great. I am definitely missing the variable names in .tupleof. For example owner.tupleof would return (int, char[]). Why not (int, id, char[], name) ? Or maybe even better: .vars to return: (TypeInfo type, char[] nameofvar, char[] protection, bool derived) .functions to return: (TypeInfo returntype, char[] nameoffunction, TypeInfo params, bool variadic, char[] protection, bool derived) This is what I would like to be able to do: ---------------------------------------------------------------------- module test3; import tango.io.Stdout; import tango.text.convert.Layout; import rodin.reflection; class Owner { int id; char[] name; } char[] ctDump(A)(A a, char[] fs) { char[] result = ""; aggregateAll(); Layout!(char) Formatter; foreach (value; refGetClass(Formatter("test3.{0}", typeid(A))).variables) result ~= Formatter(fs, value.name); return result; } void main() { Stdout("test").newline; Owner owner; owner.id = 1; owner.name = "John Miller"; mixin(ctDump(owner, "Stdout(owner.{0}).newline")); } ---------------------------------------------------------------------- test3.d(28): Error: variable owner is used before initialization as mentioned in 2) test3.d(28): Error: cannot evaluate ctDump(owner,"Stdout(owner.{0}).newline") at compile time test3.d(28): Error: argument to mixin must be a string, not (ctDump(owner,"Stdout(owner.{0}).newline")) as mentioned in 1) Please tell me what you think about it. Best regards, Daniel
Apr 10 2007