Thursday, August 14, 2008

Viewing Emitted IL

IronPython is a Python compiler. This means that it compiles Python sourcecode into IL (Intermediate Language), the bytecode of the Common Language Runtime. (Although that bytecode is interpreted, like the CPython compiled bytecode, .NET languages are typically called compiled languages because the IL can be compiled to native code by the .NET JIT compiler.) This IL remains heavily dependent on the main IronPython assemblies (and Dynamic Language Runtime assemblies in the case of IronPython 2) in order to implement the highly dynamic semantics of Python - but it is still compiled IL that is running.

This is done using the .NET 'Reflection.Emit' API to generate the IL (and the lack of this API in .NET Compact Framework is why we can't run IronPython code on the XBox 360 or Windows Mobile devices). It also means that you can use standard .NET debugging tools like 'windbg.exe' to introspect and debug your IronPython code in memory.

In his latest blog entry Curt Hagenlocher takes us through some of the techniques to do just this using a 'noninvasive debugging' technique:

1 comment:

  1. Thats really a lot of work just to see what the IL code for Microsoft.Scripting.Actions.CallSiteFactory.Generated.cs.
    Why not just take the DLR source code and take a look it at or if you really want the full debugger experience with stepping through this code, just add the Microsoft.Scripting project with source code to your solution instead of adding the assembly.


Note: only a member of this blog may post a comment.