Reflection: potential possibilities

Thomas Kuehne thomas-dloop at kuehne.cn
Fri Jun 8 01:25:21 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

gareis schrieb am 2007-06-08:
> Using TypeInfo, ClassInfo, and such, you can gain a fair bit of 
> knowledge about a class at runtime.
>
> You could also modify TypeInfo and ClassInfo. Flectioned does this in 
> allowing you to redirect functions.
>
> You should then be able to create a class at runtime and instantiate it.
>
> The problem, of course, is connecting compile-time code to run-time 
> classes. This gives two options:
> 1. Use CTFE to create classes based on other classes, or just use mixins 
> and avoid the creation issue entirely.
> 2. Use a parent class. Virtual means it just works. (Hopefully.)
>
> I haven't tried these, but it sounds like, if this works, and combined 
> with function arrays, it should be possible to come up with a program 
> that writes and then runs itself at runtime. (You need function arrays 
> to support arbitrary numbers of methods per class.)
>
> The main issues are:
>   - Does this work at all? Can I create a ClassInfo / TypeInfo object 
> and then instantiate from it, or do I always need to go from a 
> preexisting class? Can I actually modify a ClassInfo object and have the 
> changes reflected in the program? Flectioned seems to indicate so, since 
> you can redirect functions.
>   - If it works, how can I link compile-time code to run-time classes?
>
> Any thoughts?
>
> Worst case, for my project, I'll have to use CTFE to parse ClassInfo and 
> then use mixins to create the classes.

If all your class member functions are functions have the signature
	T functionName(TypeInfo[], void*)
and the dynamic classes use a common base class like:

# class DynObject : Object{
# 	T call(char[] name, TypeInfo[], void*);
# }

This can be implemented via Flectioned. The problem is how variadic
functions are implemented in D - especially GDC on 64bit systems.

Thomas


-----BEGIN PGP SIGNATURE-----

iQIVAwUBRmkc27ZlboUnBhRKAQI1Ng/+Ku2fO+KHVYSgkSi445ABIC6/osx0cvCf
NzbJmtb37j26MN3jCG9mHCPU8L0C8ru6tSexC2KSWVjeuPWb/OuOm5tabnTF8kT4
MDGPtHWHTJrKyzdPJuhvTq0fTNOhcjfbI4VwnxYsved6sV4Gk++GmaVuhbHJ7IK3
eoqmYBKOAhMmfVXD4CjJLjHUdCSk4A6fMcYcxoiJVXGVVeFKk88Ev2qm5gPhNEWx
D+sPvcnvkN3sx7wz1AwGa/J3dLE0ROGih+1HSomsCKYpXS+5Hhfe53te2VIIT3YF
whjCww53qjI8HwIsqOYSLW5vI3yXQjlsgv1eKRhY+L8Ts7MDyGvH+mciEkczx1TF
uA2Or25pZmQ36Rv+xYTXC5yqSvAms/k2Cb6kgqkMCKkXyP8S7bZBGNmBM1tBLX0z
wzsjfal1Wpt6FNBLyNA5Vkd7GpznCsohpieEA/j/XvLSfJqg1Q1T4hndHzwr0LwE
NdUILMeEWXXAm6s5LS6NB9tU308lwFnRwalH9taEYD/Rg77ogEeGnXZER+Ek3gpG
9XDoEbtAxXj7/MFLlq5PZPl5fwg44xnifLOIefKbhXw3UboQzI68MIpVm96lQyHl
Atgn9yJ+Q0NBcHVdD/SGsylYRT7tHSiGT/Y7YZE4Xm7mDckdoLz4gELFiGAuMkgC
rvncawprfXs=
=VVM8
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list