digitalmars.D.announce - dflect alpha
- Ben Hinkle (52/52) Jul 04 2005 I've started poking around with a reflection API for D called "dflect" a...
- Andrew Fedoniouk (13/69) Jul 04 2005 Cool!
- Uwe Salomon (6/13) Jul 04 2005 I stumbled over that one, too. Isn't it possible to include that like th...
- Ben Hinkle (7/23) Jul 04 2005 You're both right. When I tried Foo.x.offsetof I got a compiler error so...
- Ben Hinkle (10/37) Jul 05 2005 I got method dispatching working and when doing so I needed the slot num...
- Andrew Fedoniouk (2/6) Jul 05 2005 Cool. I mean extremely cool.
- Ben Hinkle (5/17) Jul 04 2005 The only dependency I'm aware of would be version switches. Debugging an...
- Andrew Fedoniouk (3/25) Jul 04 2005 I see, thanks, Ben.
- Markus Dangl (3/11) Jul 07 2005 Sorry, i can't find dflect.d in the zip file. Where can i get it?
- Ben Hinkle (6/15) Jul 07 2005 I forgot that part. I've updated the zip file and make a page for it
- pragma (6/23) Jul 08 2005 Ben,
- Ben Hinkle (10/37) Jul 08 2005 dlint and this reflection generator were the two reasons I wanted dmdfe ...
- pragma (11/50) Jul 10 2005 Funny you should mention that.
- Ben Hinkle (9/9) Jul 16 2005 A request for input: what (if any) metadata tags (which aren't already i...
- pragma (13/23) Jul 16 2005 Ben, here's my opinion. :)
- Ben Hinkle (11/45) Jul 16 2005 I agree dflect isn't meant to be used to generate doc. The reason I
I've started poking around with a reflection API for D called "dflect" and here's what I have after a day (the zip of the files is http://home.comcast.net/~benhinkle/dflect.zip). Comments welcome. The basic idea is that to generate metadata about a module you run dflect.exe (based not surprisingly on dmdfe) which takes a module foo and generates another D source file fooinfo with auto-generated classes describing the original module. You then compile and link in these metadata modules into the final binary. Right now it only supports fields but I'll start poking around with methods next. I haven't even started thinking about templates and more complex modules. For example given the module module test; class Foo { int x; char[] y; } running dflect gives something like // Auto-generated reflection data for module test import dflect; import test; class FooInfo : MetaClass { static MetaClass makeInfo(){return new FooInfo;} Object construct(){return new Foo;} this() { fields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8); } } static this() { dflect.register("test.Foo",&FooInfo.makeInfo); } Here's a sample app using the resulting metadata: import dflect; import test; int main() { MetaClass cls = getInfo("test.Foo"); Foo u = new Foo; MetaField field = cls.fields["x"]; field.set(u,100); field = cls.fields["y"]; field.set(u,"hello"); printf("setter %d %.*s\n",u.x,u.y); char[] res; field.get(u,&res); printf("getter %.*s\n",res); return 0; } C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter hello
Jul 04 2005
Cool! One question: as far as I remember order of fields in class instances may be different from declaration order. How then this will reliably work for classes?:fields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right? BTW: does D class layout depends on command line switches? Andrew. "Ben Hinkle" <ben.hinkle gmail.com> wrote in message news:dab8av$s2q$1 digitaldaemon.com...I've started poking around with a reflection API for D called "dflect" and here's what I have after a day (the zip of the files is http://home.comcast.net/~benhinkle/dflect.zip). Comments welcome. The basic idea is that to generate metadata about a module you run dflect.exe (based not surprisingly on dmdfe) which takes a module foo and generates another D source file fooinfo with auto-generated classes describing the original module. You then compile and link in these metadata modules into the final binary. Right now it only supports fields but I'll start poking around with methods next. I haven't even started thinking about templates and more complex modules. For example given the module module test; class Foo { int x; char[] y; } running dflect gives something like // Auto-generated reflection data for module test import dflect; import test; class FooInfo : MetaClass { static MetaClass makeInfo(){return new FooInfo;} Object construct(){return new Foo;} this() { fields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8); } } static this() { dflect.register("test.Foo",&FooInfo.makeInfo); } Here's a sample app using the resulting metadata: import dflect; import test; int main() { MetaClass cls = getInfo("test.Foo"); Foo u = new Foo; MetaField field = cls.fields["x"]; field.set(u,100); field = cls.fields["y"]; field.set(u,"hello"); printf("setter %d %.*s\n",u.x,u.y); char[] res; field.get(u,&res); printf("getter %.*s\n",res); return 0; } C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter hello
Jul 04 2005
How then this will reliably work for classes?:I stumbled over that one, too. Isn't it possible to include that like this: fields["x"] = new MetaField("x", typeid(int), Foo.x.offsetof, Foo.x.sizeof); That should always work as expected? Ciao uwefields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right?
Jul 04 2005
"Uwe Salomon" <post uwesalomon.de> wrote in message news:op.stejkmuh6yjbe6 sandmann.maerchenwald.net...You're both right. When I tried Foo.x.offsetof I got a compiler error so I just slapped in the number. I'll post something to D.bugs so that Walter can fix it - assuming what I saw was a bug. I'm also thinking of not importing the original module and in that case the fixed numbers would be the way to go.How then this will reliably work for classes?:I stumbled over that one, too. Isn't it possible to include that like this: fields["x"] = new MetaField("x", typeid(int), Foo.x.offsetof, Foo.x.sizeof); That should always work as expected? Ciao uwefields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right?
Jul 04 2005
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message news:dac0na$1hg5$1 digitaldaemon.com..."Uwe Salomon" <post uwesalomon.de> wrote in message news:op.stejkmuh6yjbe6 sandmann.maerchenwald.net...I got method dispatching working and when doing so I needed the slot number in the vtable for each method so there are definitely going to be hard-coded values in the metadata code. I decided to remove the import of the original module so I'm leaving the field offset numbers. The size might get removed and computed from the TypeInfo but for now I'll let it be. I've also written a C header file for all this so now C/C++ code can get/set fields and call methods on D objects using an API that roughly looks like JNI. I'll post an update soon.You're both right. When I tried Foo.x.offsetof I got a compiler error so I just slapped in the number. I'll post something to D.bugs so that Walter can fix it - assuming what I saw was a bug. I'm also thinking of not importing the original module and in that case the fixed numbers would be the way to go.How then this will reliably work for classes?:I stumbled over that one, too. Isn't it possible to include that like this: fields["x"] = new MetaField("x", typeid(int), Foo.x.offsetof, Foo.x.sizeof); That should always work as expected? Ciao uwefields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right?
Jul 05 2005
I've also written a C header file for all this so now C/C++ code can get/set fields and call methods on D objects using an API that roughly looks like JNI. I'll post an update soon.Cool. I mean extremely cool. Probably it will be possible to make transparent interop DMDScript <-> D ...
Jul 05 2005
"Andrew Fedoniouk" <news terrainformatica.com> wrote in message news:dabv5q$1gci$1 digitaldaemon.com...Cool! One question: as far as I remember order of fields in class instances may be different from declaration order. How then this will reliably work for classes?:The only dependency I'm aware of would be version switches. Debugging and DbC switches shouldn't matter. Although to be safe I'd pass the same switches anyway.fields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right? BTW: does D class layout depends on command line switches?
Jul 04 2005
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message news:dac14g$1ht0$1 digitaldaemon.com..."Andrew Fedoniouk" <news terrainformatica.com> wrote in message news:dabv5q$1gci$1 digitaldaemon.com...I see, thanks, Ben.Cool! One question: as far as I remember order of fields in class instances may be different from declaration order. How then this will reliably work for classes?:The only dependency I'm aware of would be version switches. Debugging and DbC switches shouldn't matter. Although to be safe I'd pass the same switches anyway.fields["x"] = new MetaField("x",typeid(int),8,4); fields["y"] = new MetaField("y",typeid(char[]),12,8);I mean that dflect.exe must be always used with the same set of command line switches as used with dmd.exe and version of dflect.exe must be always in sync with dmd.exe. Am I right? BTW: does D class layout depends on command line switches?
Jul 04 2005
Ben Hinkle schrieb:C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter helloSorry, i can't find dflect.d in the zip file. Where can i get it? Markus
Jul 07 2005
"Markus Dangl" <danglm in.tum.de> wrote in message news:dakp99$273f$1 digitaldaemon.com...Ben Hinkle schrieb:I forgot that part. I've updated the zip file and make a page for it http://home.comcast.net/~benhinkle/dflect/ You can call constructors and methods now. Return values are ignored currently. Also most likely lots of little things still don't work.C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter helloSorry, i can't find dflect.d in the zip file. Where can i get it? Markus
Jul 07 2005
In article <dakqub$2888$1 digitaldaemon.com>, Ben Hinkle says..."Markus Dangl" <danglm in.tum.de> wrote in message news:dakp99$273f$1 digitaldaemon.com...Ben, I had no idea that this was a modified DMD front-end... at first glance it looked like you had merely provided a way to spoof reflection via some other means. Bravo! - EricAnderton at yahooBen Hinkle schrieb:I forgot that part. I've updated the zip file and make a page for it http://home.comcast.net/~benhinkle/dflect/ You can call constructors and methods now. Return values are ignored currently. Also most likely lots of little things still don't work.C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter helloSorry, i can't find dflect.d in the zip file. Where can i get it? Markus
Jul 08 2005
"pragma" <pragma_member pathlink.com> wrote in message news:daltti$35e$1 digitaldaemon.com...In article <dakqub$2888$1 digitaldaemon.com>, Ben Hinkle says...dlint and this reflection generator were the two reasons I wanted dmdfe so I'm just getting around to doing what I wanted to do for a while. I figured the dmd front end does all the work of figuring out the module semantics so why not spit that metadata out? It would also be interesting to spit out the meta data in another format like XML or something instead of spitting out D code. I was going to look into that eventually but if anyone wants to poke around they're certainly welcome to experiment."Markus Dangl" <danglm in.tum.de> wrote in message news:dakp99$273f$1 digitaldaemon.com...Ben, I had no idea that this was a modified DMD front-end... at first glance it looked like you had merely provided a way to spoof reflection via some other means. Bravo! - EricAnderton at yahooBen Hinkle schrieb:I forgot that part. I've updated the zip file and make a page for it http://home.comcast.net/~benhinkle/dflect/ You can call constructors and methods now. Return values are ignored currently. Also most likely lots of little things still don't work.C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter helloSorry, i can't find dflect.d in the zip file. Where can i get it? Markus
Jul 08 2005
In article <dalvps$4pl$1 digitaldaemon.com>, Ben Hinkle says..."pragma" <pragma_member pathlink.com> wrote in message news:daltti$35e$1 digitaldaemon.com...Funny you should mention that. I already made an experiment into generating XML with the first DMDFE release you wrote. http://svn.dsource.org/projects/dsp/trunk/dexter/ I'm still learning how to get the most from the front-end. I wanted to use this to write documentation, so it captures comments and associates them with D constructs. Just pass the XML on to a stylesheet engine and presto: instant HTML documentation. I seriously think this is the way to go for producing documentation with D. - EricAnderton at yahooIn article <dakqub$2888$1 digitaldaemon.com>, Ben Hinkle says...dlint and this reflection generator were the two reasons I wanted dmdfe so I'm just getting around to doing what I wanted to do for a while. I figured the dmd front end does all the work of figuring out the module semantics so why not spit that metadata out? It would also be interesting to spit out the meta data in another format like XML or something instead of spitting out D code. I was going to look into that eventually but if anyone wants to poke around they're certainly welcome to experiment."Markus Dangl" <danglm in.tum.de> wrote in message news:dakp99$273f$1 digitaldaemon.com...Ben, I had no idea that this was a modified DMD front-end... at first glance it looked like you had merely provided a way to spoof reflection via some other means. Bravo! - EricAnderton at yahooBen Hinkle schrieb:I forgot that part. I've updated the zip file and make a page for it http://home.comcast.net/~benhinkle/dflect/ You can call constructors and methods now. Return values are ignored currently. Also most likely lots of little things still don't work.C:\dflect\dflect>dflect test.d C:\dflect\dflect>dmd dtest.d dflect.d testinfo.d test.d C:\dflect\dflect>dtest setter 100 hello getter helloSorry, i can't find dflect.d in the zip file. Where can i get it? Markus
Jul 10 2005
A request for input: what (if any) metadata tags (which aren't already in and Java's annotations. I suppose the tags will have to be in comments in order to get past the D compiler. Should doxygen/javadoc comments be added to the metadata? For example I could imagine something very simple where any comment preceding a method gets added to the metadata for that method as a "description" property. Or it can try to pick apart tags like doc, author, version, etc etc. thoughts?
Jul 16 2005
In article <dbbcdh$1rv6$1 digitaldaemon.com>, Ben Hinkle says...A request for input: what (if any) metadata tags (which aren't already in and Java's annotations. I suppose the tags will have to be in comments in order to get past the D compiler. Should doxygen/javadoc comments be added to the metadata? For example I could imagine something very simple where any comment preceding a method gets added to the metadata for that method as a "description" property. Or it can try to pick apart tags like doc, author, version, etc etc. thoughts?Ben, here's my opinion. :) Personally, I think a documentation parser (similar to my Dexter prototype) should be left to being its own tool. From a maintenance standpoint, and a coding standpoint it just makes good sense. At the very least, meshing dflect with a certain style of documentation reduces its usefulness as one may want to use a different doc tool along with dflect. I think dflect could use a good general-purpose attribute hook similar to what NET has. The most D-like way to achieve this would be to use a pragma():version(dflect){ pragma(attribute,<expression>); }The above expression would be crammed into the static ctor() for the corresponding metadata module, and would have to evaluate to a certain type: say an Attribute class or somesuch. - EricAnderton at yahoo
Jul 16 2005
"pragma" <pragma_member pathlink.com> wrote in message news:dbbgfc$1uk2$1 digitaldaemon.com...In article <dbbcdh$1rv6$1 digitaldaemon.com>, Ben Hinkle says...I agree dflect isn't meant to be used to generate doc. The reason I mentioned the doc string is that dflect is gathering up information about a class for use at run-time. Help is part of that metadata. For example in MATLAB we use Java reflection to let users load jar files and dynamically instantiate and use Java classes from the MATLAB command line. Having short doc strings of what the user just loaded would be very helpful. Otherwise they are on their own to figure out what they have.A request for input: what (if any) metadata tags (which aren't already in syntax and Java's annotations. I suppose the tags will have to be in comments in order to get past the D compiler. Should doxygen/javadoc comments be added to the metadata? For example I could imagine something very simple where any comment preceding a method gets added to the metadata for that method as a "description" property. Or it can try to pick apart tags like doc, author, version, etc etc. thoughts?Ben, here's my opinion. :) Personally, I think a documentation parser (similar to my Dexter prototype) should be left to being its own tool. From a maintenance standpoint, and a coding standpoint it just makes good sense. At the very least, meshing dflect with a certain style of documentation reduces its usefulness as one may want to use a different doc tool along with dflect.I think dflect could use a good general-purpose attribute hook similar to what NET has. The most D-like way to achieve this would be to use a pragma():Good idea - though it's a pity the code is so verbose. I'll probably just skip the whole issue for now and dump the parse tree info and that's it.version(dflect){ pragma(attribute,<expression>); }The above expression would be crammed into the static ctor() for the corresponding metadata module, and would have to evaluate to a certain type: say an Attribute class or somesuch. - EricAnderton at yahoo
Jul 16 2005