What is the relationship between the Dynamic Language Runtime and C# 4.0?

Aug 11, 2011 at 7:42 PM

Let's say I wanted to create a dynamic language compiler/interpreter, a Scheme interpreter perhaps, on the .NET platform as it exists today. Would I be better off using the Dynamic Language Runtime (DLR), or using C# 4.0 to implement my language's dynamic features? Or do I need both?

I know that there has been other work done in this area, in particular with IronScheme and IronPython. Both of those languages use the DLR; I believe IronPython uses the most current version of the DLR (which is about a year old), while IronScheme uses an early, heavily modified fork of an early version of the DLR. But C# 4.0 was not available when these compilers were created.

I've seen Rob Conery's work with Massive, using C# 4.0's dynamic features; it is quite impressive. But would C# hold up to the full-scale effort of a dynamic language compiler/intepreter? Are there features in the DLR that are missing from C# 4.0, or was the DLR essentially rolled into C# 4.0? Would I be missing any important features of the DLR if I just used C# 4.0 exclusively?

Aug 11, 2011 at 8:08 PM

Robert,

The facts: IronRuby and IronPython both use the DLR, in fact most of the DLR's features are derived from earlier implementation of IronPython. I'm not familiar with how what version of the DLR IronScheme uses. A portion of the DLR (Microsoft.Scripting.Core.dll) was shipped in .NET 4.0 in System.Core.dll, and that portion is what C# 4.0 uses for it's "dynamic" keyword support, which is why that assembly is not present in .NET 4.0 builds of the DLR. The rest of the DLR's codebase (Microsoft.Scripting.dll, Microsoft.Dynamic.dll are the most important) are available for download from this CodePlex project, or the IronLanguages GitHub project. They provide the APIs for consumers and producers of hosting languages, while the APIs in .NET 4.0 are for actually doing dynamic dispatch of methods.

To write a dynamic language compiler for .NET 4.0, I'd use C# as the implementation language and use the DLR as a library for simplifying common compiler tasks. For a simple example language on the DLR, look at Sympl.

~Jimmy

Aug 11, 2011 at 8:33 PM
On 08/11/2011 02:42 PM, robertwharvey wrote:
> From: robertwharvey
>
> Let's say I wanted to create a dynamic language compiler/interpreter, a
> Scheme interpreter perhaps, on the .NET platform as it exists today.
> Would I be better off using the Dynamic Language Runtime (DLR), or using
> C# 4.0 to implement my language's dynamic features? Or do I need both?

I think it depends a bit on what your goals are: how much you want to
leverage, how much you want to learn vs. create, if you value speed or
flexibility, if you want to interoperate with other languages, and what
the long term plans of your project are.

> I know that there has been other work done in this area, in particular
> with IronScheme and IronPython. Both of those languages use the DLR; I
> believe IronPython uses the most current version of the DLR (which is
> about a year old), while IronScheme uses an early, heavily modified fork
> of an early version of the DLR. But C# 4.0 was not available when these
> compilers were created.

It looks like IronScheme abandoned the DLR before it was even completed.
There is some discussion here, albeit not very deep:
http://ironscheme.codeplex.com/discussions/79734

> I've seen Rob Conery's work with Massive, using C# 4.0's dynamic
> features; it is quite impressive. But would C# hold up to the full-scale
> effort of a dynamic language compiler/intepreter? Are there features in
> the DLR that are missing from C# 4.0, or was the DLR essentially rolled
> into C# 4.0? Would I be missing any important features of the DLR if I
> just used C# 4.0 exclusively?

We are developing a .NET Scheme, and are planning the DLR integration
piece by piece. You can use some parts of the DLR without using other
parts, and integrate over more time.

For example, we handle our own function callstack (to get proper tail
recursion), but we bottom out on variable lookups in the DLR's global
environment. We have defined scheme functions that can wrap proper tail
call functions with DLR functions, so that Python code can call our
Scheme functions. And Scheme can use DLR data types (like Python lists
or Ruby dictionaries).

Demo:
http://www.youtube.com/user/dsblank007?feature=mhum#p/a/u/0/Eeg3VpNbvro

We wrote our (prototype) Scheme in Scheme, and then, through a series of
transformations, convert it to C# using just a few parts of the DLR so
far. This is part of a multi-year project, and we haven't really gotten
serious about the C# code yet (it was my first C# program). We'll no
doubt take advantage of C# 4.0's dynamic, and the DLR as we go forward.

Ours is an open source project, if you are interested.

-Doug

--
Douglas S. Blank, Associate Professor and Chair
Department of Computer Science, Bryn Mawr College
http://cs.brynmawr.edu/~dblank (610)526-6501
Mar 15, 2012 at 9:55 PM

I'd also imagine that if a couple of people were to help out with leppie's IronScheme, we could get it to use the latest version of the DLR.

-Nathan