Peter Miller

Musings on Technology and Programming
in

Code Camp: DLR Session Recap

Due to some scheduling issues, I was only able to attend one session of the recent San Diego code camp. The one session that I went to was about the Dynamic Language Runtime (DLR). The DLR is a new piece of the .NET landscape that makes it easier for dynamic languages, such as Python, JavaScript and Ruby to access the .NET framework libraries and easier to call scripts in dynamic languages from C# or VB code.

According to the presenter, Steve Saxon, Microsoft got much of the initial inspiration for the DLR from the custom work they did implementing Iron Python, the .NET version of Python. By generalizing this code, Microsoft was able to create the framework that is the DLR and in fact the latest version of Iron Python was implemented using the DLR.

So what makes up the DLR? Steve went into some of the details and I took away the following two interesting points about its implementation:

  1. For code to run on the CLR, it needs to be converted to MSIL. To get dynamic code converted to MSIL, the individual language implementation needs to be able to convert the dynamic code into an Abstract Syntax Tree (AST). I don't know too much about specifics of AST's, but it is basically a tree structure that represents your program's execution flow. The DLR takes Abstract Syntax Trees and parses them into MSIL. So, if you have a language you want to run on the CLR and you can write a parser to convert it into an AST, the DLR will do the rest for you.
  2. When objects come from a dynamic language, they get wrapped in a CLR wrapper for access from the regular .NET languages. In effect, this wrapper ends up being a glorified function pointer table or hash. In order to deal with the possibility of methods and properties being added at runtime, the statically typed CLR uses a hash structure containing names and pointers to the named method. Calls to a hash are not evaluated until runtime, so you can in effect do an end run around the compiler's type checking.

All in all, the presentation was quite interesting, but perhaps more interesting than the DLR itself is what it enables. You may benefit from the DLR when writing JavaScript in Silverlight for example, without ever having to know how it works. If however, you are curious for more, check out Jim Hugunin's blog Thinking Dynamic for lots of posts about the DLR and Iron Python.

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)