[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Generic IL Examples

From: Fergus Henderson
Subject: Re: [DotGNU]Generic IL Examples
Date: Wed, 19 Feb 2003 18:05:29 +1100
User-agent: Mutt/1.3.28i

On 19-Feb-2003, Rhys Weatherley <address@hidden> wrote:
> On Wednesday 19 February 2003 04:29 pm, Fergus Henderson wrote:
> > I assume that it is also possible to refer to such parameters by name,
> > e.g. "!T"?
> /me looks at Gyro ilasm code again
> Nope.  It's always an integer.
> Which is probably what was intended.  There are some weird scoping rules.  
> Sometimes "!0" can refer to "parameter 0" of the thing being instantiated in 
> a method call, not the surrounding class's "parameter 0".  Resolving which T 
> is being referred to might be tricky.  Consider this:
>     .class Blah<T,V> {
>     ...
>     callvirt void class Stack<!1>::Push(!0)
>     callvirt void class Stack<!0>::Push(!0)
>     ...
>     }
> This roughly corresponds to:
>     callvirt void class Stack<V>::Push(V)
>     callvirt void class Stack<T>::Push(T)
> i.e. the "!0" in the method signature parameters refers to the parameters to 
> "Stack", not the parameters to "Blah".

I was thinking 

      callvirt void class Stack<!V>::Push(!V)
      callvirt void class Stack<!T>::Push(!T)

i.e. keep the "!" and "!!" prefixes, but just use names instead of numbers.

But yes, I see that it could be confusing if "!V" refers to different
things depending on where it occurs.  The IL assembler wouldn't have any
trouble -- for each occurrence, it knows from the context and the number
of exclamation marks in the prefix which generic class or method
to look in for the names -- but the poor human reader might get a bit lost.

So another possibility would be to use a slightly different syntax for
names that refer to classes other than the current scope.  For example,
perhaps those could use "~V" rather than "!V".

Then it would be

      callvirt void class Stack<!V>::Push(~V)
      callvirt void class Stack<!T>::Push(~T)

That seems to me like a definite readability improvement on the original

      callvirt void class Stack<!1>::Push(!0)
      callvirt void class Stack<!0>::Push(!0)

Fergus Henderson <address@hidden>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]