Metacode mechanics

AgentOrange AgentOrange_member at pathlink.com
Thu Mar 2 13:01:43 PST 2006


In article <du7kl1$288j$1 at digitaldaemon.com>, Bruno Medeiros says...
>
>Don Clugston wrote:
>> Craig Black wrote:
>>>
>>> Compile-time reflection would be very nice.  I'm not sure I understand 
>>> why array literals would be a requirement for this.  Am I missing 
>>> something?
>> 
>> It's because we can't have compile-time constant folding of [], except 
>> for char arrays, until we get array literals. Compile-time reflection 
>> _could_ be done without using arrays, but I think it's the most natural 
>> way of doing it, anything else would require new syntax or be a bit clunky?
> >
>
>Why would it requite clunky syntax? I don't see why array literals would 
>affect this. How exactly are you thinking compile-time reflection should 
>work? (in terms of usage)
>In fact I don't see how compile-time reflection could work at all 
>(regardless of array literals). I tried to convert my runtime reflection 
>example in the Reflection thread, but some things wouldn't work, one of 
>which being that one cannot use a TypeInfo as a type (for instance in a 
>declaration or something).
>
>-- 
>Bruno Medeiros - CS/E student
>"Certain aspects of D are a pathway to many abilities some consider to 
>be... unnatural."

I dont see why it would require any syntax beyond what D currently uses, just a
way to integrate it... a simple metaprotocol... 

you could write all of your 'metacode' in D which gets compiled into small
shared libraries which are dynamically loaded (or compiled, i suppose) at
compile/translation time to process your code, via a protcol of metaobjects
representing your code (reflection data on steroids). your metacode, in D, would
just manipulate these metaobjects before being sent to the compiler....

Its all a fairly straightforward process. ive currently been playing with this
using an experimental metacompiler hooked up with dparser, and it works QUITE
WELL. For example, i can take source modules, and translate them back into
source replacing all class references with (assert(ref !is null), ref) and
instantly you have auto-asserting class references :D the only real haslte is
using the #line directive to synch up debugging data between your translated
code and your original source. But in the end metacode expands just like macros
in c++, only much much cooler :D





More information about the Digitalmars-d-dtl mailing list