[IronPython] Lightweight Code Generation?
jim at ironpython.com
Mon Oct 11 05:46:41 CEST 2004
Andrew Deren wrote:
> Would you know where I can find more info on dynamic methods? One thing
> especially looking for is a way to call other dynamically created methods
> from one. Is it even possible?
> If I have a script that defines custom functions, I would need to emit
> too. Would I create separate DynamicMethod for each one of them?
The best pointers I know are Joel's hello world from my last message and the
docs that ship with the various Whidbey betas. You can get the betas and
the docs from msdn. Here's a link to the docs online:
Every function that you want to create should go in its own DynamicMethod.
I assume that you can call a DynamicMethod in generated bytecode by just
using ILGenerator.Emit(OpCodes.Call, myDynamicMethod) as you would for
emitting a call to any MethodInfo. I have to admit that I've never tried
this so I'm assuming there's no issue using this with DynamicMethods. Have
you tried this?
The reason that I've never tried this is that the IronPython implementation
never has a reason to call DynamicMethods directly. DynamicMethods are used
to build Function objects that are called using standard method calls. This
is needed because functions in Python are first-class entities.
Thank - Jim
More information about the Ironpython-users