Any chance to call Tango as Extended Standard Library

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 20 21:00:24 PST 2009


Lars Ivar Igesund wrote:
> Andrei Alexandrescu wrote:
> 
>> Lars Ivar Igesund wrote:
>>> No, you misunderstand. I said safely call, not exceptionally 
>>> efficient. To me a virtual call would be acceptable. However, at 
>>> least in my cases, there would normally not be more than one 
>>> imlemented interface and such it would be a tiny vtable.
>> Ok, so the scope is reducing nicely. We now have a few problems to
>> solve (some details glossed over for simplicity).
>> 
>> a) Get from void* to the TypeInfo that's typing that void*. This
>> will involve a search as the void* could point really anywhere,
>> including untyped memory. So we have a core function:
>> 
>> TypeInfo fromAddress(void * p);
>> 
>> b) Starting from a TypeInfo, get an interface in case the
>> underlying struct implements that interface:
>> 
>> Object TypeInfo.QueryInterface(TypeInfo someInterface);
>> 
>> c) Finally, given a void* and an interface, invoke a method of that
>>  interface:
>> 
>> T structCast!(Interface)(p).method(arguments);
> 
> Since you used template lingo, it looks a bit like compile time
> functionality, but yes, very close now :)
> 
> Also (I keep forgetting to mention important details) - I typically
> see this used in variadic functions, such that the typeinfo already
> is there.

But what are you ultimately trying to accomplish, and why do you must 
lose all static information since it was just available to the caller? 
Isn't there a simpler way to achieve your goal (e.g. using the new 
variadics)? You are essentially asking for full-blown runtime scripting 
for all structs.

> And an additional question only semi-related to the above; is it
> possible to have a function that works as a variadic function, but
> where the number of arguments is restricted to 1 (or 2 or 3 but not
> unbounded).

void foo(R..)(R args) if (R.length == 2)
{
     ...
}

It doesn't work now due to a bug in the compiler, you may want to submit it.

> Oh oh, I'm getting into a steam (and even less related ...) -
> variadic ref parameters.
> 

That will be fixed.


Andrei



More information about the Digitalmars-d mailing list