I'm just starting to try to learn more about the .Net VM underpinnings, and am immediately thrown off by something. I know there's this new thing called the DLR that allows for all the dynamic stuff in C# and the running of the IronX languages. But now I'm reading about this language called Boo, and apparently it has had dynamic capabilities since long before the DLR existed. So,
1) How is this even possible?
2) What does the DLR add to the equation?
3) Would a language like Boo stand to gain anything by re-implementing itself in terms of the DLR?
From what I've kind of gathered here and there, it looks like the DLR came out of IronPython, when they factored out everything that was necessary for DL support in .Net, and put it in reusable form. So what I'm guessing is that DLR is nothing special, just some libraries that help with dynamic objects in Microsoft.Scripting.dll, but nothing that you couldn't just go out and code up by yourself if you had the time, which I guess is what happened for Boo? And then for 2 and 3, I guess the commonality and reusability of the DLR would allow any future DLR improvements to be grandfathered in automatically, but that there's no urgent "need" to re-implement using the DLR if you've already made your own custom runtime? Or does the DLR have some secret MS sauce that makes it better than anything we could do on top of .Net?
4) Is the DLR really a runtime or just a set of libraries? (What exactly is a runtime anyway? I probably need to learn more compiler theory before I can even understand an answer to this question, or whether it's even a question that means anything. Ignore this question. Or don't.)
5) How does IronPython compilation work? Does it compile down to a new dynamic version of the CIL, or does it just prepend a "ironpython.exe" command to a string with the program's text in it? Hmm, well if dynamic is a keyword in C#, then there must be a dynamic version of the CIL, right? So how does .Net know whether to use the CLR or the DLR on the CIL?
6) Is the DaVinci project for the JVM different? It looks like it's an actual re-implementation of the JVM itself. What are the implications of this approach? I'm guessing there's huge performance gains, but anything else? Any reason MS didn't take this road?
7) Does the DLR make Boo somewhat obsolete for making DSLs?
Lots of questions here! I'm not sure I can answer all of them, but I'll do as much as I can:
Boo is not dynamic in the same sense that (Iron)Python is. It's mostly a statically typed language with strong type inference and pythonic syntax. This, coupled with its optional duck typing, give it a very dynamic feel, but it's certainly not the same as Python. Boo is more similar (except for syntax) to C# 4 than Python.
DLR adds dynamic support for language implementors on top of the CLR, which is more geared towards statically typed languages (such as VB.NET, C# ,F#)
Not really IMHO. It would become too similar to IronPython. Precisely one of the characteristics of Boo is that it's statically typed.
Runtimes are libraries which support some basic constructs in the language. VB.NET, C#, F#, Boo, they all have runtime libraries. You usually never see VB.NET or C# runtimes because they come with the .NET framework. There was a great answer on SO about this from Eric Lippert but I can't find it.
Can't comment on this, don't have much hands-on experience with IronPython.
Don't know about the DaVinci project, can't comment on this.
No. As far as I know Boo's macros and extensible compiler are quite unique for a .NET language (Nemerle has similar macro capabilities). I can't really say if Boo DSLs can be more or less powerful than IronPython DSLs. What I can say for sure is that the implementation of Boo DSLs is wildly different from the implentation of Python DSLs.
The DLR basically brings 3 things to the party:
The meta object protocol is the only piece that absolutely needs to be shared - everything else you could create on your own.
IronPython builds fully on top of the DLR - so it's compilation model is actually to compile to expression trees. The DLR inner layer which shipped w/ .NET 4.0 is used to compile those expression trees and we use the interpreter which is a piece of the outer layer to interpret those expression trees. We can then lazily compile the expression trees after the interpreted versions have become hot. That compilation includes the production of call sites which we use for dynamic dispatch of various operations (getting, setting members, calling objects, etc...) and again we use the DLR - in this case it's call site mechanism. IronPython uses a combination of both standard DLR binders for these operations along with custom binders which do IronPython specific actions (flow through code context, supporting *args and **args calls, etc...) which then fall back to standard DLR binders for interop.
The Davinci project will add "method handles" to the JVM which the CLR has already had in the form of delegates. It will also add a new "invokedynamic" opcode which the CLR doesn't have and didn't gain w/ the DLR work. Instead the DLR just uses the existing primitives (delegates, reified generics) plus libraries for defining the interop protocol. Both add the concept of call sites and those may be fairly similar between the two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With