www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - compile time reflection to runtime reflection

reply BLS <nanali nospam-wanadoo.fr> writes:
Warning: This idea is probabely not a strike of a genius.

Simply said : Is Mr. Compiler able to produce a binary file which 
contains compile time reflection information ? In other words, a file 
which enable us to create classloader.d

To make it very slick I suggest to introduce the keyword : rtf
f.i.
module Runtime;
rtf class A
output-> A.drr

another idea is version(RTF)

Well hopefully this idea is not a complete mess...
Bjoern
Jul 24 2007
parent reply Reiner Pope <some address.com> writes:
BLS wrote:
 Warning: This idea is probabely not a strike of a genius.
 
 Simply said : Is Mr. Compiler able to produce a binary file which 
 contains compile time reflection information ? In other words, a file 
 which enable us to create classloader.d
 
 To make it very slick I suggest to introduce the keyword : rtf
 f.i.
 module Runtime;
 rtf class A
 output-> A.drr
 
 another idea is version(RTF)
 
 Well hopefully this idea is not a complete mess...
 Bjoern
 

of the class's declaration? But I think we already have enough to do it within D -- can't we use __traits to find about the types, and generate structs at compile-time using struct literals? So you can make a template which builds up a Member[] array, and then a Class[] array (supposing you could list all the classes in a module), and then you just write (at global scope) Class[] allClasses = GenerateRuntimeInfo!(my.module.name); Now we can access it at runtime! I started writing an example of how it would work, but I'm not too sure of the details. But I still think that compile-time reflection is enough: lifting information from compile-time to runtime is an easy enough operation. The other way is not. :) -- Reiner
Jul 24 2007
parent BLS <nanali nospam-wanadoo.fr> writes:
Reiner Pope schrieb:

Thanks Reiner,

 BLS wrote:
 Warning: This idea is probabely not a strike of a genius.

 Simply said : Is Mr. Compiler able to produce a binary file which 
 contains compile time reflection information ? In other words, a file 
 which enable us to create classloader.d

 To make it very slick I suggest to introduce the keyword : rtf
 f.i.
 module Runtime;
 rtf class A
 output-> A.drr

 another idea is version(RTF)

 Well hopefully this idea is not a complete mess...
 Bjoern

of the class's declaration?

Yes. rtf means runtime flectioned, indicating that the D compiler should generate a .drr file.
 
 But I think we already have enough to do it within D -- can't we use 
 __traits to find about the types, and generate structs at compile-time 
 using struct literals?
 
 So you can make a template which builds up a Member[] array, and then a 
 Class[] array (supposing you could list all the classes in a module), 
 and then you just write (at global scope)
 
 Class[] allClasses = GenerateRuntimeInfo!(my.module.name);
 
 Now we can access it at runtime!
 

You may know about Frank Benoit s TIOPORT project. A Java to D translator. One of the major goals of TIOPORT was to translate SWT into D: Frank did an amazing job, but due to the fact that D has less (compared to Java) runtime reflection support a simple hello world GUI SWT programm in D is bloated up to about 12 MB. My interest in SWT is building a D C/S IDE and a kind of multimedia Scintilla Control. But without having Java-like, better identical, Runtime Reflection everything I do now is not worth the effort...
 
 I started writing an example of how it would work, but I'm not too sure 
 of the details. But I still think that compile-time reflection is 
 enough: lifting information from compile-time to runtime is an easy 
 enough operation. The other way is not. :)
 
   -- Reiner

I am very interested to see the code! But IMO it means that I have to mixin your code into a class in case that I need Runtime Reflection. Why not letting the compiler do that Job ? Bjoern Bjoern
Jul 24 2007