[Mono-devel-list] Using System.Reflection.Emit for interactive languages

Paolo Molaro lupus at ximian.com
Mon May 19 04:38:14 EDT 2003


On 05/18/03 Jim Blandy wrote:
> - Is it possible to re-define a method?  Is there anything less
>   horrible than MethodRental.SwapMethodBody?

There are ways to do it with the unmanaged/profiling API.
Note: since MethodRental works only for types built at runtime,
you can use some other way that may look nicer. For example
having a field in your class that is an object of a nested type of the
class. The methods you want to redefine in your class are just
calls to methods in the nested type object. When you want to
redefine a method, you just build a new nested type (optionally
deriving from the first one) and providing the new method in it.

> - Is it possible to delete a method altogether?
> - Is it possible to create anonymous modules, types, and methods?

I think you're mixing mechanism with policy here. What is an anonymous
method? In the CLR all the methods need a name, so you may conclude that
anonymous methods are not possible. But the issue is that nobody
prevents you from writing your compiler for your language with the
convention that, for example, methods whose names start with
'.anonymous!' are seen as anonymous methods. The same is true for
deleting methods, you can just keep your own hashtable of methods you
conside 'deleted' for your language.
If you actually want to free the memory associated with a method,
currently the only way to do it is to build the method (and it's class)
in its own appdomain and then onload the whole appdomain.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list